Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a domain (lets call it bar.com) and I want the default hostname to be foo.bar.com. So, bar.com would be redirected to foo.bar.com and foo.bar.com would correspond to the main httpdocs folder (I don't want my entire site to be in subdomains/foo/httpdocs, that's just plain ugly and redundant).

I've set foo.bar.com as an alias to bar.com in Plesk and that works fine. Then, to redirect bar.com to foo.bar.com I used an .htaccess with the following:

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

However, as you have probably figured by now, this results in a redirect loop.

Any ideas?

share|improve this question

migrated from stackoverflow.com Nov 4 '11 at 8:00

This question came from our site for professional and enthusiast programmers.

    
To the ones voting to close this as off-topic: Maybe you should take a look at the THOUSANDS of similar threads in stackoverflow. I did, before I opened this to make sure it's not off topic. –  Lea Verou Nov 3 '11 at 2:24
    
We are slowly cleaning them up. Don't worry. –  mauris Nov 3 '11 at 10:33

1 Answer 1

up vote 1 down vote accepted

You left out a ! in your RewriteCond to indicate that you DON'T want the host to be foo.bar.com:

RewriteCond %{HTTP_HOST} !^foo\.bar\.com
RewriteRule ^(.*)$ http://foo.bar.com/$1 [R=301,L]
share|improve this answer
    
Whoops, I can't believe I didn't see that!! EPIC FAIL. Thanks!! –  Lea Verou Nov 3 '11 at 3:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.