Redirect subdomain from http://www to just http://

Is the sub domain on the same server as your main domain?
If it is let me know and we'll try something else.
But this should do it ~

RewriteEngine On
RewriteCond %{HTTP_HOST} !^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://sub.domain.com/$1 [R=301,L]


Any problems let me know as that should work.

Jaz

Key:
Red ~ Mod_Rewrite
 
Thanks for the quick reply. Yeah they are on the same server. The problem is I move the default domain for testing sometimes. So the site that shows up if you just type in the IP (or mistype a subdomain) may be a random website I'm working on, not even related to the the main domain.
 
Well try that first as it should be fine thinking about it.

If not we can try to get fancy, haven't worked with redirects and sub domains before TBH but there are a few things we can try if it doesn't, but that should work, let me know either way. :)

Jaz
 
OK try adding the ServerAlias directive above turning the RewriteEngine on and see if that makes any difference.
So....

ServerAlias *.yourdomain.com
RewriteEngine On
RewriteCond %{HTTP_HOST} !^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://sub.domain.com/$1 [R=301,L]


Jaz

Red ~ Mod_Rewrite
 
I'm getting a internal error when I go to the site. Is this a situation where I would just need to modify the htaccess file for the default site for the subdomain. That way they just get redirected to the correct subdomain from the default domain?
 
I would put them in the main root that being ~ domain.com/.htaccess as the sub domain should still be taking the rules from the main domain. But try the first solution first when you do.
 
pablo631 said:
Sometimes users forget to NOT type in www. when trying to access a subdomain.
I never enter www. to reach a subdomain. That's just silly and I've never run into any problems before either :confused:
 
Back
Top