redirect http://*.example.com to http://www.example.com/*

Discussion in 'Apache' started by FFMG, May 9, 2013.

  1. #1
    FFMG, May 9, 2013 IP
  2. RoseHosting

    RoseHosting Well-Known Member

    Messages:
    230
    Likes Received:
    11
    Best Answers:
    11
    Trophy Points:
    138
    #2
    Create a .htaccess file containing the following lines:

    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} ^example\.com [NC]
    RewriteRule (.*) http://www.example.com/$1 [L,R=301]
    RewriteCond %{HTTP_HOST} !^(www\.)?example\.com [NC]
    RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
    RewriteRule ^(.*)$ http://example.com/%1/$1 [L,NC,QSA]
    Code (markup):
    Don't forget to change 'example.com' with your actual domain name.
     
    RoseHosting, May 9, 2013 IP