【问题标题】:301 Redirect URLs starting with a specific keyword以特定关键字开头的 301 重定向 URL
【发布时间】:2018-11-15 15:39:53
【问题描述】:

我需要使用 RedirectMatch 重定向所有以特定单词开头的 URL。

假设我需要重定向任何以关键字“pdf”开头的 URL,都应该重定向到基本 URL。

要求:

http://www.example.com/pdf         -> http://www.example.com/
http://www.example.com/pdf-444-abc -> http://www.example.com/
http://www.example.com/blog/pdf-abc-1234          -> must not redirect
http://www.example.com/images/web/pdf/1234568.jpg -> must not redirect

我使用了以下 301 重定向规则,它重定向了所有上述示例。

RedirectMatch 301 /pdf(.*)$ http://www.example.com/

我怎样才能做到这一点?

【问题讨论】:

    标签: .htaccess url url-rewriting url-redirection


    【解决方案1】:

    如果只匹配起始字符,请使用“^”(插入符号)

    RedirectMatch 301 ^/pdf(.*) http://www.example.com/
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-29
      • 2015-12-30
      • 1970-01-01
      相关资源
      最近更新 更多