403 redirect not working

How to make Apache redirect to 403 error?
I tried:

RewriteRule ^forbid/(.*)$ / [R=403,L] 

this caused an error of 500 servers throughout the site

RewriteRule ^forbid/(.*)$ - [R=403,L] 

and

RewriteRule ^forbid/(.*)$ [R=403,L] 

they just don't work
. I have the following .htaccess file:

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]

Please help me!

+3
source share
2 answers

Try this instead:

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

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

+6
source

If you don’t have RewriteBaseone that we don’t see in your rules, I think that you don’t want ^your expression to be “forbidden” since it starts with “/”

RewriteRule ^forbid/(.*)$ - [R=403,L]
# Instead try
RewriteRule ^/forbid/(.*)$ - [R=403,L]
# Or
RewriteRule forbid/(.*)$ - [R=403,L]
+1
source

All Articles