Welcome to WebmasterWorld Guest from 54.226.246.160

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

.htaccess subdomain redirect problem

     

TechMan

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

5+ Year Member



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

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

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



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


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

TechMan

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

5+ Year Member



Thanks man!

jdMorgan

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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

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



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

Featured Threads

Hot Threads This Week

Hot Threads This Month