Server: Nginx
Application: PHP
URL in question is
/p/all_articles/user/ABC
/p/all_articles/user/ABC/page/123
which is
/index.php?p=all_articles&user=ABC
/index.php?p=all_articles&user=ABC&page=123
ABC = this could be a-zA-Z0-9 as it's username
123 = this could be page numbers 0-9
Tried many combinations and options, the following got me much closer to expected result, but it is not perfect.
location /p/all_articles {
rewrite ^/p/all_articles/user/(.*)?$ /index.php?p=all_articles&user=$1 last;
rewrite ^/p/all_articles/user/(.*)/page(?:/([0-9]+))?$ /index.php?p=all_articles&user=$1&page=$2 last;
try_files $uri $uri/ /index.php;
}
the above rewrite location block results only when one of them is quoted other one would work, but not together.
Similarly
/search/QUERY
/search/QUERY/page/123
which is
/index.php?search=QUERY
/index.php?search=QUERY&page=123
QUERY = anything a-zA-Z0-9 and space
123 = this could be page numbers 0-9
like the one for all_articles, the closest I was able to get is
location /search {
rewrite ^/search /index.php?search last;
rewrite ^/search/(.*)/page(?:/([0-9]+))?$ /index.php?search=$1&page=$2 last;
try_files $uri $uri/ /index.php;
}
But, this works to get either one of the clean URL when the other rewrite is quoted, but not together.
I appreciate if anyone give any answers to solve this issue.