I been searching around but cant find a solution to this, so pls help. I have a subdomain that I want to redirect using .htaccess. from www.domain.com/subdomain to www.subdomain.domain.com and also to remove the www from www.subdomain.domain.com to http://subdomain.domain.com I tried the following but it didn't work. #remove www RewriteEngine On RewriteCond %{HTTP_HOST} ^www.subdomain.domain.com [NC] RewriteRule ^(.*)$ http://subdomain.domain.com/$1 [L,R=301] #redirect directory to subdomain RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com RewriteRule (.*) http://subdomain.domain.com/$1 [L,R=301] what it does is redirect www.subdomain.domain.com to www.domain.com/subdomain/ and does nothing to the www. pls specify if the .htaccess should be uploaded to the public_html folder or public_html/subdomain folder
ok, I finally figured it out. giving out the code in case someone else needs it too. heres the code for removing www. I uploaded .htaccess to my subdirectory since this code seems to be not working when in the main directory. #remove www RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.(.+)$ RewriteRule ^(.*)$ http://%1/$1 [R=301,L] ---- or --- #insert www RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] ---- this is for redirecting domain.com/subdomain to subdomain.domain.com #redirect directory to subdomain RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com RewriteRule (.*) http://subdomain.domain.com/$1 [L,R=301]
#301 redirect RewriteEngine on RewriteCond %{HTTP_HOST} . RewriteCond %{HTTP_HOST} !^www\.mydomain\.co.uk RewriteCond %{HTTP_HOST} !^mydomain.co.uk RewriteRule (.*) http://www.mydomain.co.uk/$1 [R=301,L] PHP: this should work. I used it for .com but see no reason why it will fail on .co.uk
[B]Options +FollowSymlinks RewriteEngine On[/B] [B]RewriteCond %{HTTP_HOST} ^[/B]mydomain.co.uk[B]$ [NC] RewriteRule ^(.*)$ http://www.[/B]mydomain.co.uk[B]/$1 [R=301,L][/B] Code (markup):