When to start and finish the rewrite?

Is this the right way :


RewriteEngine on
RewriteCond %{REMOTE_ADDR} ^1\\.24\\.192\\. [OR]
RewriteCond %{REMOTE_ADDR} ^14\\.45\\.40\\. [OR]
RewriteCond %{REMOTE_ADDR} ^7\\.14\\.248\\. [OR]
RewriteCond %{REMOTE_ADDR} ^7\\.19\\.17\\. [OR]
RewriteCond %{REMOTE_ADDR} ^8\\.147\\.111\\.126$
RewriteRule /403.php [L,R=301]
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xaldon\\ WebSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus
RewriteRule ^.* - [F,L]

Or this :


RewriteEngine on
RewriteCond %{REMOTE_ADDR} ^1\\.24\\.192\\. [OR]
RewriteCond %{REMOTE_ADDR} ^14\\.45\\.40\\. [OR]
RewriteCond %{REMOTE_ADDR} ^7\\.14\\.248\\. [OR]
RewriteCond %{REMOTE_ADDR} ^7\\.19\\.17\\. [OR]
RewriteCond %{REMOTE_ADDR} ^8\\.147\\.111\\.126$
RewriteRule /403.php [L,R=301]

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xaldon\\ WebSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus
RewriteRule ^.* - [F,L]

? ?

Also, I’m still learning on all of this .htaccess stuff, so please feel free to pass any comments on any other parts of the code.

From those two options the first is the right way; you only need to “start the engine” once. Although I prefer to leave an empty line between blocks for readability.


RewriteEngine on
RewriteCond %{REMOTE_ADDR} ^1\\.24\\.192\\. [OR]
RewriteCond %{REMOTE_ADDR} ^14\\.45\\.40\\. [OR]
RewriteCond %{REMOTE_ADDR} ^7\\.14\\.248\\. [OR]
RewriteCond %{REMOTE_ADDR} ^7\\.19\\.17\\. [OR]
RewriteCond %{REMOTE_ADDR} ^8\\.147\\.111\\.126$
RewriteRule /403.php [L,R=301]

RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xaldon\\ WebSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus
RewriteRule ^.* - [F,L]

For the last part, I would add [NC] to the flags to make it case insensitive; that way it will also match “blackwidow”, “blAckWiDoW”, etc.


RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^Xaldon\\ WebSpider [OR,NC]
RewriteCond %{HTTP_USER_AGENT} ^Zeus
RewriteRule ^.* - [F,L]

Also, don’t use ^.* (see your other thread on this)

Lastly, why redirect to 403.php? Is access Forbidden for those IPs ?
Note which letter I made bold there