1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

.htaccess help for redirecting subdomain

Discussion in 'Apache' started by zenite, Feb 16, 2008.

  1. #1
    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 16, 2008 IP
  2. zenite

    zenite Peon

    Messages:
    240
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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]
     
    zenite, Feb 20, 2008 IP
  3. shyboy

    shyboy Well-Known Member

    Messages:
    682
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    150
    #3
    shyboy, Feb 22, 2008 IP
  4. zenite

    zenite Peon

    Messages:
    240
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4

    #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
     
    zenite, Feb 23, 2008 IP
  5. kulinar

    kulinar Member

    Messages:
    45
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #5
    [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):
     
    kulinar, Feb 25, 2008 IP