homepage Welcome to WebmasterWorld Guest from 23.23.57.144
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

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

10+ Year Member



 
Msg#: 4049584 posted 10:52 am on Dec 26, 2009 (gmt 0)

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]

 

wilderness

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



 
Msg#: 4049584 posted 4:01 pm on Dec 26, 2009 (gmt 0)

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.

Dexie

10+ Year Member



 
Msg#: 4049584 posted 4:28 pm on Dec 26, 2009 (gmt 0)

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 ?

wilderness

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



 
Msg#: 4049584 posted 4:33 pm on Dec 26, 2009 (gmt 0)

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]

Dexie

10+ Year Member



 
Msg#: 4049584 posted 4:53 pm on Dec 26, 2009 (gmt 0)

But where does :

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

come in ?

Getting a tad lost.

wilderness

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



 
Msg#: 4049584 posted 4:59 pm on Dec 26, 2009 (gmt 0)

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.

Dexie

10+ Year Member



 
Msg#: 4049584 posted 5:10 pm on Dec 26, 2009 (gmt 0)

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]

wilderness

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



 
Msg#: 4049584 posted 5:24 pm on Dec 26, 2009 (gmt 0)

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]

Dexie

10+ Year Member



 
Msg#: 4049584 posted 6:41 pm on Dec 28, 2009 (gmt 0)

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 ?

jdMorgan

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



 
Msg#: 4049584 posted 5:08 am on Dec 29, 2009 (gmt 0)

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

Dexie

10+ Year Member



 
Msg#: 4049584 posted 11:23 am on Dec 29, 2009 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved