htaccess-重定向目录并从SEF url末尾删除匹配的字符串

问题描述 投票:0回答:1

我想使用.htaccess重定向目录结构,并从所有SEF URL的末尾删除此字符串“ -detail”。

例如:

https://www.example1.com/shop/items/product-catalog/category/concrete-tiles-detail

重定向到

https://www.example2.com/product-catalog/category/concrete-tiles

第一个规则有效,但是我没有找到在结尾处删除字符串的解决方案。我尝试了this答案,但在这种情况下不起作用。

RewriteEngine On
RewriteBase /
RewriteRule ^shop/items/product-catalog/(.*) https://www.example2.com/product-catalog/$1 [R=301,L]
RewriteRule ^(.*?)="\{\{-detail(.*)$ /$1$2 [R=301,L]
apache .htaccess redirect mod-rewrite
1个回答
0
投票

只需在模式中的分组匹配之后添加该部分(并在模式末尾锚定),就可以解决问题。

RewriteRule ^shop/items/product-catalog/(.*)-detail$ https://www.example2.com/product-catalog/$1 [R=301,L]

您尝试过的第二条规则可以完全删除。

© www.soinside.com 2019 - 2024. All rights reserved.