Forum Moderators: phranque

Message Too Old, No Replies

Wildcard Domains

         

Brett_Tabke

6:28 pm on Sep 17, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Lets say I have 10 domains pointed at a main domain. How can I rewrite all 10 to redirect to the main domain if it isn't the main domain?

For instance, I have WebmasterWorld setup this way:

RewriteCond %{HTTP_HOST} ^72\.3\.232\.139 [OR]
RewriteCond %{HTTP_HOST} .mobi [OR]
RewriteCond %{HTTP_HOST} .cn [OR]
RewriteCond %{HTTP_HOST} ^webmasterworld\. [NC,OR]
RewriteCond %{HTTP_HOST} ^mail\.webmasterworld\. [NC]
RewriteRule ^(.*) [webmasterworld.com...] [R=301,L]

So essentially, I want to do a not www.webmasterworld.com, and redirect with a hard 301 to the main domain.

jdMorgan

10:47 pm on Sep 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use:

# If not exactly "www.webmasterworld.com" (or blank if HTTP/1.0)
RewriteCond %{HTTP_HOST} !^(www\.webmasterworld\.com)?$
# externally redirect to www.webmasterworld.com
RewriteRule (.*) http://www.webmasterworld.com/$1 [R=301,L]

This takes care of case errors and trailing dots or port numbers as well.

[added] Accepting a blank hostname prevents an infinite redirection loop if the request is made with HTTP/1.0 and the Host header is not sent. [/added]

Jim

[edited by: jdMorgan at 10:48 pm (utc) on Sep. 17, 2008]