0

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?

2
  • 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, 2011 at 2:24
  • We are slowly cleaning them up. Don't worry.
    – mauris
    Nov 3, 2011 at 10:33

1 Answer 1

1

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]
1
  • Whoops, I can't believe I didn't see that!! EPIC FAIL. Thanks!!
    – Lea Verou
    Nov 3, 2011 at 3:20

You must log in to answer this question.