问题描述
我正在尝试执行以下操作:
I'm trying to do the following:
我有网址: http://www.example.com/9999
我希望它从该数字中减去5000,然后无缝重定向到: http://www.example.com/page.php?id=4999
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
mod_rewrite中的正则表达式可以进行数学运算吗?
Can regular expressions in mod_rewrite do maths?
推荐答案
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产品ID从5000开始,最近我们通过了5000标记(Offer ID 10000+),所以我也必须为10000+添加10行.到我们达成ID为20000(> 5年)的报价时,希望有技术可以节省我另外10行的写作时间.像核末日一样可以做到的.
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.
这篇关于在mod_rewrite中使用regexp进行数学运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!