4

How to force apache to redirect to a 403 error?
I've tried:

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

this caused 500 server error on the whole site

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

and

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

these simply 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!

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
tsds
  • 8,700
  • 12
  • 62
  • 83

2 Answers2

8

Try this instead:

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

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

onteria_
  • 68,181
  • 7
  • 71
  • 64
1

Unless you have a RewriteBase defined that we don't see in your rules, I think you don't want the ^ before 'forbid' your expression, since it would technically start with '/'

RewriteRule ^forbid/(.*)$ - [R=403,L]
# Instead try
RewriteRule ^/forbid/(.*)$ - [R=403,L]
# Or
RewriteRule forbid/(.*)$ - [R=403,L]
Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
  • actually, I have RewriteBase, but I forgot to copy that. But anyway this doesn't make any sense. – tsds May 17 '11 at 14:41