【问题标题】:URL 301 redirect via .htaccess file in phpURL 301 通过 php 中的 .htaccess 文件重定向
【发布时间】:2015-07-07 08:56:06
【问题描述】:
www.example.com/products/223/category/sub_category/product_name.html

RewriteRule ^products/([^/]+)/([^.]+)\.html$ /$2/p$1 [L,NC,R=301]

上面的重定向规则将我重定向到下面的 URL。

www.example.com/category/sub_category/product_name/p223

我想更新它以便重定向 来自

www.example.com/products/223/category/sub_category/product_name.html

www.example.com/product-name/p223

我想显示产品名称(“_”应替换“-”)和带有前缀“P”的产品 ID。

【问题讨论】:

    标签: php apache .htaccess redirect


    【解决方案1】:

    试试这个:

    RewriteEngine On
    RewriteRule ^/?product/([^/]+)/([^/]+)/([^/]+)/([^_]+)_([^.]+)\.html$ http://example.com/$4-$5/p$1 [NC,R=301,L]
    

    这会重定向:

     www.example.com/products/223/category/sub_category/product_name.html
    

     www.example.com/product-name/p223
    

    【讨论】:

    • 感谢您的回复,我忘了提及,但类别和子类别在 url 中也是动态的。
    • 感谢您的回复。重写规则 ^products/(\d+)/(.*)/(.*)/([^_]+)_([^.]+).html$ /$4-$5/p$1 [L,NC,R =301] 这对我有用。
    【解决方案2】:

    以下重定向对我有用。

    RewriteRule ^products/(\d+)/(.*)/(.*)/([^_]+)_([^.]+).html$ /$4-$5/p$1 [L,NC,R=301]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-12
      • 2021-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多