【问题标题】:How to rewrite part of a url using apache rewrite rule?如何使用 apache 重写规则重写部分 url?
【发布时间】:2013-06-09 01:21:25
【问题描述】:

www.example.com

该网站的类别如下:

爬行动物、蔬菜、国家

每个类别中的页面,网址如下:

www.example.com/reptiles/iguana.html www.example.com/reptiles/black_mamba.html

现在假设我想更改“爬行动物”类别,将其重命名为“蜥蜴”。

所以我需要一个重写规则和/或 301 重定向,以确保访问旧 URL 的任何人最终都会到达新 URL。

我是否需要为每个页面(iguana.html、black_mamba.html 等)制定规则,或者是否可以通过某种方式指定任何带有“reptiles”的 url 应该将该部分更改为“lizards” ?

谢谢。

【问题讨论】:

    标签: apache mod-rewrite url-rewriting apache2


    【解决方案1】:

    试试这个:

    RewriteRule ^reptiles\/(.*) lizards/$1 [L,R=301]
    

    【讨论】:

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