Currently we have an htaccess setup using the below settings;
RewriteCond %{HTTP_HOST} !^(staged|foobar)\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !/(Press_Kits|logos|admin|console|shop)/ [NC]
RewriteRule ^(.*)$ https://www.example.com/shop/$1 [L,R=302]
The goal of it is to have most to all traffic to direct to https://example.com/shop/
, but to allow access to the subdirectories like https://example.com/logos/
, etc. This all works well for the most part. The issue lies where we are now trying to duplicate the shop for a staging environment and set that to https://staged.example.com
which going to that domain will work with the above htaccess settings as well, however getting to the backend of the shop using the subdirectory location of https://staged.example.com/admin
redirects to the main dir's shop.
So https://staged.example.com
works, but https://staged.example.com/admin
doesn't work, and redirects to https://example.com/shop/admin
.. I've gone into the database to redirect all the SQL settings for the shop to be pointing to the staged subdomain, so I'm at a loss as to what causes the redirect back to the main store.
The subdomain doesn't have any redirects in place to retain everything within the subdomain, so would that be something I have to add on the subdomains side? Is there another/change I need to make on the current conditions to allow not only for the subdomain but also the subdomains subdirectories?
Any ideas? Thanks!
https://example.com/shop/
" - Note that the rule you posted redirects to www - please clarify. And your condition specifically checks for a trailing slash (which is not present on your example URL/admin
- so the condition would be satisfied). Is/admin
a physical directory? Do you have any other.htaccess
files in subdirectories? Do you have access to the server config? Check the HTTP response headers of the undesirable redirect and post the results here - this might have some clues. Do you have other directives in this.htaccess
file?https://example.com/shop/
as well (this has been a working thing so we may have added the www just recently during all the testing). /admin isn't an actual physical directory, it's just what the backend url is set as (so it could be changed to anything and no need to create a physical directory for it). I'll see if I can get the server config details on the unwanted redirect and come back here. As for other directives, its a lengthy htaccess used from a Magento webstore, however for redirect purposes, that is all we gothttps://staged.example.com/admin
, I received the following:xx.xxx.xxx.54 staged.example.com - [18/Oct/2021:19:09:35 +0000] "GET /admin HTTP/2.0" 302 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36" | TLSv1.3 | 2.775 2.785 2.787 MISS 0 NC:000000 UP:SKIP_CACHE_SET_COOKIE
--- Does that give any hints or is there more data we need to look at?https://example.com/shop/
" - My point was that if the directive stateswww
and you are seeing a redirect to the domain apex then obviously something else is performing the redirect. "/admin
isn't an actual physical directory" - that's fine, but it means that mod_dir won't append the trailing slash and that condition will always be successful (since it is expecting a trailing slash).