Forum Moderators: phranque
If the visitor types in [12.34.56.78...] I want them to be 301 redirected to [domain.com....]
Thanks for any help!
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]
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]
Jim
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 ;).