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

LVL 13
themrrobertAsked:
Who is Participating?
 
themrrobertAuthor Commented:
Now I added

RewriteCond %{REQUEST_URI} =/
RewriteRule ^.*$ /index.phtml [L]
0
 
themrrobertAuthor Commented:
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

0
 
Bernard S.CTOCommented:
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]
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.