301 htaccess重定向目录通配符

时间:2014-11-13 21:31:58

标签: regex .htaccess mod-rewrite redirect http-status-code-301

有没有更有效的方法来编写这些重定向?

RewriteRule ^directory/subdir/1990/010190/(.*)$ directory/editorials/$1 [L,R=301]
RewriteRule ^directory/subdir/1990/020190/(.*)$ directory/editorials/$1 [L,R=301]
RewriteRule ^directory/subdir/1990/030190/(.*)$ directory/editorials/$1 [L,R=301]
RewriteRule ^directory/subdir/1990/040190/(.*)$ directory/editorials/$1 [L,R=301]
RewriteRule ^directory/subdir/1990/050190/(.*)$ directory/editorials/$1 [L,R=301]
RewriteRule ^directory/subdir/1990/060190/(.*)$ directory/editorials/$1 [L,R=301]

似乎我需要一个通配符用于/1990/

的子目录

能够做到这一点会大大减少重定向的次数,使其更易于管理。任何帮助或提示赞赏!

1 个答案:

答案 0 :(得分:2)

您可以对所有这些规则使用单一规则:

RewriteRule ^directory/subdir/1990/0[1-6]0190/(.*)$ directory/editorials/$1 [L,R=301]