homepage Welcome to WebmasterWorld Guest from 54.161.236.229
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
.htaccess subdomain redirect problem
TechMan




msg:4246044
 2:55 pm on Dec 25, 2010 (gmt 0)

Hi,

I have a website let's say www.webmasterworld.com

And I have a subdomain something.webmasterworld.com

Both main domain and sub domain are pointing to directory "public_html"

I have .htaccess on root which redirects any URL without www to www. For e.g. if user enters webmasterworld.com then he will be redirected to www.webmasterworld.com If user enters webmasterworld.com/mypage.htm then he will be redirected to www.webmasterworld.com/mypage.htm

Now the problem is this is also affecting my subdomain. Because if someone enters something.webmasterworld.com/visit.htm then he is redirect to www.webmasterworld.com/visit.htm

I don't want this! If user enters subdomain then I don't want to redirected to www domain. This is what I have in my .htacces file

RewriteCond %{HTTP_HOST} !^www.webmasterworld.com$ [NC]

RewriteRule ^(.*)$ [webmasterworld.com...]

[R=301,L]

Can you please tell me what should I do to solve above problem?

Thanks

 

g1smd




msg:4246046
 3:00 pm on Dec 25, 2010 (gmt 0)

RewriteCond %{HTTP_HOST} !^((sub|www)\.example\.com)?$ [NC]

Don't forget to escape literal periods in RegEx patterns.

TechMan




msg:4246140
 6:42 am on Dec 26, 2010 (gmt 0)

Thanks man!

jdMorgan




msg:4249400
 4:23 pm on Jan 5, 2011 (gmt 0)

There is apparently a formatting problem with the code, or with the code as posted here. Also, the use of [NC] in the RewriteCond is not advisable, since the apparent goal is to fully-canonicalize these subdomains. In the interest of clarity, the correctly-formatted solution would be:

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

Jim

g1smd




msg:4249488
 7:22 pm on Jan 5, 2011 (gmt 0)

Yes, the [NC] was a typo. Remove it.

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