2

I have tried a number of ways to try to redirect a sub url in my htaccess file with very little progress, and I know I am doing it correctly but for some reason it just is not working, and as far as I can tell there is no module that can do this. I am simply trying to direct a sub domain to the main domain.

This is the code I am using.

  RewriteBase /
  RewriteRule ^red.sitename.com$ http://sitename.com/ [R=301,L]

Now I have red somewhere that you have to do it this a certain way when clean urls is enabled and this is suppose to be the correct way but it is not working.

1 Answer 1

4

The piece you are missing is RewriteCond.

This should redirect just the subdomain

RewriteBase /
RewriteCond %{HTTP_HOST} ^red\.sitename\.com$ [NC]
RewriteRule ^(.*)$ http://sitename.com/$1 [L,R=301]

Note also that the separator needs to be escaped as \. to prevent it from being used as a single character match in the pattern. The [NC] also tells Apache to ignore case during the match.

0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.