Forum Moderators: phranque

Message Too Old, No Replies

redirecting the root folder

         

theresandy

12:05 am on Jul 27, 2005 (gmt 0)

10+ Year Member



Hi,
I know this is probably the most simple rewrite rule ever, but for some reason I can't seem to figure it out.

I have:

http://www.example.com
and
http://www.example.com/test/

When the user goes to www.example.com, he should see the content of www.example.com/test/, same for www.example.com/test.html, going to www.example.com/test/test.html, and so on (everything should be redirected, images, html files, php files, etc)

So basicly I wan't to redirect the root folder to a folder inside it.
Here's what I tried:

RewriteEngine on
RewriteRule ^(.+)$ test/$1

but it's crashing everything, and it's quite obvious why, but how to fix it?

Thanks in advance

jdMorgan

12:18 am on Jul 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's crashing because it rewrites forever -- there's nothing to stop it.

You are not going to be able to come up with a "universal" solution to this, so I suggest naming your new top-level directory something unique, such as "~test" -- with the "~" being the usual character used for various purposes similar to this.

Then you'd have:


RewriteEngine on
RewriteCond %{REQUEST_URI} !^/~test/
RewriteRule ^(.*)$ /~test/$1 [L]

and that won't loop, because the RewriteCond will stop it.

Jim

theresandy

4:00 am on Jul 27, 2005 (gmt 0)

10+ Year Member



Jim,
for some weird reason, my apache won't recognize folders like "~something", it gives me a 404 (but a folder named "~" only would work).

Anyway, I went ahead and removed the "~" from your rule and it worked great, no more unlimited redirects.

Thanks a lot by the help!

gark

12:39 pm on Aug 4, 2005 (gmt 0)



Thank you jdMorgan. I wasted the entire morning trying to find this solution myself or somewhere else on the web. Luckily I finally came here. ;-)

I was pretty close already but always tried to use %{REQUEST_FILENAME} instead of %{REQUEST_URI} to avoid the infinite loop.