我不是mod重写方面的专家。我正在尝试在我的根目录的.htaccess中重写多个规则,如下所示:
RewriteEngine On
#HEADER REDIRECTION
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#FINISH HEADER REDIRECTION
#PREVENT IF NOT USER_AGENT
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule .* - [F]
#FINISH PREVENT IF NOT USER_AGENT
#PREVENT UNEXPECTED USER_AGENT STRING
RewriteCond %{HTTP_USER_AGENT} ^Custo [OR]
RewriteCond %{HTTP_USER_AGENT} ^FlashGet [OR]
RewriteCond %{HTTP_USER_AGENT} ^GetRight [OR]
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]
RewriteCond %{HTTP_USER_AGENT} ^aHMView
RewriteRule .* - [F]
#FINISH PREVENT UNEXPECTED USER_AGENT STRING
#BYPASS STRANGERS
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{HTTP_REFERER} !^http://www.site.com [NC]
RewriteRule .* - [F]
#FINISH PYPASS STRANGERS
但规则导致内部服务器错误500
有什么错吗?如果是的话,我该怎么写呢?
感谢,
答案 0 :(得分:1)
尝试使用“基本.htaccess代码语法检查程序和验证程序”http://www.lyxx.com/freestuff/002.html或“.htaccess validator v1.06”http://shop.alterlinks.com/htaccess-validator/htaccess-validator.php
答案 1 :(得分:1)
你的规则是完整的。他们在vanilla Apache 2.2服务器上的空白htaccess文件中为我工作。您可能没有加载mod_rewrite。检查httpd.conf中的行,如下所示:
LoadModule rewrite_module modules/mod_rewrite.so
未被注释掉。