Redirect to subfolder. Disallow direct subfolder access

codplay

Registered
Jul 24, 2017
1
0
1
united states
cPanel Access Level
Website Owner
Folder structure

-public_html

-magsandbox
-app
- pub
- ....

-magstage
-app
- pub
- ....

-magquality
-app
- pub
- ....
In public_html/.htaccess, I have following rule

RewriteCond %{HTTP_HOST} ^domain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteCond %{REQUEST_URI} !magstage/
RewriteRule (.*) /magstage/$1 [L]
This has been working perfectly so far. domain.com redirect to domain.com/magstage behind the scenes and my site is accessible.

But from SEO perspective I have a duplication issue.

domain.com and domain.com/magstage are both accessible for crawling and both are the one and same magento installation.

How can I allow the redirect to subfolder but at the same block the subfolder access?

I tried various combination adding htaccess in root as well as in subfolder. either the site goes down OR goes in a loop with both redirecting to each other.