Site icon Hip-Hop Website Design and Development

How to make WordPress search page use a relative path

I am working with a WP blog hosted on a subdomain (eg. wp.foo.com). The primary domain (eg. foo.com) is a non-WP platform running a main app/service. For blog content, however, the main platform uses a reverse proxy to display the WP blog page and articles but with the primary domain showing (eg. foo.com/blog/ rather than wp.foo.com/blog/). That part is all well and good thanks to the Make Paths Relative plugin.

Except for searching the blog… the one path it does not make relative is for search result pages. For example, when users search the blog from foo.com/blog/ using the WordPress search widget, the search result page displays the undesired URL format wp.foo.com/?s=cheese instead of the desired foo.com/?s=cheese format. Is there a filter and function to use that will allow me to use a relative path /?s=cheese thus allowing the reverse proxy to do what we want it to do?

So far I tried fiddling with a solution involving the template_redirect hook via theme functions.php but have not had any luck yet.

I also changed the search <form> template to action="/" and that did not work either. Any help is greatly appreciated. Thanks in advance!