Reputation: 3194
I had a subdomain setup with an A record, this subdomain is now no longer active, and is pointing to the root of the hosting account.
How can I create a htaccess redirect to direct the subdomain, shop.domain.com to domain.com/shop
As the subdomain now points to domain.com, if I use the following redirect it obviously doesn't work:
Redirect 301 "/" http://www.domain.com/shop/
Upvotes: 0
Views: 76
Reputation: 120634
You can use mod_rewrite
for this:
RewriteCond %{HTTP_HOST} ^shop\.
RewriteRule (.*) http://www.domain.com/shop/$1 [R=301,L]
The RewriteCond
checks to make sure that the hostname of the request begins with the string "shop." and if so, the subsequent RewriteRule
is evaluated.
The ^
before shop
ensures that it only matches the string "shop" if it is at the beginning of the hostname.
Upvotes: 1