如何调试的.htaccess重写规则不工作 [英] How to debug .htaccess RewriteRule not working
问题描述
我在未进行任何操作,的.htaccess
文件有一个重写规则
。我该如何解决呢?
I have a RewriteRule
in a .htaccess
file that isn't doing anything. How do I troubleshoot this?
- 如何验证,如果
的.htaccess
甚至被阅读和遵守Apache的文件?我可以写一个回声这是工作的消息,如果我不写,哪里会该行呼应了? - 如果不被使用的
的.htaccess
文件,我怎么才能让Apache使用它? - 如果在
的.htaccess
正在使用的,但我的重写规则
仍然没有效果,还有什么可我做的调试?
- 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?
推荐答案
输入一些垃圾值到的.htaccess
例如富栏
, sakjnaskljdnas
不被认可htaccess的任意关键字
并访问您的网址。如果是工作,你应该得到一个
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内部服务器错误
500 Internal Server Error
服务器遇到一个内部错误或配置错误,无法完成您的请求......
The server encountered an internal error or misconfiguration and was unable to complete your request....
我建议你把它后不久 RewriteEngine叙述上
。
因为你是你的机器上。我presume您可以访问到Apache .conf文件
文件。
Since you are on your machine. I presume you have access to apache .conf
file.
打开 .conf文件
文件,查找类似的行:
open the .conf
file, and look for a line similar to:
LoadModule rewrite_module modules/mod_rewrite.so
如果是被注释掉(#),取消并重新启动Apache。
If it is commented(#), uncomment and restart apache.
要改写记录
RewriteEngine On
RewriteLog "/path/to/rewrite.log"
RewriteLogLevel 9
把上面的3条线在你的虚拟主机
。重新启动httpd的。
Put the above 3 lines in your virtualhost
. restart the httpd.
RewriteLogLevel 9
使用了水平很高的价值将显着减慢你的Apache服务器!使用重写日志文件在一个水平仅大于2的调试!
9级将记录几乎每一个细节rewritelog
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.
事情已经在Apache的2.4改为:
Things have changed in Apache 2.4:
从2.2 升级到2.4
FROM Upgrading to 2.4 from 2.2
在 RewriteLog 和 RewriteLogLevel 指令已被删除。此功能现在由使用的LogLevel 指令配置日志的适当水平的mod_rewrite的模块提供。又见mod_rewrite的记录部分。
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.
有关更多的LogLevel,请参阅 LogLevel指令
For more on LogLevel, refer LogLevel Directive
您可以完成
RewriteLog "/path/to/rewrite.log"
在这种方式现在
LogLevel debug rewrite_module:debug
这篇关于如何调试的.htaccess重写规则不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!