2009-12-11 73 views
2

會有更簡單的方法來做到這一點與正則表達式?Mod_rewrite規則匹配網址中的促銷代碼

RewriteRule ^2090024$ https://www.wsjwine.com/discovery_offer.aspx?promo=2090024 [L] 
RewriteRule ^2090025$ https://www.wsjwine.com/discovery_offer.aspx?promo=2090025 [L] 
RewriteRule ^2090013$ https://www.wsjwine.com/discovery_offer.aspx?promo=2090013 [L] 

RewriteRule ^2078027$ https://www.wsjwine.com/discovery_offer.aspx?promo=2078027 [L] 
RewriteRule ^2078028$ https://www.wsjwine.com/discovery_offer.aspx?promo=2078028 [L] 
RewriteRule ^2078029$ https://www.wsjwine.com/discovery_offer.aspx?promo=2078029 [L] 
RewriteRule ^2078030$ https://www.wsjwine.com/discovery_offer.aspx?promo=2078030 [L] 

我覺得有,但不知道mod_rewrite不夠好。

回答

1

取決於您想要接受的數字格式。如果它足夠正好趕上任何7位號碼:

RewriteRule ^([0-9]{7})$ https://www.wsjwine.com/discovery_offer.aspx?promo=$1 [L] 

如果它可以是任何位數(不只是7):

RewriteRule ^([0-9]+)$ https://www.wsjwine.com/discovery_offer.aspx?promo=$1 [L]