0

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/

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Sean, that does the trick. Do you mind explaining the RewriteCond line, is that a wildcard search for the term 'shop' in the URL, or is it specific to the fact 'shop' is a subdomain?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.