Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

.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

>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
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]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading