Forum Moderators: phranque

Message Too Old, No Replies

How to write a URL in .htaccess

         

Maleville

7:07 am on Mar 4, 2004 (gmt 0)

10+ Year Member



Hello.

If I want to exclude some bad guys, is this written correctly:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REMOTE_REFERER} ^http\:\/\/www2\.example\.com\/fr\/example\/modeles\/HTML\/page\.asp.*$ [OR]
RewriteCond %{REMOTE_HOST} ^.*lavache-102-X-1-91\.w193-251\.abo\.example\.fr.*$ [NC]
RewriteRule .* [other.com...] [R,L]

Is this shortest way better:

RewriteCond %{REMOTE_REFERER} ^example\.com/fr/example/modeles/HTML/page\.asp [OR]
RewriteCond %{REMOTE_HOST} ^lavache-102-X-1-91\.w193-251\.abo\.example\.fr [NC]

[edited by: jdMorgan at 8:05 am (utc) on Mar. 4, 2004]
[edit reason] examplified URLs & IPs [/edit]

jdMorgan

8:14 am on Mar 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteCond %{REMOTE_REFERER} ^http://www2\.example\.com/fr/example/modeles/HTML/page\.asp [OR]
RewriteCond %{REMOTE_HOST} ^.*lavache-102-X-1-91\.w193-251\.abo\.example\.fr [NC]
RewriteRule .* - [F]

Avoid using {REMOTE_HOST} if at all possible. This requires your server to do a DNS lookup on each and every request that matches your RewriteRule, and is very SLOW. If possible, use the bad guy's {REMOTE_ADDR} (IP address) instead.
Also, most "bad guys" won't follow an external redirect, so just give them a simple 403-Forbidden response as shown with "[F]".

Jim

hyperbole

7:31 pm on Mar 5, 2004 (gmt 0)

10+ Year Member



Why would you use Rewrite instead of deny for this?

jdMorgan

7:46 pm on Mar 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



An interesting question.

I do it to keep my server error logs neat and trim. If you use 'Deny' you get an entry in the server error log reading "Client denied by server configuration," plus the usual 403 entry in your access log. If you use mod_rewrite, you get only the access log entry. I prefer to reserve my error log for serious errors -- If my error log's not empty, it means I have some 'repair' work to do.

The above behaviour may just be a result of the way my servers are configured, but it works for me. Otherwise, there's no real advantage either way. I actually use both methods for different purposes.

Jim