【问题标题】:301 redirection regex301重定向正则表达式
【发布时间】:2021-04-19 12:48:02
【问题描述】:

我正在尝试重定向 301 页面。我遇到了一个问题,我陷入了困境。 第1页:https://test.example.com/the-magazine/2012-springsummer-issue/about-last-night-event-planning/

对于上面的页面,我将重定向正则表达式写为:

Source URL: /the-magazine/2012-springsummer-issue/([A-Za-z].*)
Target URL: https://www.example.com/article/$1

$1 替换 (.*) 捕获的所有文本

我还有一个页面:

2nd Page: https://test.example.com/category/the-magazine/2012-springsummer-issue

此页面也正在重定向。 如何编写一个正则表达式来说明“/category/”是否存在不要重定向到目标 URL:https://www.example.com/article/$1

提前谢谢你

【问题讨论】:

标签: regex wordpress url redirect


【解决方案1】:

这是你想要的吗?

表达式:(?<!\/category)\/the-magazine\/2012-springsummer-issue\/([A-Za-z].*)

  • 确保没有\category 带有负面的后视:(?<!\/category)
  • 字面匹配:\/the-magazine\/2012-springsummer-issue\/
  • 捕获url的其余部分:([A-Za-z].*)

示例 1:

https://test.example.com/the-magazine/2012-springsummer-issue/about-last-night-event-planning

匹配/the-magazine/2012-springsummer-issue/about-last-night-event-planning,捕获about-last-night-event-planning

示例 2:

https://test.example.com/category/the-magazine/2012-springsummer-issue/about-last-night-event-planning

什么都不匹配,什么都不捕获

【讨论】:

  • 是的。非常感谢。
猜你喜欢
  • 2018-04-19
  • 1970-01-01
  • 2018-05-31
  • 2020-10-14
  • 2012-06-21
  • 2017-06-21
  • 2014-12-05
  • 2015-08-29
相关资源
最近更新 更多