重定向URL(如果它包含关键字),获取访问过的URL,删除关键字并在前面添加一些内容


redirect URL if it contains keyword, take the visited URL, remove the keyword and add something to the front

如果标题有点混乱,我很抱歉,用例子解释更容易。我想接受这个URL和所有包含find-in-set-any 的URL

http://www.example.com/orange/find-in-set-any/most-popular-products/find-in-set-any?limitstart=0

并将其重定向到:

http://www.example.com/our-products/orange/most-popular-products?limitstart=0

所以我已经删除了find-in-set-any的所有实例,但在的末尾留下了任何?的内容

这也有点令人困惑,因为我们有语言子域,所以原始URL可能是

http://www.example.com/bg/orange/find-in-set-any/most-popular-products/find-in-set-any?limitstart=0

http://www.example.com/fr/orange/find-in-set-any/most-popular-products/find-in-set-any?limitstart=0

或58个不同语言子域中的任何一个。

我想保留现有的语言子域。

如果我说得不清楚,我很抱歉。任何帮助都将不胜感激。

关于已经尝试过的规则,我正在尝试这个atm,因为我想我会把它分成几个部分:

RewriteCond %{REQUEST_URI} find-in-set-any
RewriteRule ^/find-in-set-any(.*)$ /$1 [L,R=301]

但我一定完全错了,因为我不能让它产生任何效果。

编辑

所以我最新的是:

RewriteEngine On
RewriteCond %{REQUEST_URI} find-in-set-any
RewriteRule (.*)find-in-set-any(.*) $1 $2 [N]
RewriteRule (.*)find-in-set-any/ $1 $2 [N]
RewriteRule (/)find-in-set-any(/) $1 $2 [N]

我敢肯定这不是最有效的方法。我只需要在它之前添加我们的产品,这由于大约50个语言子域fr/ bg/ de/等的存在而变得复杂。还有2或3个4位数的子域,如zh-CNzh-TW

您可以尝试以下规则:

RewriteEngine On
RewriteCond %{REQUEST_URI} find-in-set-any
RewriteCond %{REQUEST_URI} ^(?:(/[^/]+))?/([^/]+)/find-in-set-any/([^/]+)/find-in-set-any [NC]
RewriteRule ^ http://%{HTTP_HOST}%1/our-products/%2/%3 [L,R=301,QSA]

这只会重定向此url:

http://www.example.com/fr/orange/find-in-set-any/most-popular-products/find-in-set-any?limitstart=0

http://example.com/fr/our-products/orange/most-popular-products?limitstart=0