.HTACCESS – 删除部分url

我在我的cms中使用了一个预定义的htaccess,如下所示:

RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?%{QUERY_STRING} [L] 

我想更新url,以删除2“子目录”:

from /en/top/solutions/?id=1/solutions/?id=1
from /en/top/about/?othervar=1/about/?othervar=1

这是我迄今为止所做的一件事情:

 RewriteRule ^en/top/ /$1 [L,R=301] 

我无法得到它的工作。 谢谢

$1意味着“使用原始url的第一个捕获部分”。 为了捕获原始URL的一部分,您需要使用括号来捕获它。像这样:

 RewriteRule ^/en/top/(.*) /$1 [QSA] 

这意味着“以/en/top/开始的任何东西,然后捕获后面的内容并将其放入variables$ 1。重写为$ 1variables并附加原始查询string。