Forum Moderators: phranque
I'm new to mod_rewrite module, so don't blame me for my newbie question :)
Here it is. I have a "main" domain called main.com, and I have subdomain called sub.main.com. Then I have 2 cms systems installed /cms1 and /cms2, they can be accessed either from main domain or subdomain, thus I need to redirect users to correct cms system, e.g. if they ask for main.com/index.html they would get main.com/cms1/index.php
I tries to solve it by myseld and, the first thing I did is that I worte redirect php script, that was analysing if request comes from main.com, then redirect to main.com/cms1/ if resource requested from sub.main.com redirect to sub.main.com/cms2/
Then I've added the following rewrite rule
RewriteRule ^(.*)$ redirect.php?param=$1 [L]
And of course you know what has happened :) (dead loop)
I think that's not a unique case, and someone has solved it already. Could you please give an advise how it can be solved.
Thanks in advance,
Alex
Welcome to WebmasterWorld!
If I understand your question, you can get rid of redirect.php, and simply use:
RewriteCond %{HTTP_HOST} ^(www\.)?main\.com
RewriteCond %{REQUEST_URI} !^/cms1/
RewriteRule ^([^.]+)\.html$ /cms1/$1.php [L]
#
RewriteCond %{HTTP_HOST} ^(www\.)?sub\.main.com
RewriteCond %{REQUEST_URI} !^/cms2/
RewriteRule ^([^.]+)\.html$ /cms2/$1.php [L]
Jim
# Forbid access to cms2 from main domain
RewriteCond %{HTTP_HOST} ^(www\.)?main\.com
RewriteRule ^cms2/ - [F]
You can handle that case this way if you prefer:
RewriteCond %{HTTP_HOST} ^(www\.)?main\.com(:[0-9]{1,5})?$
Jim