php 如何在任何操作系统上启用 mod_rewrite?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3131236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you enable mod_rewrite on any OS?
提问by John
If I understand correctly, I need to put something in httpd.configto enable mod_rewrite. If this is true, what do I need to put in httpd.confor apache.conf? Please be OS specific.
如果我理解正确,我需要添加一些东西httpd.config来启用 mod_rewrite。如果这是真的,我需要什么就摆在httpd.conf或apache.conf?请特定于操作系统。
回答by Pekka
Nope, mod_rewriteis an Apache module and has nothing to do with PHP.
不,mod_rewrite是一个 Apache 模块,与 PHP 无关。
To activate the module, the following line in httpd.confneeds to be active:
要激活模块,httpd.conf需要激活以下行:
LoadModule rewrite_module modules/mod_rewrite.so
to see whether it is already active, try putting a .htaccessfile into a web directory containing the line
要查看它是否已经处于活动状态,请尝试将.htaccess文件放入包含该行的 Web 目录中
RewriteEngine on
if this works without throwing a 500 internal server error, and the .htaccessfile gets parsed, URL rewriting works.
如果这在不引发 500 内部服务器错误的情况下有效,并且.htaccess文件被解析,则 URL 重写有效。
回答by FarmerGedden
Just a fyi for people enabling mod_rewrite on Debian with Apache2:
对于使用 Apache2 在 Debian 上启用 mod_rewrite 的人来说,仅供参考:
To check whether mod_rewrite is enabled:
要检查是否启用了 mod_rewrite:
Look in mods_enabled for a link to the module by running
通过运行在 mods_enabled 中查找到模块的链接
ls /etc/apache2/mods-enabled | grep rewrite
If this outputs rewrite.loadthen the module is enabled. (Note: your path to apache2 may not be /etc/, though it's likely to be.)
如果此输出,rewrite.load则模块已启用。(注意:您的 apache2 路径可能不是 /etc/,但很可能是。)
To enable mod_rewrite if it's not already:
如果还没有启用 mod_rewrite:
Enable the module (essentially creates the link we were looking for above):
启用模块(基本上创建我们在上面寻找的链接):
a2enmod rewrite
Reload all apache config files:
重新加载所有 apache 配置文件:
service apache2 restart
回答by Sadee
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
在我的情况下,即使在所有这些配置都完成之后还是出现了问题(@Pekka 提到了 httpd.conf 和 .htaccess 文件中的更改)。我添加后才解决
<Directory "project/path">
Order allow,deny
Allow from all
AllowOverride All
</Directory>
to virtual host configuration in vhost file
到 vhost 文件中的虚拟主机配置
Edit on 29/09/2017 (For Apache 2.4 <) Refer this answer
2017 年 9 月 29 日编辑(对于 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>
回答by Jason Lewis
No, you should not need to. mod_rewriteis an Apache module. It has nothing to do with php.ini.
不,你应该不需要。mod_rewrite是一个 Apache 模块。它与php.ini.
回答by Hassan Saeed
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
如果它与托管站点有关,则询问您的托管服务,或者如果您想在本地机器中启用它,请查看与在 wamp apache 中启用重写模块相关的 youtube 分步教程
https://youtu.be/xIspOX9FuVU?t=1m43s
Wamp server icon -> Apache -> Apache Modules 并检查重写模块选项,它应该被选中,但在那之后 wamp 需要重新启动所有服务
回答by Marco Schaffner
Module rewrite_module is built-in in to the server most cases
大多数情况下,模块 rewrite_module 内置于服务器中
Use .htaccess
使用 .htaccess
Use the Mod Rewrite Generator at http://www.generateit.net/mod-rewrite/
使用http://www.generateit.net/mod-rewrite/ 上的 Mod 重写生成器
回答by jeremy woods
network solutions offers the advice to put a php.ini in the cgi-bin to enable mod_rewrite
网络解决方案提供了将 php.ini 放入 cgi-bin 以启用 mod_rewrite 的建议
回答by JItendra
In order to use mod_rewrite you can type the following command in the terminal:
为了使用 mod_rewrite,您可以在终端中键入以下命令:
$ su
$ passwd **********
# a2enmod rewrite
Restart apache2 after
之后重启apache2
# service apache2 restart
# /etc/init.d/apache2 restart
or
或者
# service apache2 restart

