Carrlos Boyd
Carrlos Boyd

Reputation: 147

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

Upvotes: 11

Views: 38926

Answers (2)

Saeed
Saeed

Reputation: 493

You should consider about search engines and use permanent redirect (301), also its best practice to use NC flag at the end if second line to be matched in a case-insensitive manner.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.example\.com  [NC]
RewriteRule ^(.*) http://www.example.com/$1 [L,R=301]

Upvotes: 8

nandhp
nandhp

Reputation: 4817

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/)

Upvotes: 25

Related Questions