Personal Loans - Debt Consolidation - Find a Better Job - Mortgage - Web Advertising

PDA

View Full Version : .htaccess help for redirecting subdomain


zenite
Feb 16th 2008, 9:06 pm
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

zenite
Feb 20th 2008, 3:42 am
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]

shyboy
Feb 22nd 2008, 8:44 am
how do i direct a site from http://mydomain.co.uk to http://www.mydomain.co.uk?

zenite
Feb 23rd 2008, 12:41 pm
how do i direct a site from http://mydomain.co.uk to http://www.mydomain.co.uk?


#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]

this should work. I used it for .com but see no reason why it will fail on .co.uk

kulinar
Feb 25th 2008, 5:13 am
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.co.uk/$1 [R=301,L]