301重定向以特定关键字开头的网址

时间:2018-06-06 04:12:35

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

我需要使用RedirectMatch重定向所有使用特定单词的网址。

我们说我需要重定向任何以关键字" pdf"开头的网址。应该重定向到基本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/

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:1)

仅匹配起始字符使用' ^' (脱字符号)

RedirectMatch 301 ^/pdf(.*) http://www.example.com/
相关问题