4

如何强制 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]

请帮我!

4

2 回答 2

8

试试这个:

RewriteRule ^forbid/(.*)$ - [F]

来源:http ://httpd.apache.org/docs/current/rewrite/flags.html#flag_f

于 2011-05-17T14:16:42.553 回答
1

除非您有一个RewriteBase我们在您的规则中看不到的定义,否则我认为您不希望^之前的“禁止”您的表达,因为它在技术上会以“/”开头

RewriteRule ^forbid/(.*)$ - [R=403,L]
# Instead try
RewriteRule ^/forbid/(.*)$ - [R=403,L]
# Or
RewriteRule forbid/(.*)$ - [R=403,L]
于 2011-05-17T14:13:13.907 回答