Welcome to WebmasterWorld Guest from 54.242.173.65

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

.htaccess Redirect from IP Address to Domain? Is this possible?

Redirect visitors who type in 12.34.56.78 to www.domain.com. Possible?

     
2:53 am on May 22, 2008 (gmt 0)

Full Member

10+ Year Member

joined:Aug 8, 2005
posts: 206
votes: 0


Is it possible, using .htaccess, to redirect a visitor who gets to my site by typing in its IP address, to the main website URL.

If the visitor types in [12.34.56.78...] I want them to be 301 redirected to [domain.com....]

Thanks for any help!

4:04 pm on May 22, 2008 (gmt 0)

Senior Member

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

joined:Mar 31, 2002
posts:25430
votes: 0


This subject has been well-covered here under various thread titles involving domain name canonicalization.

Here are two ways to do it with Apache mod_rewrite. The first is simplest, and should be used if you have no subdomains in addition to your "www" subdomain. The second is more selective and can be used with multiple subdomains, but provides less protection against incoming links with the "wrong" domain, because you must list all the "wrong" ones:


Options +FollowSymLinks
RewriteEngine on
#
# Redirect all requests for all non-canonical domains to same page in www.example.com
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

-or-

Options +FollowSymLinks
RewriteEngine on
#
# Redirect all requests for listed non-canonical domains to same page in www.example.com
RewriteCond %{HTTP_HOST} ^example\.com [OR]
RewriteCond %{HTTP_HOST} ^123\.45\.67\.89
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

There are many variations on the above, depending on what you need to do for your site(s). See the references cited in our Forum Charter and the tutorials in our forum library for more information.

Jim

11:19 pm on May 22, 2008 (gmt 0)

Full Member

10+ Year Member

joined:Aug 8, 2005
posts: 206
votes: 0


I am certain that my site can only be accessed at:
[12.34.56.78,...] [domain.com,...] and [domain.com,...] so I am going to select the second method and just list out the first two addresses.

I apologize for not locating the thread(s) in which this topic was previously covered. I'm a pretty senior member here -- I should know better ;).

5:26 am on May 27, 2008 (gmt 0)

Full Member

10+ Year Member

joined:Aug 8, 2005
posts: 206
votes: 0


-deleted-

Thank you for the help!

[edited by: FTFlash at 5:33 am (utc) on May 27, 2008]

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members