开发者

math with regexp in mod_rewrite

I'm trying to do the following:

I have the url: http://www.example.com/9999

and I want it to subtract 5000 from that number, and seamlessly redirect to: http://www.example.com/page.php?id=4999

Can regu开发者_Go百科lar expressions in mod_rewrite do maths?


No. There is no math in regexp.


There might not be math in regexp, but what I needed was perfectly doable:

Options +FollowSymLinks  
Options +Indexes  
RewriteEngine On
RewriteRule ^5([0-9][0-9][0-9])($) /offer_details.php?offers_id=$1$2 [R]
RewriteRule ^6([0-9][0-9][0-9])($) /offer_details.php?offers_id=1$1$2 [R]
RewriteRule ^7([0-9][0-9][0-9])($) /offer_details.php?offers_id=2$1$2 [R]
RewriteRule ^8([0-9][0-9][0-9])($) /offer_details.php?offers_id=3$1$2 [R]
RewriteRule ^9([0-9][0-9][0-9])($) /offer_details.php?offers_id=4$1$2 [R]

Out product IDs started from 5000, and we recently passed the 5000 mark (offer ID 10000+), so I'm gonna have to add, like, ten lines for 10000+, too. And by the time we reach offer id 20000 (>5 years) there would hopefully be technology to save me the writing of another 10 lines. Something along the lines of a nuclear apocalypse will do.


Make a conditional loop with the number of lines, and set the number of lines to increment up by one whenever the threshhold is reached for lines of 10, the 100th line would be generated when the 999th element appears.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜