0

I am trying to redirect 301 pages. I came across one issue, in which I am stuck. 1st Page: https://test.example.com/the-magazine/2012-springsummer-issue/about-last-night-event-planning/

For above page i have written the redirect regex as:

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

$1 replaces all the text captured by (.*)

I have another page:

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

This page is also being redirect. How to write a regex to say if '/category/' exists donot redirect to Target URL: https://www.example.com/article/$1

Thank you in advance

Sujan Shrestha
  • 946
  • 1
  • 11
  • 27
  • 1
    Does this answer your question? [Reference - What does this regex mean?](https://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean) – Joundill Apr 19 '21 at 23:35

1 Answers1

1

Is this what you want?

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

  • make sure there is no \category with a negative lookbehind: (?<!\/category)
  • match literally: \/the-magazine\/2012-springsummer-issue\/
  • capture the rest of the url: ([A-Za-z].*)

Example 1:

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

Matches /the-magazine/2012-springsummer-issue/about-last-night-event-planning, captures about-last-night-event-planning.

Example 2:

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

Matches nothing, captures nothing

asdf101
  • 406
  • 2
  • 15