Directory redirect with htaccess and duplicated content


I got a problem with my subdirectory redirecting. I’ve got this project structure:

  • public_html
    • public
      • landing-page
      • nuxt_app
      • app
      • .htaccess

In this structure I have app which is located in public_html/public/app and url to it is like this: and I have landing-page dir which url is I’ve used httpd configuration to move root directory from public_html to public_html/public and htaccess file to move everything from landing-page to root dir

My main problem is with .htaccess file which partialy works it shows content from landing-page in root directory but also shows content in url: and generates duplicate content


RewriteEngine on
RewriteCond %{REQUEST_URI}  !^/landing-page
RewriteRule ^(.*)$ /landing-page/$1 [NC,L]

Using redirect like this:

Redirect /landing-page/

causes infinite loop

>Solution :

Assuming DocumentRoot has been set to public_html/public, you can try this .htaccess inside public/ directory:

RewriteEngine on

# external redirect to remove landing-page from external URLs
RewriteRule ^landing-page/(.*) /$1 [R=301,NC,L,NE]

# internal rewrite to add landing-page silently
RewriteRule !^landing-page/ landing-page%{REQUEST_URI} [NC,L]

Leave a ReplyCancel reply