301将不在我的htaccess中的每个URL重定向到特定的URL

时间:2014-01-31 10:13:06

标签: .htaccess mod-rewrite redirect

我正在将旧域(jeans-vintage.com)重定向到新域(destock-vintage.com)。这是我的.htaccess的片段:

RewriteRule ^/$ http://www.destock-vintage.com/ [R=301,NE,NC,L]
RewriteRule ^/jeans-vintage$ http://www.destock-vintage.com/ [R=301,NE,NC,L]

# HOMMES

RewriteRule ^70-polos$ http://www.destock-vintage.com/24-polos-vintage? [R=301,NE,NC,L]
RewriteRule ^68-hommes$ http://www.destock-vintage.com/7-vetements-vintage-homme? [R=301,NE,NC,L]
RewriteRule ^69-tous-les-$ http://www.destock-vintage.com/7-vetements-vintage-homme? [R=301,NE,NC,L]
RewriteRule ^71-t$ http://www.destock-vintage.com/23-t-shirts-vintage? [R=301,NE,NC,L]
RewriteRule ^72-c$ http://www.destock-vintage.com/25-chemises-vintage? [R=301,NE,NC,L]
RewriteRule ^73-pulls$ http://www.destock-vintage.com/22-pulls-vintage? [R=301,NE,NC,L]
RewriteRule ^74-bermudas-et-shorts$ http://www.destock-vintage.com/55-shorts-bermudas-vintage? [R=301,NE,NC,L]
RewriteRule ^75-pantalo$ http://www.destock-vintage.com/26-pantalons-vintage? [R=301,NE,NC,L]
RewriteRule ^76-jeans$ http://www.destock-vintage.com/9-jeans-vintage? [R=301,NE,NC,L]
...

我想要实现的是将此htaccess中未特别提及的每个URL重定向到新域根目录destock-vintage.com。

例如,当我去jeans-vintage.com/70-polos时,它很适合去destock-vintage.com/24-polos-vintage。

但是,如果我转到此网址http://www.jeans-vintage.com/panier?add&id_product=3460&token=43e9dbbf254328614bc7b9512e3948e6,它会保留在jeans-vintage.com上,并且不会重定向到去库存...

我希望你明白:)

提前致谢!

2 个答案:

答案 0 :(得分:1)

最终使用 CATCH ALL规则制定这样的规则。只有当URI与任何最高规则都不匹配时,才会触发该结束规则。

# HOMMES

RewriteRule ^70-polos$ http://www.destock-vintage.com/24-polos-vintage? [R=301,NE,NC,L]
RewriteRule ^68-hommes$ http://www.destock-vintage.com/7-vetements-vintage-homme? [R=301,NE,NC,L]
RewriteRule ^69-tous-les-$ http://www.destock-vintage.com/7-vetements-vintage-homme? [R=301,NE,NC,L]
RewriteRule ^71-t$ http://www.destock-vintage.com/23-t-shirts-vintage? [R=301,NE,NC,L]
RewriteRule ^72-c$ http://www.destock-vintage.com/25-chemises-vintage? [R=301,NE,NC,L]
RewriteRule ^73-pulls$ http://www.destock-vintage.com/22-pulls-vintage? [R=301,NE,NC,L]
RewriteRule ^74-bermudas-et-shorts$ http://www.destock-vintage.com/55-shorts-bermudas-vintage? [R=301,NE,NC,L]
RewriteRule ^75-pantalo$ http://www.destock-vintage.com/26-pantalons-vintage? [R=301,NE,NC,L]
RewriteRule ^76-jeans$ http://www.destock-vintage.com/9-jeans-vintage? [R=301,NE,NC,L]

# CATCH ALL rule
RewriteRule ^ http://www.destock-vintage.com/ [R=301,L]

答案 1 :(得分:1)

如果我理解正确,您只需要在现有规则的最后添加最后一条规则来捕获所有URI:

RewriteRule ^ http://www.destock-vintage.com/ [R = 301,NE,NC,L]

这不会与其他规则竞争,因为每个其他规则都有“LAST”选项[L](因此,如果在“全部捕获”规则之前任何规则匹配,则之后不会执行任何规则)。

此致