Forum Moderators: phranque
I have been using the “deny from” for a long time, which has become messy and quite a huge list. I am in need of additional control and mod rewrite structure offers me more flexibility.
I have followed several tutorials out there, but confusion has me unsure if what I am doing is correctly done.
My new htaccess looks something like this:
RewriteEngine on# Block IP addresses
RewriteCond %{REMOTE_ADDR} ^000\.000\.000\.
RewriteCond %{REMOTE_ADDR} ^000\.000\.000\.000$# Block Domain Referers
RewriteCond %{HTTP_REFERER} (somesite\.com) [NC,OR]
RewriteCond %{HTTP_REFERER} (somesite \.net) [NC,OR]# Block User Agent
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} ^SpambotExample [OR]RewriteRule .* - [F]
Questions:
1.) Is it okay to keep my comments “# Some comment” in my htaccess for easy reference.
2.) For each Rewrite type do I need to insert the “RewriteEngine on” before each one… or is at the top of the htaccess all that is needed?
I appreciate any feedback to help assure I don’t blow something up ;) I like the mod Rewrite structure much better.
Thanks
-S
Several problems with directive ordering, and with missing and extra [OR] flags:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
#
# Block IP addresses
RewriteCond %{REMOTE_ADDR} ^000\.000\.000\. [b][OR][/b]
RewriteCond %{REMOTE_ADDR} ^000\.000\.000\.000$ [b][OR][/b]
#
# Block Domain Referers
RewriteCond %{HTTP_REFERER} somesite\.com [NC,OR]
RewriteCond %{HTTP_REFERER} othersite\.net [NC,OR]
RewriteCond %{HTTP_REFERER} nuthersite\.(net¦com) [NC,OR]
#
# Block User Agent
RewriteCond %{HTTP_USER_AGENT} ^SpambotExample
#
# Important -- No [OR] on last RewriteCond!
#
RewriteRule .* - [F]
Jim