Imagine a WordPress installation with two versions, in one of them, the URLs start with example.com/shop and the other example.com/nl/shop
Using the following htaccess file, I constantly need to uncomment two lines and comment out two others to switch between two versions of the site.
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /shop/
RewriteBase /nl/shop/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule . /shop/index.php [L]
RewriteRule . /nl/shop/index.php [L]
</IfModule>
As a potential fix, I used the following htaccess file which take advantages of an environment variable named BASE:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::2$
RewriteRule ^(.*)$ - [E=BASE:%1]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . %{ENV:BASE}/index.php [L]
</IfModule>
It works for both versions, however now I can’t access the admin area which
has the ~/shop/wp-admin/ or ~/nl/shop/wp-admin/ in its URI, because of too many redirect error.
What should I change to fix that issue?
2
Answers
Thanks to the given solution in here, I made a small change to my RewriteRule directive and now the redirect error is gone for good.
Try with this code –