Is there a way I can replace non alphanumeric characters returned with $request_uri
with a space (or a +
)?
What I'm trying to do is redirect all 404's in one of my sites to it's search engine, where the query is the uri
requested. So, I have a block in my nginx.conf containing:
error_page 404 = @notfound;
location @notfound {
return 301 $scheme://$host/?s=$request_uri;
}
While this does indeed work, the url's it's returning are the actual uri
's complete with -_/
characters causing the search to always return 0 results
For instance... give this url: https://example.com/my-articles
, the redirect ends up as this: https://example.com/?s=/my-articles
What I would like is to end up (ultimately) like this: https://example.com/?s=my+articles
(tho, the + at the beginning works fine too... https://example.com/?s=+my+articles
I will need to do this without LUA or Perl modules. So, how can I accomplish this?