0

I have two domains that are aliases, domain1.com and domain2.com Currently they are both directed into the same place, the root of my web space. However, I wish to separate them into independent pages and direct domain2.com into a subfolder with different content.

I understand that the correct way to do this is using Apache Virtual Hosts. However, my service provider does not allow me access to that functionality so I'll have to solve it using mod_rewrite.

What I need is something that directs www.domain2.com and domain2.com to subfolder/ (which should trigger index.php). Also, www.domain2.com/file.txt should go to subfolder/file.txt, etc... This is what I came up with:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} domain2\.com [NC]
RewriteRule ^(.*)$ subfolder/$1 [L]
</IfModule>

However, when I run it and go to domain2.com, I get 500 Internal Server Error and the log file says:

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

To test what's going on I made a small php script that prints out the string that it gets. I also modified the rule:

RewriteRule ^(.*)$ subfolder/test.php?string=$1 [L]

Now when I go to domain2.com or domain2.com/asd, it prints out: subfolder/test.php Somehow it gets into recursion and prints itself. Whereas, if I use the following rule:

RewriteRule ^abc(.*)$ subfolder/test.php?string=$1 [L]

Then domain2.com/abcdef prints: def

I can't figure out what I'm doing wrong. Do you have any suggestions? Thanks!

1 Answer 1

0

It could be that the rewrite rule applies to subfolders of the one whose .htaccess it appears in. Does it help to add a condition that blocks the rewrite for URLs that already start with subfolder/?

1

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.