htaccess 301 redirect

Discussion in 'Apache' started by deriklogov, Sep 18, 2014.

  1. #1
    Hi,
    I know that probably this question already been asked but I cant find answer on it.
    I need to do, needs to be done thru .htaccess:

    redirect domain from non www to www including all sub folders

    so it someone types domain.com/test1 it should be redirected to www.domain.com/test1

    and redirect all subdomains on domain to their folders

    so if subdomain is test1.domain.com it should be redirected to www.domain.com/test1

    Please help, I need it urgent
     
    deriklogov, Sep 18, 2014 IP
  2. Krellen

    Krellen Greenhorn

    Messages:
    38
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    18
    #2
    RewriteEngine on
    RewriteBase /
    
    # Force WWW
    RewriteCond %{HTTP_HOST} ^domain.com$
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
    Code (markup):
     
    Krellen, Sep 21, 2014 IP