Permalink to search.php failing to redirect to /search

AI-generated summary

A permalink issue is reported by smaffulli where requests to /search.php result in a blank page with a 406 error instead of redirecting to /search. xrav3nz explains this is due to the existing /search route in Discourse, which hits the SearchController and mistakes the .php part as the desired response format. A suggested solution is to handle the redirect in NGINX using a rewrite rule, such as:

location = /search.php {
  return 301 /search?$args;
}

This would redirect requests to /search.php to /search before they reach Discourse.

I noticed today that the permalink from search.php to External URL /search is not working properly. I get displayed a blank page, no html at all.

nginx throws a 406 error

[31/Oct/2017:17:35:42 +0000] "discussion.dreamhost.com" $IP.IP.IP.IP "GET /search.php HTTP/2.0" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:56.0) Gecko/20100101 Firefox/56.0" "-" 406 211 "-" 0.379 0.379 "-"

the error on rails log shows that the permalink is somewhat processed by SearchController: is that correct? Any suggestion on how to properly redirect requests from /search.php to /search?

Started GET "/search.php" for $IP.IP.IP.IP at 2017-10-31 17:20:17 +0000
Processing by SearchController#show as 
Completed 406 Not Acceptable in 321ms (ActiveRecord: 43.6ms)

I’m afraid so, since there is already a Discourse(Rails) route named /search: it hits the SearchController before it can be processed by the PermalinkController.

The .php part is considered (mistaken) as the desired response format, thus the 406.

There could be better solutions, but I think you’ll have to handle the redirect on NGINX, before it gets to Discourse:

Maybe something along the lines of: (not tested)

location = /search.php {
  return 301 /search?$args;
}