【问题标题】:Redirect 301 with regular expresions to other url with similar numeration使用正则表达式将 301 重定向到具有相似分子的另一个 url
【发布时间】:2021-04-06 12:25:45
【问题描述】:

我在网站上迁移了我的文章,并且 CMS 系统转换了网址。

我需要重定向类似以下的 URL:

示例,案例1。文章名称相同,网址末尾不同编号:

原网址:https://www.website.com/folder/2087-name-of-the-article

来源网址https://www.website.com/folder/name-of-the-article-r929/

示例,案例 2。 URL 末尾的文章名称和编号不同,但有其他子文件夹:

原始网址:https://www.website.com/folder/2087-name-of-the-article

来源网址https://www.website.com/folder0/folder/name-of-the-article-r929/

非常感谢,圣诞快乐。

【问题讨论】:

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


    【解决方案1】:

    您能否尝试使用所示示例进行以下、编写和测试。请确保在测试 URL 之前清除浏览器缓存。如果您想重定向(也可以在浏览器中更改 URL),请在两个规则中添加 R=301L 标志。

    RewriteEngine ON
    RewriteRule ^folder/name-of-the-article-r929/?$ folder/2087-name-of-the-article [L]
    RewriteRule ^folder0/folder/name-of-the-article-r929/?$ folder/2087-name-of-the-article [L]
    

    这认为你想将http://localhost:80/folder/name-of-the-article-r929/ 重写为http://localhost:80/folder/2087-name-of-the-article

    AND http://localhost:80/folder0/folder/name-of-the-article-r929/ TO http://localhost:80/folder/2087-name-of-the-article

    localhost 可能是您的域名。

    【讨论】:

      猜你喜欢
      • 2021-04-04
      • 1970-01-01
      • 2018-04-19
      • 1970-01-01
      • 1970-01-01
      • 2012-06-21
      • 2014-12-05
      • 2018-05-31
      相关资源
      最近更新 更多