0

My aim is to simulate virtual hosts using mod_rewrite in .htaccess such that http://dog.animal.com maps internally to WEBROOT/public_html/dog/ , cat.animal.com maps internally to WEBROOT/public_html/cat/ , where dog and cat are established usernames on the system.

I have (in an .htaccess in WEBROOT):

RewriteCond   %{HTTP_HOST}                 ^[^.]+\.animal\.com$
RewriteRule   ^(.+)                        %{HTTP_HOST}$1          [C]
RewriteRule   ^([^.]+)\.animal\.com(.*) /public_html/$1$2

But on requesting dog.animal.com I receive the following loop

Forbidden. You don't have permission to access /public_html/dogpublic_html/dogpublic_html/dogpublic_html/dogpublic_html/..... etc etc

Clearly I am overlooking something stupidly obvious. I'd appreciate any pointers!

(I should say that in the above example, there are A records in teh zone file for the two subdomains)

1 Answer 1

0

In your second rewrite rule, you use /public_html which refers to root. Try removing the starting / or put the full path with WEBROOT

5
  • I've tried modifying the replacement string, but always it gets repeated. Somehow, somewhere my RewriteCond is being matched again, hence the repetition of the filepath. I need to figure out how to have it stop after the first iteration. Removing 'root' does not affect this. Thanks, though.
    – Centzon
    Commented Oct 5, 2011 at 22:30
  • Maybe a hack, but try to put a [L] at the end of the last rewrite to stop the rewriting
    – crazyjul
    Commented Oct 5, 2011 at 22:51
  • I've read rules for rewrite are slightly different in .htaccess. By using a condition with HTTP_HOST, you do not need first rewrite rule, which add HTTP_POST in front of full URL
    – crazyjul
    Commented Oct 5, 2011 at 23:11
  • Unfortunately I do not have access to Apache's logs-- I'm working on a remote machine to which I have very limited access. Hence the .htaccess route; otherwise I'd just have virtualHosted my way through the problem in httpd.conf
    – Centzon
    Commented Oct 6, 2011 at 0:20
  • So remove the first rewriting rule should fix it
    – crazyjul
    Commented Oct 6, 2011 at 4:06

Your Answer

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

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