【问题标题】:.htaccess unnecessary Pinterest arrays redirection to actual URL.htaccess 将不必要的 Pinterest 数组重定向到实际 URL
【发布时间】:2021-07-12 13:23:08
【问题描述】:

如何重定向此模式

example.com/fruits/7285/good-slug","id":"33b4","favicon_link":"https:/i.pinimg.com/fa/9.png

到这里:

example.com/fruits/7285/good-slug

试过了:

RewriteEngine on 
RewriteRule ^(fruits/\d+/[\w-]+). /$1 [R=301,L,NC,NE]

但它重定向太多。

Pinterest 通过在我的 URL 后添加一些数组来引用此类 URL(abc.com/fruits/123/slug),我不知道如何,所以我需要重定向到我的实际地址。

【问题讨论】:

    标签: regex .htaccess redirect mod-rewrite url-rewriting


    【解决方案1】:

    您可以将此重定向规则与possessive quantifier 一起使用:

    RewriteRule ^(fruits/\d+/[\w-]++). /$1 [R=301,L,NC,NE]
    

    [\w-]++ 匹配与单词或连字符匹配的最长可能字符串,没有任何回溯。

    另一方面,^(fruits/\d+/[\w-]+). 将导致重定向循环,因为正则表达式引擎回溯以允许匹配 [\w-]+ 模式之后的单个字符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-26
      • 1970-01-01
      • 1970-01-01
      • 2020-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多