Welcome to WebmasterWorld Guest from 54.227.110.209

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

No not rewrite subdomains

     

alhermette

4:26 pm on May 7, 2012 (gmt 0)



I have the following in my .htaccess file

# Force www
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]


It was put there for SEO reasons to ensure that traffic to http://example.com was redirected to the www. address consistently.

I am now developing a subdomain and of course when I type in subdomain.example.com it helpfully directs me to www.example.com.

Can somebody help me get the syntax right so that only requests to http://example.com are redirected to www.example.com and not any other subdomains.

incrediBILL

6:20 pm on May 7, 2012 (gmt 0)

WebmasterWorld Administrator incredibill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



I would think changing from
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
to
RewriteCond %{HTTP_HOST} ^(example\.com)?$
Would do the trick

alhermette

7:59 pm on May 7, 2012 (gmt 0)



Thank you, that did the trick.

lucy24

2:16 am on May 8, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



Most specific to most general. Start with anything that applies to the subdomain, get it out of the way and then carry on as usual with the primary domain.

What if your requested host is example.com:80 or the like?

g1smd

6:42 am on May 8, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



There was a reason that the pattern was !^(www\.example\.com)?$ which is now negated by using something else.

Use this:

RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteCond %{HTTP_HOST} !^subdomain\.
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
 

Featured Threads

Hot Threads This Week

Hot Threads This Month