Forum Moderators: phranque
RewriteEngine on
RewriteCond %{REMOTE_ADDR} ^80\.xyz\.114\.34$ [OR]
RewriteCond %{REMOTE_ADDR} ^81\.xyz\.221\.49$ [OR]
RewriteCond %{REMOTE_ADDR} ^83\.xyz\.91\.24$ [OR]
RewriteCond %{REMOTE_ADDR} ^86\.xyz\.156\.151$
RewriteRule ^(.*)$ http://www.example.com/examplepage/index.php [L]
Also, instead of {REMOTE_ADDR} - should it be {REMOTE_HOST} ? ?
Any help appreciated.
Dexie.
[edited by: jdMorgan at 3:49 am (utc) on Dec. 27, 2009]
[edit reason] example.com [/edit]
RewriteCond %{REQUEST_URI} !^examplepage/index.php$
Additionally, I would suggest two things:
1) Denying access based solely on a solitary Class D range will come back to bite you in the backside (i. e. expand the Class D range).
2) You might explore multiple conditions based on both REMOTE_ADDR and USER_AGENT or REMOTE_ADDR and other criteria.
RewriteEngine on
RewriteCond %{REMOTE_ADDR} ^80\.xyz\.114\.34$ [OR]
RewriteCond %{REMOTE_ADDR} ^81\.xyz\.221\.49$ [OR]
RewriteCond %{REMOTE_ADDR} ^83\.xyz\.91\.24$ [OR]
RewriteCond %{REMOTE_ADDR} ^86\.xyz\.156\.151$
RewriteCond %{REQUEST_URI} !^examplepage/index.php$
[edited by: jdMorgan at 3:48 am (utc) on Dec. 27, 2009]
[edit reason] formatting [/edit]
You need to insert an exception just above your closing line
RewriteEngine on
RewriteCond %{REMOTE_ADDR} ^80\.xyz\.114\.34$ [OR]
RewriteCond %{REMOTE_ADDR} ^81\.xyz\.221\.49$ [OR]
RewriteCond %{REMOTE_ADDR} ^83\.xyz\.91\.24$ [OR]
RewriteCond %{REMOTE_ADDR} ^86\.xyz\.156\.151$
RewriteCond %{REQUEST_URI} !^/examplepage/index.php$
RewriteRule ^(.*)$ http://www.example.com/examplepage/index.php [L]
[edited by: jdMorgan at 3:47 am (utc) on Dec. 27, 2009]
[edit reason] Example.com and fixed a typo. [/edit]
REMOTE_ADDR is an IP address, taken from the TCP/IP stack for this incoming connection (i.e. no extra work involved).
REMOTE_HOST is the result of your server issuing a reverse-DNS lookup request to the DNS system (which may be local to your host, or not) and getting the hostname to which that requesting IP address belongs. This requires the server (and the client) to wait while the DNS request is sent and serviced, and the response is sent back.
In some cases, reverse-DNS lookups are not supported on a server, in which case REMOTE_HOST will return the original IP address unchanged.
Best practices are to avoid reverse DNS lookups. If they can't be avoided entirely, then next-best is to only do them in limited circumstances -- for example, only for 'page' requests, and not for every image, stylesheet, external JavaScript file, favicon, object (etc.) referenced by those pages. If you do an rDNS lookup for every HTTP request and the traffic to your site grows, you can expect to have to upgrade your server so that it can handle all the extra work and all of the connections queued and waiting for rDNS lookups to complete. All these lookups can bring a busy site to its knees.
Another thing to avoid is unnecessary file- and directory-exists checks, as in the unconditional, wasteful, and all-too-common code sequence:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST)FILENAME} !-d
Jim