apache 是否需要重启apache才能使.htaccess中的re-write规则生效?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/142559/
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
Do you have to restart apache to make re-write rules in the .htaccess take effect?
提问by Jesse Hattabaugh
I have pushed my .htaccess files to the production severs, but they don't work. Would a restart be the next step, or should I check something else.
我已将我的 .htaccess 文件推送到生产服务器,但它们不起作用。下一步是重新启动,还是我应该检查其他内容。
采纳答案by TomG
A restart is notrequired for changes to .htaccess. Something else is wrong.
在这里重新启动不要求更改为.htaccess。还有什么不对的。
Make sure your .htaccess includes the statement
确保您的 .htaccess 包含声明
RewriteEngine on
重写引擎开启
which is required even if it's also present in httpd.conf. Also check that .htaccess is readable by the httpd process.
Check the error_log - it will tell you of any errors in .htaccess ifit's being used.
Putting an intentional syntax error in .htaccess is a good check to make sure the file is being used -- you should get a 500 error on any page in the same directory.
即使它也存在于 httpd.conf 中也是必需的。还要检查 .htaccess 是否可以被 httpd 进程读取。
检查 error_log -如果正在使用.htaccess,它会告诉您任何错误。在 .htaccess 中故意放置一个语法错误是一个很好的检查,以确保文件正在被使用——你应该在同一目录中的任何页面上得到 500 错误。
Lastly, you can enable a rewrite log using commands like the following in your httpd.conf:
最后,您可以在 httpd.conf 中使用如下命令启用重写日志:
RewriteLog "logs/rewritelog"
RewriteLogLevel 7
RewriteLog "日志/重写日志"
重写日志级别 7
The log file thus generated will give you the gory detail of which rewrite rules matched and how they were handled.
这样生成的日志文件将为您提供有关哪些重写规则匹配以及如何处理这些规则的详细信息。
回答by Milen A. Radev
No:
否:
Apache allows for decentralized management of configuration via special files placed inside the web tree. The special files are usually called
.htaccess, but any name can be specified in the AccessFileNamedirective... Since .htaccess files are read on every request, changes made in these files take immediate effect...
Apache 允许通过放置在网络树中的特殊文件对配置进行分散管理。特殊文件通常被称为
.htaccess,但可以在AccessFileName指令中指定任何名称...由于每次请求都会读取 .htaccess 文件,因此在这些文件中所做的更改会立即生效...
回答by PiedPiper
From the apache documentation: Most commonly, the problem is that AllowOverride is not set such that your configuration directives are being honored. Make sure that you don't have a AllowOverride None in effect for the file scope in question. A good test for this is to put garbage in your .htaccess file and reload. If a server error is not generated, then you almost certainly have AllowOverride None in effect.
来自 apache 文档:最常见的问题是 AllowOverride 未设置为使您的配置指令得到遵守。确保您没有对相关文件范围有效的 AllowOverride None。一个很好的测试是将垃圾放入 .htaccess 文件并重新加载。如果未生成服务器错误,那么您几乎可以肯定 AllowOverride None 已生效。
回答by ethyreal
Only if you have notadded the mod_rewrite module to Apache.
仅当您尚未将 mod_rewrite 模块添加到 Apache 时。
You only need to restart Apache if you change any Apache ".conf" files.
如果您更改了任何 Apache“.conf”文件,您只需要重新启动 Apache。
回答by Dave Ip
I have the same issue and it seems PiedPiper post about AllowOverride were most helpful. Check your httpd.conf file for "AllowOverride" and make sure it is set to All.
我有同样的问题,似乎 PiedPiper 关于 AllowOverride 的帖子最有帮助。检查您的 httpd.conf 文件中的“AllowOverride”并确保将其设置为 All。
回答by Abhishek Gurjar
In case of .htaccess restart is not required if it is not working probable reasons include.
如果 .htaccess 不工作,则不需要重新启动,可能的原因包括。
AllowOverrideMay not be set which user can set inside httpd.conf or might have to contact server admin.
Check the file name of .htaccess it should be .htaccess not htaccess.txt see herefor guide how to create one.
Try to use
Options -Indexesordeny allkind of simple directive to see if it is working or not.clear browser cache everytime if having rule for redirects or similar if previous redirect is cached it appears as if things are not working.
AllowOverride可能无法设置哪个用户可以在 httpd.conf 中设置或可能必须联系服务器管理员。
检查 .htaccess 的文件名,它应该是 .htaccess 而不是 htaccess.txt,请参阅此处了解如何创建一个文件。
尝试使用
Options -Indexes或deny all某种简单的指令来查看它是否有效。如果有重定向规则或类似规则,如果缓存了先前的重定向,则每次都清除浏览器缓存,它看起来好像没有工作。
回答by ceejayoz
What's in your .htaccess? RewriteRules? Check that mod_rewrite is installed and enabled.
您的 .htaccess 中有什么?重写规则?检查 mod_rewrite 是否已安装并启用。
Other stuff? Try setting AllowOverride to 'all' on that directory.
其他的东西?尝试在该目录上将 AllowOverride 设置为“all”。

