Forum Moderators: phranque
I have a few sites we have are all under a single context root, so:
www.domain.com/root/site1
www.domain.com/root/site2
www.domain.com/root/site3
I want users to be able to hit www.domain.com/site1 and be forwarded. If this can be done without changing the URL in the browser then even better.
I've got as far as:
RewriteRule ^/(.*)$ /root/$1 [PT]
This redirects the first page fine, but if you hit any links in the web page they obviously still have the original context root, so this rule adds /root to it again, and the page cannot be found:
www.domain.com/root/site1/page1 becomes www.domain.com/root/root/site1/page1 and 404s.
I'm obviously missing something fundamental but mod-rewrite seems like a mine field.
Thanks!
That's because you used
.* which matches "everything". You need to make the pattern to be matched more exact and/or test
THE_REQUEST in a RewriteCond to make sure that the requested URL was as a result of a client request, not as a result of a previous rewrite, or you could test that the URL does NOT contain "root".