Welcome to WebmasterWorld Guest from 54.197.116.116

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Redirecting some IP address's to another page on the same website ?

   
10:52 am on Dec 26, 2009 (gmt 0)

10+ Year Member



Could anyone let me know if the code below is correct please ?

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]

4:01 pm on Dec 26, 2009 (gmt 0)

WebmasterWorld Senior Member wilderness is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



You need to insert an exception just above your closing line, else your going to get caught in a loop.

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.

4:28 pm on Dec 26, 2009 (gmt 0)

10+ Year Member



Thanks wilderness, how would the closing line look like, if it was for anyone from any of those IP address's viewing any page on websiteaddress.com please ?
4:33 pm on Dec 26, 2009 (gmt 0)

WebmasterWorld Senior Member wilderness is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



how would the closing line look like

what ever data is on

http://www.example.com/examplepage/index.php

as you've specified.

[edited by: jdMorgan at 3:48 am (utc) on Dec. 27, 2009]
[edit reason] example.com [/edit]

4:53 pm on Dec 26, 2009 (gmt 0)

10+ Year Member



But where does :

RewriteCond %{REQUEST_URI} !^examplepage/index.php$

come in ?

Getting a tad lost.

4:59 pm on Dec 26, 2009 (gmt 0)

WebmasterWorld Senior Member wilderness is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



But where does :

It prevents a continuious loop (request) for the same page.

1)requested page
2) redirect to requested page
3) loop (absent exception) duplicates initial request again
4) and again and again, until your server time-outs.

5:10 pm on Dec 26, 2009 (gmt 0)

10+ Year Member



Thanks, are we now saying that the complete code should read :

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]

5:24 pm on Dec 26, 2009 (gmt 0)

WebmasterWorld Senior Member wilderness is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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]

6:41 pm on Dec 28, 2009 (gmt 0)

10+ Year Member



Many thanks wilderness, (and Jim for the formatting), that's solved that one. Bearing in mind what is needed in this scenario, is {REMOTE_ADDR} better than {REMOTE_HOST} please ?
5:08 am on Dec 29, 2009 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Those are two different things.

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

Because these result in calls to the OS to go check the filesystem -- sometimes requiring a read of the physical disk. That and a few rDNS lookups can make for an awfully-slow server -- one reason why WP and Joomla with out-of-the box un-optimized .htaccess code don't 'scale' very well as traffic increases...

Jim

11:23 am on Dec 29, 2009 (gmt 0)

10+ Year Member



Thanks for the detailed reply Jim, will stick with the REMOTE_ADDR