views:

224

answers:

2

How can I redirect all requests going to web root to another folder (e.g. public/)?

I've already tried this (contents of .htaccess in web root):

RewriteEngine on
RewriteRule ^(.*)$ public/$1

But now I have duplicate content for addresses: address.tld/ and address.tld/public/

I would like to redirect address.tld/public/ to address.tld/, so there won't be any duplicates, but I just don't know how to do it and not get into redirecting cycle...

+1  A: 

With mod_rewrite you'll not get redirecting cycles.

Time Machine
I got into a cycle using 'Redirect permanent' request, sorry for misinformation.
tomp
A: 

Try these rules:

RewriteCond %{THE_REQUEST} ^GET\ /public/
RewriteRule ^public/(.*) /$1 [L,R=301]
RewriteRule !^public/ public%{REQUEST_URI} [L]
Gumbo
This works, thanks very much.
tomp