【问题标题】:htaccess - redirect directory and remove matching string form end of SEF urlhtaccess - 重定向目录并从 SEF url 末尾删除匹配字符串
【发布时间】:2020-10-04 13:17:38
【问题描述】:

我想使用 .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

路径的“类别”部分是动态的。甚至可以由几个目录组成,例如

https://www.example1.com/shop/items/product-catalog/category1-2-or-3/sub-category/concrete-tiles-detail 

第一个规则有效,但我没有找到删除末尾字符串的解决方案。我尝试了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】:

    只需在模式中的分组匹配之后添加该部分(并在最后锚定模式)就可以了。

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

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-13
    • 1970-01-01
    • 1970-01-01
    • 2014-08-07
    • 2015-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多