如何调试 .htaccess RewriteRule 不起作用 [英] How to debug .htaccess RewriteRule not working
问题描述
我在 .htaccess
文件中有一个 RewriteRule
没有做任何事情.我该如何解决这个问题?
- 我如何验证
.htaccess
文件是否被 Apache 读取并遵守?我可以写一个回声它正在工作"的消息,如果我写了,那行会在哪里回显? - 如果没有使用
.htaccess
文件,我如何让 Apache 使用它? - 如果正在使用
.htaccess
但我的RewriteRule
仍然没有效果,我还能做些什么来调试?
在 .htaccess
中输入一些垃圾值例如foo bar
, sakjnaskljdnas
htaccess 无法识别的任何关键字并访问您的网址.如果它工作正常,你应该得到一个
500 内部服务器错误
内部服务器错误
服务器遇到内部错误或配置错误,无法完成您的请求....
我建议你在 RewriteEngine on
之后尽快把它.
因为你在你的机器上.我想你可以访问 apache .conf
文件.
打开 .conf
文件,并查找类似于以下内容的行:
LoadModule rewrite_module modules/mod_rewrite.so
如果有注释(#),取消注释并重启apache.
<小时>日志重写
RewriteEngine OnRewriteLog "/path/to/rewrite.log"重写日志级别 9
将以上 3 行放在您的 virtualhost
中.重新启动httpd.
RewriteLogLevel 9
使用较高的 Level 值会显着降低 Apache 服务器的速度!使用级别大于 2 的重写日志文件仅用于调试!级别 9 将记录几乎所有 rewritelog 详细信息.
更新
Apache 2.4 发生了变化:
FROM 从 2.2 升级到 2.4
<块引用>RewriteLog 和 RewriteLogLevel 指令已被删除.现在通过使用 LogLevel 指令为 mod_rewrite 模块配置适当的日志记录级别来提供此功能.另请参阅 mod_rewrite 日志记录部分.
有关 LogLevel 的更多信息,请参阅 LogLevel 指令>
你可以做到
RewriteLog "/path/to/rewrite.log"
现在就这样
LogLevel 调试 rewrite_module:debug
I have a RewriteRule
in a .htaccess
file that isn't doing anything. How do I troubleshoot this?
- How can I verify if the
.htaccess
file is even being read and obeyed by Apache? Can I write an echo "it is working" message, if I do write it, where would that line be echoed out? - If the
.htaccess
file isn't being used, how can I make Apache use it? - If the
.htaccess
is being used but myRewriteRule
still isn't having an effect, what more can I do to debug?
Enter some junk value into your .htaccess
e.g. foo bar
, sakjnaskljdnas
any keyword not recognized by htaccess
and visit your URL. If it is working, you should get a
500 Internal Server Error
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request....
I suggest you to put it soon after RewriteEngine on
.
Since you are on your machine. I presume you have access to apache .conf
file.
open the .conf
file, and look for a line similar to:
LoadModule rewrite_module modules/mod_rewrite.so
If it is commented(#), uncomment and restart apache.
To log rewrite
RewriteEngine On
RewriteLog "/path/to/rewrite.log"
RewriteLogLevel 9
Put the above 3 lines in your virtualhost
. restart the httpd.
RewriteLogLevel 9
Using a high value for Level will slow down your Apache server dramatically! Use the rewriting logfile at a Level greater than 2 only for debugging!
Level 9 will log almost every rewritelog detail.
UPDATE
Things have changed in Apache 2.4:
FROM Upgrading to 2.4 from 2.2
The RewriteLog and RewriteLogLevel directives have been removed. This functionality is now provided by configuring the appropriate level of logging for the mod_rewrite module using the LogLevel directive. See also the mod_rewrite logging section.
For more on LogLevel, refer LogLevel Directive
you can accomplish
RewriteLog "/path/to/rewrite.log"
in this manner now
LogLevel debug rewrite_module:debug
这篇关于如何调试 .htaccess RewriteRule 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!