In the nginx config file for my server, I have written the following location block:
location ~ /page/(?!(3/?|5/?|6/?|8/?)) {
return 301 https://anothersite.com/page$is_args$args;
}
With this, I'm trying to redirect all /page/ EXCEPT the following:
/page/3
/page/3/
/page/5
/page/5/
/page/6
/page/6/
/page/8
/page/8/
Which works well for those pages. However, this also excludes any pages that START with the pattern. So pages like the following
/page/33
/page/814
/page/577
do not get redirected, but they should be. How should I change that regex so that I can limit the match only to the first character after /page/ (with or without a trailing slash)?
I've also tried this:
location ~ "/page/(?!([3]{1}/?|[5]{1}/?|[6]{1}/?|[8]{1}/?))" {
return 301 https://anothersite.com/page$is_args$args;
}
However this seems to behave exactly like the first pattern.
Any help is much appreciated! Thanks in advance!