如何在任何操作系统上启用 mod_rewrite?
如果我理解正确的话,我需要在 httpd.config 中添加一些内容来启用 mod_rewrite。如果这是真的,我需要在 httpd.conf
或 apache.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
不,
mod_rewrite
是一个 Apache 模块,与 PHP 无关。要激活该模块,
httpd.conf
中的以下行需要处于活动状态:要查看它是否已处于活动状态,请尝试将
.htaccess
文件放入包含以下内容的 Web 目录中: 如果此行有效且不会引发 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:to see whether it is already active, try putting a
.htaccess
file into a web directory containing the lineif this works without throwing a 500 internal server error, and the
.htaccess
file gets parsed, URL rewriting works.对于在带有 Apache2 的 Debian 上启用 mod_rewrite 的人来说,仅供参考:
要检查 mod_rewrite 是否已启用:
在 mods_enabled 中查找模块的链接
通过运行If thisoutput
rewrite.load
然后模块被启用。 (注意:您的 apache2 路径可能不是 /etc/,尽管很可能是。)要启用 mod_rewrite(如果尚未启用):
启用模块(实质上创建我们在上面查找的链接) :
重新加载所有 apache 配置文件:
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
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):
Reload all apache config files:
就我而言,即使完成所有这些配置(@Pekka 提到了 httpd.conf 和 .htaccess 文件中的更改),问题仍然发生。 后才解决此问题
仅在我于 2017 年 9 月 29 日编辑vhost 文件中添加虚拟主机配置
(对于 Apache 2.4 <)
参考此答案
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
to virtual host configuration in vhost file
Edit on 29/09/2017 (For Apache 2.4 <)
Refer this answer
不,你不需要。
mod_rewrite
是一个 Apache 模块。它与php.ini
无关。No, you should not need to.
mod_rewrite
is an Apache module. It has nothing to do withphp.ini
.如果它与托管站点相关,则询问您的托管,或者如果您想在本地计算机中启用它,则检查此 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
大多数情况下,模块 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/
网络解决方案提供了将 php.ini 放入 cgi-bin 中以启用 mod_rewrite 的建议
network solutions offers the advice to put a php.ini in the cgi-bin to enable mod_rewrite
为了使用 mod_rewrite,您可以在终端中键入以下命令:
Restart apache2 after
或
In order to use mod_rewrite you can type the following command in the terminal:
Restart apache2 after
or