Please consider the following URLs.
- https://products.example.com/family/child
- https://products.example.com/products/family/child
- https://products.example.com/family/children
- https://products.example.com/products/family/children
Among the four, I need to redirect one as follow: https://products.example.com/family/children
Which means that I want to redirect the URLs that do not contain the word /products/
and /children
. If the URL does not contain the word /products/
but contain /child
at the end, I need to replace the /child
with /children
.
UPDATE 1: I have 2 problems as below.
- Identify the URL that are to be substituted.
- Modify the identified URL as required.
I can identify the URL with this regex but not able to substitute.
Update 2: I think I found a way to identify: ^(?!.*\/products(?:\/))(?:(.*)\/|$)?(?:child)$
and substitute: $1/children
Next problem is: the regex works with option /m
only. Can this be modified to work without it as:
rewrite ^(?!.*\/products(?:\/))(?:(.*)\/|$)?(?:child)$ $1/children permanent;