regex - mod_rewrite 可以做数学吗?

标签 regex apache mod-rewrite

我打算将我的网站转换为新的 CMS,但我想使用 mod_rewrite 将旧链接无缝重定向到新位置。

问题是我的新博客的文章编号与旧的不同,因为我将首先导入一些较旧的博客条目。因此,我的 mod_rewrite 需要采用类似 old.php?article=125 的 URL。 , 进行加法运算以找出新的文章编号(例如 +200,在本例中),然后重定向到 new.php?i=325 .

mod_rewrite 可以自己添加,还是我需要某种“帮助”脚本来做到这一点?

最佳答案

mod rewrite 可以做正则表达式。如果您可以将新文章的值定义为相同的 id 加上 1000,那么您可以这样做:

rewriteRule /article=(\d{1})$ /new.php?i=100$1
rewriteRule /article=(\d{2})$ /new.php?i=10$1
rewriteRule /article=(\d{3})$ /new.php?i=1$1

关于regex - mod_rewrite 可以做数学吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3063548/

相关文章:

javascript - 正则表达式在 JavaScript 字符串中返回未定义

java - 从 Apache exec commons 获取并解析输出流

apache - 配置为使用HBase运行Hadoop

.htaccess - 如何进行 .htaccess 重写以屏蔽转发的 URL?

php - 我应该在现有规则中添加什么 RewriteRule 来解决这个问题?

javascript - 将函数调用与 JS Regex 匹配

javascript - 针对 RegExp 的 Google Closure 编译器警告

php - url 中的 htaccess rewriterule 2 参数

regex - 字符串中字符位置的转义字符 : R lang

java - 自动完成功能在 Apache ISIS Action 中不起作用