Accidentally entering the wrong path on a website served from NGINX will not allow for automatic searching or parsing of keys derived from the URL path alias.

As some major hosting companies use NGINX servers, this could be an issue for anyone using Search 404 on those systems.

The problem arises from the following server request on line 26 of search404.module:

  if (empty($keys)) {
    $keys = \Drupal::request()->server->get('REDIRECT_URL');
  }

get('REDIRECT_URL') will only work on Apache web servers. More information here.

I attempted a patch myself, but have had no success with the new Drupal 8 path API. Perhaps someone smarter than me can take a look at this issue?

So far I have tried to make use of the following with no luck as they render the internal path rather than the user's input:

\Drupal::service('path.current')->getPath();
\Drupal::request()->getRequestUri();

Comments

rich_dawson created an issue. See original summary.

rich_dawson’s picture

Issue summary: View changes
heikki’s picture

This is not a correct solution, but I used this to pick keys from the url:

    $path = \Drupal::service('path.current')->getPath();
    $paths = explode('/', $path);
    $keys = end($paths);

This obviously only picks the last segment of the path, but it's enough for my use-case.

You could try this if you are using OR query in search api (or whatever search module you are using).

    $path = \Drupal::service('path.current')->getPath();
    $keys = str_replace('/', ' ', $path);
anish_zyxware’s picture

@heikki
Can you make it as a patch? I don't have an nginx instance right now to test it. So I was postponing it indefinitely.

magi.yv’s picture

Assigned: Unassigned » magi.yv
magi.yv’s picture

Assigned: magi.yv » Unassigned
Status: Needs work » Needs review
StatusFileSize
new696 bytes

@heikki
could you please review this patch.

AsadKamil’s picture

Status: Needs review » Reviewed & tested by the community

Patch applied successfully,
thanks.

magi.yv’s picture

Version: 8.x-1.0-alpha2 » 8.x-1.x-dev
Assigned: Unassigned » magi.yv
Status: Reviewed & tested by the community » Needs work
magi.yv’s picture

StatusFileSize
new765 bytes

Created a patch to fix the issue when using 'OR query' in search.

mslabba_zyxware’s picture

Status: Needs work » Fixed

Successfully merged the patch

mslabba_zyxware’s picture

Status: Fixed » Needs work

This patch will fix this particular issue, but has effect on other areas.
After applying this patch 'disable search' functionality does not works as expected

magi.yv’s picture

Assigned: magi.yv » Unassigned
Status: Needs work » Needs review
StatusFileSize
new825 bytes

Fixed issue on 'OR' query and disable search feature. Please review the patch.

magi.yv’s picture

StatusFileSize
new1.04 KB

mslabba_zyxware’s picture

Status: Needs review » Fixed

Successfully merged the patch

anish.a’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.