如何在任何操作系统上启用 mod_rewrite?

发布于 2024-09-07 06:23:10 字数 137 浏览 2 评论 0原文

如果我理解正确的话,我需要在 httpd.config 中添加一些内容来启用 mod_rewrite。如果这是真的,我需要在 httpd.confapache.conf 中放入什么?请具体说明操作系统。

If I understand correctly, I need to put something in httpd.config to enable mod_rewrite. If this is true, what do I need to put in httpd.conf or apache.conf? Please be OS specific.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

只有一腔孤勇 2024-09-14 06:23:10

不,mod_rewrite 是一个 Apache 模块,与 PHP 无关。

要激活该模块,httpd.conf 中的以下行需要处于活动状态:

LoadModule rewrite_module modules/mod_rewrite.so

要查看它是否已处于活动状态,请尝试将 .htaccess 文件放入包含以下内容的 Web 目录中: 如果此行

RewriteEngine on

有效且不会引发 500 内部服务器错误,并且 .htaccess 文件被解析,则 URL 重写有效。

Nope, mod_rewrite is an Apache module and has nothing to do with PHP.

To activate the module, the following line in httpd.conf needs to be active:

LoadModule rewrite_module modules/mod_rewrite.so

to see whether it is already active, try putting a .htaccess file into a web directory containing the line

RewriteEngine on

if this works without throwing a 500 internal server error, and the .htaccess file gets parsed, URL rewriting works.

三月梨花 2024-09-14 06:23:10

对于在带有 Apache2 的 Debian 上启用 mod_rewrite 的人来说,仅供参考:

要检查 mod_rewrite 是否已启用:

在 mods_enabled 中查找模块的链接

ls /etc/apache2/mods-enabled | grep rewrite

通过运行If thisoutput rewrite.load 然后模块被启用。 (注意:您的 apache2 路径可能不是 /etc/,尽管很可能是。)

要启用 mod_rewrite(如果尚未启用)

启用模块(实质上创建我们在上面查找的链接) :

a2enmod rewrite

重新加载所有 apache 配置文件:

service apache2 restart

Just a fyi for people enabling mod_rewrite on Debian with Apache2:

To check whether mod_rewrite is enabled:

Look in mods_enabled for a link to the module by running

ls /etc/apache2/mods-enabled | grep rewrite

If this outputs rewrite.load then the module is enabled. (Note: your path to apache2 may not be /etc/, though it's likely to be.)

To enable mod_rewrite if it's not already:

Enable the module (essentially creates the link we were looking for above):

a2enmod rewrite

Reload all apache config files:

service apache2 restart
找回味觉 2024-09-14 06:23:10

就我而言,即使完成所有这些配置(@Pekka 提到了 httpd.conf 和 .htaccess 文件中的更改),问题仍然发生。 后才解决此问题

<Directory "project/path">
  Order allow,deny
  Allow from all
  AllowOverride All
</Directory>

仅在我于 2017 年 9 月 29 日编辑vhost 文件中添加虚拟主机配置

(对于 Apache 2.4 <)
参考此答案

<VirtualHost dropbox.local:80>
DocumentRoot "E:/Documenten/Dropbox/Dropbox/dummy-htdocs"
ServerName dropbox.local
ErrorLog "logs/dropbox.local-error.log"
CustomLog "logs/dropbox.local-access.log" combined
<Directory "E:/Documenten/Dropbox/Dropbox/dummy-htdocs">
    # AllowOverride All      # Deprecated
    # Order Allow,Deny       # Deprecated
    # Allow from all         # Deprecated

    # --New way of doing it
    Require all granted    
</Directory>

In my case, issue was occured even after all these configurations have done (@Pekka has mentioned changes in httpd.conf & .htaccess files). It was resolved only after I add

<Directory "project/path">
  Order allow,deny
  Allow from all
  AllowOverride All
</Directory>

to virtual host configuration in vhost file

Edit on 29/09/2017 (For Apache 2.4 <)
Refer this answer

<VirtualHost dropbox.local:80>
DocumentRoot "E:/Documenten/Dropbox/Dropbox/dummy-htdocs"
ServerName dropbox.local
ErrorLog "logs/dropbox.local-error.log"
CustomLog "logs/dropbox.local-access.log" combined
<Directory "E:/Documenten/Dropbox/Dropbox/dummy-htdocs">
    # AllowOverride All      # Deprecated
    # Order Allow,Deny       # Deprecated
    # Allow from all         # Deprecated

    # --New way of doing it
    Require all granted    
</Directory>

稍尽春風 2024-09-14 06:23:10

不,你不需要。 mod_rewrite 是一个 Apache 模块。它与php.ini无关。

No, you should not need to. mod_rewrite is an Apache module. It has nothing to do with php.ini.

只等公子 2024-09-14 06:23:10

如果它与托管站点相关,则询问您的托管,或者如果您想在本地计算机中启用它,则检查此 youtube 分步教程,与在 wamp apache 中启用重写模块相关
https://youtu.be/xIspOX9FuVU?t=1m43s
Wamp 服务器图标 ->阿帕奇-> Apache Modules 并检查重写模块选项
应该检查它,但之后 wamp 需要重新启动所有服务

if it related to hosting site then ask to your hosting or if you want to enable it in local machine then check this youtube step by step tutorial related to enabling rewrite module in wamp apache
https://youtu.be/xIspOX9FuVU?t=1m43s
Wamp server icon -> Apache -> Apache Modules and check the rewrite module option
it should be checked but after that wamp require restart all services

鸠书 2024-09-14 06:23:10

大多数情况下,模块 rewrite_module 内置于服务器中

使用 .htaccess

使用 http:// /www.generateit.net/mod-rewrite/

Module rewrite_module is built-in in to the server most cases

Use .htaccess

Use the Mod Rewrite Generator at http://www.generateit.net/mod-rewrite/

吹梦到西洲 2024-09-14 06:23:10

网络解决方案提供了将 php.ini 放入 cgi-bin 中以启用 mod_rewrite 的建议

network solutions offers the advice to put a php.ini in the cgi-bin to enable mod_rewrite

薄凉少年不暖心 2024-09-14 06:23:10

为了使用 mod_rewrite,您可以在终端中键入以下命令:

 $ su

 $ passwd **********

 # a2enmod rewrite

Restart apache2 after

 # service apache2 restart

 # /etc/init.d/apache2 restart

 # service apache2 restart

In order to use mod_rewrite you can type the following command in the terminal:

 $ su

 $ passwd **********

 # a2enmod rewrite

Restart apache2 after

 # service apache2 restart

 # /etc/init.d/apache2 restart

or

 # service apache2 restart
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文