homepage Welcome to WebmasterWorld Guest from 54.205.207.53
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
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#: 4450403 posted 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

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



 
Msg#: 4450403 posted 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#: 4450403 posted 7:59 pm on May 7, 2012 (gmt 0)

Thank you, that did the trick.

lucy24

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



 
Msg#: 4450403 posted 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

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4450403 posted 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.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved