homepage Welcome to WebmasterWorld Guest from 54.204.58.87
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

    
.htaccess Redirect from IP Address to Domain? Is this possible?
Redirect visitors who type in 12.34.56.78 to www.domain.com. Possible?
FTFlash




msg:3655982
 2:53 am on May 22, 2008 (gmt 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!

 

jdMorgan




msg:3656478
 4:04 pm on May 22, 2008 (gmt 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

FTFlash




msg:3656930
 11:19 pm on May 22, 2008 (gmt 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 ;).

FTFlash




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

-deleted-

Thank you for the help!

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

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