Forum Moderators: phranque

Message Too Old, No Replies

Redirect users using IP address to access the site to site using DNS

         

techy2000

10:06 pm on Feb 27, 2008 (gmt 0)

10+ Year Member



Some users are accessing our site (e.g. www.xyz.com) using the individual IP addresses of the Apache servers behind the site's Virtual IP instead of the site's DNS name. Since the site is hosted by a 3rd party the Apache IP addresses resolve to a different domain name (*.pqr.com) than the Site's domain name (*.xyz.com) leading to cookie and domain mismatch.

The solution that I plan to implement is to redirect any user who accesses the site using an IP address (e.g. xx.#*$!.#*$!.#*$!) to www.xyz.com

I am new to Apache re-write rules and need guidance on how this can be done.

The HOST attribute in the header will contain an IP address or the domain name that has been used to access the site.
If it is an IP address, we need to redirect the user to www.xyz.com

techy2000

10:41 pm on Feb 27, 2008 (gmt 0)

10+ Year Member



RewriteEngine on
RewriteCond %{HTTP_HOST} ^10\.10\.177\.
RewriteRule (.*) [xyz.com...] [R=301,L]

I am using the following rule after looking at some similar posts in the forum

jdMorgan

1:45 am on Feb 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Good enough, although since you're not using a back-reference, there is no need for the parentheses in the RewriteRule pattern.

Jim