用于重定向公共URL的正则表达式

时间:2017-06-15 14:07:46

标签: regex wordpress url-redirection

我们如何将这两个重定向URL合并(一般化)为一个。

例如:
URL1:(?i)/MathBlog/10-common-math-errors-made-by-elementary-students/ => /mathblog/common-math-errors-made-by-elementary-students/

网址2:(?i)/MathBlog/amp/10-common-math-errors-made-by-elementary-students/ => /mathblog/amp/common-math-errors-made-by-elementary-students/

应该成为 URL3:(?i)/MathBlog/{regex}/10-common-math-errors-made-by-elementary-students/ => /mathblog/{/amp}/common-math-errors-made-by-elementary-students/

{/amp}必须是可选的,即使/amp可用,然后附加到重定向网址或忽略它。

1 个答案:

答案 0 :(得分:0)

这个怎么样:

(?i)(\/MathBlog(?:\/amp)?\/)10-(common-math-errors-made-by-elementary-students\/) => $1$2

Live demo