Home > other >  Directory redirect with htaccess and duplicated content
Directory redirect with htaccess and duplicated content

Time:08-17

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: www.example.com/app and I have landing-page dir which url is www.example.com. 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: www.example.com/landing-page and generates duplicate content

.htaccess

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

Using redirect like this:

Redirect /landing-page/ https://example.com/

causes infinite loop

CodePudding user response:

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
RewriteCond %{ENV:REDIRECT_STATUS} ^$
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]
  • Related