bahattab
22-12-2008, 11:15 PM
How to Redirect from IP Address to Domain by .htaccess ?
.htaccess Redirect from IP Address to Domain?
Is this possible?
Redirect visitors who type in 12.34.56.78 to www.domain.com (http://www.domain.com). Possible?
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 http://12.34.56.78 I want them to be 301 redirected to http://www.domain.com.
Thanks for any help!
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 (http://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 (http://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]
Or
RewriteCond %{REMOTE_ADDR} ^64\.126\.81\.30$ [OR]
RewriteCond %{REMOTE_ADDR} ^75\.117\.244\.27$
RewriteRule .* http://www.usdoj.gov/criminal/cybercrime/cyberstalking.htm [R,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.
I am certain that my site can only be accessed at:
http://12.34.56.78, http://domain.com, and http://www.domain.com, so I am going to select the second method and just list out the first two addresses.
http://www.webmasterworld.com/apache/3655980.htm
.htaccess Redirect from IP Address to Domain?
Is this possible?
Redirect visitors who type in 12.34.56.78 to www.domain.com (http://www.domain.com). Possible?
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 http://12.34.56.78 I want them to be 301 redirected to http://www.domain.com.
Thanks for any help!
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 (http://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 (http://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]
Or
RewriteCond %{REMOTE_ADDR} ^64\.126\.81\.30$ [OR]
RewriteCond %{REMOTE_ADDR} ^75\.117\.244\.27$
RewriteRule .* http://www.usdoj.gov/criminal/cybercrime/cyberstalking.htm [R,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.
I am certain that my site can only be accessed at:
http://12.34.56.78, http://domain.com, and http://www.domain.com, so I am going to select the second method and just list out the first two addresses.
http://www.webmasterworld.com/apache/3655980.htm