【问题标题】:.htaccess redirect similar URLs (404).htaccess 重定向类似的 URL (404)
【发布时间】:2019-04-29 18:09:59
【问题描述】:

我尝试重定向多个具有相似结构的 Url。

网址 1:www.example.com/news-1

网址 2:www.example.com/news-2

重定向到:

www.example.com/news

我尝试了以下代码,但没有成功。

redirectMatch 301 ^/news-*$ https://www.example.com/news

如果我将它们中的每一个都重定向到同一页面,它就会起作用。 但是我有 200 多个新闻页面,所以我正在寻找一种解决方案来在 1 行中解决这个问题。

redirectMatch 301 ^/news-1$ https://www.example.com/news
redirectMatch 301 ^/news-2$ https://www.example.com/news

提前谢谢你!

编辑:

已解决:

redirectMatch 301 ^/news-(.*)$ https://www.example.com/news

【问题讨论】:

  • 但是这个/news-(.*)$也给出了同样的结果news-sadfasdfsdaf

标签: php .htaccess mod-rewrite


【解决方案1】:

据我了解,

redirectMatch 301 ^/news-(.*)$ https://www.example.com/news

上面的代码还将这个https://www.example.com/news-asdfasdfasdf重定向到https://www.example.com/news

如果你像这样使用#redirectMatch 301 ^/news-([0-9]+)$ https://www.example.com/news 只会将https://www.example.com/news-200 重定向到https://www.example.com/news

https://www.example.com/news-asdfasdfasdf 到 404 页面。

【讨论】:

    猜你喜欢
    • 2012-02-15
    • 2013-11-26
    • 1970-01-01
    • 2013-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-29
    • 2016-06-05
    相关资源
    最近更新 更多