Search code examples
.htaccessurl-rewriting

htaccess redirect subdomain to root domain


I want to redirect this subdomain:

http://abc.domain-name.com

to a folder on the root domain that uses the same name:

http://www.domain-name.com/abc

This way, if I try to access the following file:

http://abc.domain-name.com/folder/file.html

It will go to:

http://www.domain-name.com/abc/folder/file.html

Solution

  • Try this:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^subdomain\.yourdomain\.com
    RewriteRule ^(.*)$ http://www\.yourdomain\.com/subdomain/$1 [L]
    

    (from http://systembash.com/content/simple-redirect-subdomain-to-a-directory/)