Tom Pažourek
Tom Pažourek

Reputation: 10167

Redirect website root to subdirectory

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...

Upvotes: 2

Views: 724

Answers (2)

Gumbo
Gumbo

Reputation: 655129

Try these rules:

RewriteCond %{THE_REQUEST} ^GET\ /public/
RewriteRule ^public/(.*) /$1 [L,R=301]
RewriteRule !^public/ public%{REQUEST_URI} [L]

Upvotes: 2

user142019
user142019

Reputation:

With mod_rewrite you'll not get redirecting cycles.

Upvotes: 1

Related Questions