Link to home
Start Free TrialLog in
Avatar of themrrobert
themrrobertFlag for United States of America

asked on

Apache Rewrite: How to redirect without infinite loop.

I'm using this code and trying to make / route to /site/

/index.phtml -> /site/index.phtml

This code makes an infinite loop of site/site/site/site/site/site/...
RewriteEngine On
RewriteRule ^(.*)$ /site/$ [R,L]

Open in new window

Avatar of themrrobert
themrrobert
Flag of United States of America image

ASKER

Figured out solution on my own. I had to create an index.php file in the site root and have it point to /index.phtml (to make the rule take effect)

Here is my .htaccess:


If anyone can also make it route / to /site/ that would get the points now.

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /site/$1 [L]

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of themrrobert
themrrobert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bernard Savonet
Nice trick
Note that for some servers you might need the rewrite rule to rewrite to a full http address

RewriteRule ^(.*)$ http://mydomain.com/site/$1 [L]
...
RewriteRule ^.*$ http://mydomain.com/site/index.phtml [L]