HTaccess如何重定向多个URL?

时间:2013-10-02 15:34:52

标签: .htaccess

我想将多个网址重定向到同一网页。

我可以这样做:

Redirect /index.html http://example.com/newdirectory/
Redirect /index1.html http://example.com/newdirectory/
Redirect /index2.html http://example.com/newdirectory/
Redirect /index3.html http://example.com/newdirectory/
Redirect /index4.html http://example.com/newdirectory/
Redirect /index5.html http://example.com/newdirectory/

有没有更好的方法来做到这一点? (更干净)

1 个答案:

答案 0 :(得分:2)

是的,使用RedirectMatch您可以在模式中使用正则表达式:

RedirectMatch 302 ^/(index|index1|index2|index3|index4|index5)\.html$ http://example.com/newdirectory/

或者更简洁:

RedirectMatch 302 ^/index[1-5]?\.html$ http://example.com/newdirectory/