I am trying to do the following nginx redirect
/news/today-xx/index.php (xx will be moving with new page)
/blog/category-xx/today-xx/index.php
to
/article/today-xx/ (xx will be moving with new page)
/article/category-xx/today-xx/
but still want to access archival pages.
/news/index.php and /news/
/blog/index.php and /blog/
Here is what I have so far
location ^~ /(news|blog)/(.*) {
return 301 /article/$1;
}
This should do it:
I added the starting and ending anchors (
^
and$
), escaped the extension for php (\.
) and most importantly, changed the middle section to(.+)
, which captures one or more characters between the slashes to the variable. This means that the regex won't match to the old archive scripts.