skip to Main Content

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


  1. Chosen as BEST ANSWER

    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.

    <IfModule mod_rewrite.c>
      RewriteEngine On
    
      RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::2$
      RewriteRule ^(.*)$ - [E=BASE:%1]
    
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^ %{ENV:BASE}/index.php [QSA,L]
    </IfModule>
    

  2. Try with this code –

    RewriteEngine on 
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^mysite1/(.*)$ mysite1/index.php?url=$1 [L,QSA] 
    RewriteRule ^mysite2/(.*)$ mysite2/index.php?url=$1 [L,QSA] 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search