将多个URL(URL中包含的数字)重定向到同一个新URL

时间:2016-06-20 04:10:36

标签: .htaccess redirect mod-rewrite

我有3个网址,如:

http://example.com/archives/2001_2005/
http://example.com/archives/2006/
http://example.com/archives/2007/

如何使用.htaccess 301将所有这些重定向到:

http://example.com/archives/2001-2007/

我在下面尝试了这个但是它没有用(我更喜欢简单的一行而不是):

RewriteRule ^archives/(2001_2005|2006|2007) http://example.com/archives/2001-2007/ [R=301,L]

1 个答案:

答案 0 :(得分:1)

您可以使用RedirectMatch:

RedirectMatch 301 ^/archives/(2001_2005|2006|2007) http://example.com/archives/2001-2007

在测试之前清除浏览器缓存。