如何强制apache重定向到403错误?
我试过了:
RewriteRule ^forbid/(.*)$ / [R=403,L]
这导致整个网站出现500服务器错误
RewriteRule ^forbid/(.*)$ - [R=403,L]
和
RewriteRule ^forbid/(.*)$ [R=403,L]
这些根本不起作用
我有以下.htaccess文件:
RewriteEngine on
RewriteRule ^(config|backup)(.*)$ - [F] [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin/(.*)$ /admin/index.php?%{QUERY_STRING} [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !util
RewriteRule ^(.*)$ index.php?%{QUERY_STRING} [L,QSA]
拜托,帮助我!
答案 0 :(得分:7)
请改为尝试:
RewriteRule ^forbid/(.*)$ - [F]
来源:http://httpd.apache.org/docs/current/rewrite/flags.html#flag_f
答案 1 :(得分:1)
除非您定义了RewriteBase
我们未在规则中看到,否则我认为您不希望^
之前'禁止'您的表达,因为它从技术上开始于' /'
RewriteRule ^forbid/(.*)$ - [R=403,L]
# Instead try
RewriteRule ^/forbid/(.*)$ - [R=403,L]
# Or
RewriteRule forbid/(.*)$ - [R=403,L]