Wordpress 在.htaccess中使用环境变量来处理两个RewriteBase语句
假设WordPress安装有两个版本,其中一个版本的URL以example.com/shop开头,另一个版本的URL以example.com/nl/shop开头 使用下面的htaccess文件,我经常需要取消注释两行并注释掉另外两行,以便在站点的两个版本之间切换Wordpress 在.htaccess中使用环境变量来处理两个RewriteBase语句,wordpress,apache,.htaccess,Wordpress,Apache,.htaccess,假设WordPress安装有两个版本,其中一个版本的URL以example.com/shop开头,另一个版本的URL以example.com/nl/shop开头 使用下面的htaccess文件,我经常需要取消注释两行并注释掉另外两行,以便在站点的两个版本之间切换 <IfModule mod_rewrite.c> RewriteEngine On #RewriteBase /shop/ RewriteBase /nl/shop/ RewriteRule ^index\
<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>
重新启动发动机
#基地/商店/
新基地/荷兰/商店/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
#重写规则/shop/index.php[L]
重写规则/nl/shop/index.php[L]
作为一种潜在的修复方法,我使用了以下htaccess文件,它利用了名为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>
重新启动发动机
RewriteCond%{REQUEST_URI}:$1^(.*?/)(.*):\2$
重写规则^(.*)-[E=基:%1]
重写cond%{REQUEST_FILENAME}-F
重写规则%{ENV:BASE}/index.php[L]
它适用于两个版本,但是现在我无法访问
由于重定向错误太多,URI中有~/shop/wp admin/或~/nl/shop/wp admin/
我应该改变什么来解决这个问题?多亏了中给出的解决方案,我对我的RewriteRule指令做了一个小的更改,现在重定向错误就永远消失了
<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>
重新启动发动机
RewriteCond%{REQUEST_URI}:$1^(.*?/)(.*):\2$
重写规则^(.*)-[E=基:%1]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^%{ENV:BASE}/index.php[QSA,L]
尝试使用此代码-
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]
谢谢,但您的解决方案不适用于example.com/shop/something或example.com/nl/shop/something