[thelist] RewriteRule for entire site?

misterhaan misterhaan at track7.org
Wed Aug 16 13:43:54 CDT 2006


I'm trying to use apache mod_rewrite to give some spammers and annoying 
useragents a 403 page, but it appears to only work on requests for pages 
in the root directory.  I have the following in the .htaccess at the web 
root (I have a lot more lines, but you probably don't need to see that):

RewriteEngine on
#some rules not for spammers, etc.
RewriteCond %{HTTP_REFERER} ^http://[^/]*$ [NC,OR]
# more referrer conditions, all with [NC,OR]
# a few ip conditions, with [OR]
# a few user agent conditions, with [NC,OR], except the last one which 
is just [NC]
RewriteRule !(403\.php|\.css|\.png|\.ico) - [F,L]

I'm allowing access to my 403 page as well as the files it references, 
but it also behaves the same if i use this rule instead:
RewriteRule .* - [F,L]

Like I said, it works fine for requests like http://www.example.org/ or 
http://www.example.org/somepage.php, but it gets ignored for requests 
like http://www.example.org/somedir/ or 
http://www.example.org/somedir/somepage.php.

Do I really need to have a copy of all these rewrite conditions in an 
.htaccess file in every directory?  I'm also open to suggestions on 
better ways to achieve this, as long as they still use my custom 403 
page -- mod_rewrite is the only way I know of besides doing it through 
php, which I expect would be slower.



More information about the thelist mailing list