| .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.
|
|
|