My scenario is this:
For 20+ years I've used the following URL for search result on a old website:
https://www.example.com/cgi-bin/website.cgi?type=search_result&query=examplequery
https://www.example.com/cgi-bin/website.cgi?type=search_result&query=examplequery&page=72
I would like to start using a new, shorter url for search results, like this:
https://www.example.com/?q=examplequery
https://www.example.com/?q=examplequery&p=72
I would also like the old URLs to permanent redirect to the new URL, if possible.
This is what I have tried, after searching for a solution (this is in the location block in nginx.conf).
if ($args ~ "^/?q=val1&p=val2") {
rewrite ^ /cgi-bin/website.cgi?type=search_result&query=$arg_q&page=$arg_p? last;
}
if ($args ~ "^/?q=val1") {
rewrite ^ /cgi-bin/website.cgi?type=search_result&query=$arg_q? last;
}
For some reason, this is not working. I don't get any error.
In order to redirect old urls to the new format, I will use:
if ($args ~ "type=search_result&query=$val1&page=$val2") {
rewrite ^ /&q=$arg_query&p=$arg_page? permanent;
}
if ($args ~ "type=search_result&query=$val1") {
rewrite ^ /&q=$arg_query? permanent;
}
Not sure if this is working or not, since it depends on the above statements, I have not been able to test. But I don't get any errors.
I'm not sure that I'm doing wrong. If someone could have a look I would be very greatful.