Skip to content

Bug - Search - Redirect loop on non-multisite #785

Description

@amnesty-dev

Describe the bug
On a non-multisite install running a search causes an infinite redirect loop.

(This issue replaces #780 which misidentified the root cause for the loop.)

To Reproduce
Steps to reproduce the behavior:

  1. Run a search either with the standard /?s=foo or /search/foo
  2. See the browser failing due to an endless redirect loop.

Expected behaviour
see search results

Actual behaviour
endless redirect loop

Additional context

This check:

if ( set_url_scheme( $current, 'https' ) === set_url_scheme( $target, 'https' ) ) {

never succeeds due to the current_url helper function returning a wrong value for a search query. This happens because it behaves differently in a non-multisite setup.

The reason it actually does return the wrong value is due to amnesty_maybe_override_search_uri being hooked into home_url which changes any search query URL into the search page without the query.

The immediate fix for the endless loop here seems to be to drop the different behavior on non-multisite here:

if ( ! is_multisite() ) {
$home = home_url( $path, 'https' );
return empty( $query ) ? $home : add_query_arg( $query, $home );
}

But I'd also question what the hooking into home_url here does and if it really is needed since that also seems to be wrong.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status
To do

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions