homepage Welcome to WebmasterWorld Guest from 54.204.64.152
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
No not rewrite subdomains
alhermette




msg:4450405
 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




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

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

alhermette




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

Thank you, that did the trick.

lucy24




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

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




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

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]

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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved