Skip to content

UrlRewrite removes query string from url, if url has trailing slash #18717

Closed
@sergeynezbritskiy

Description

@sergeynezbritskiy

Preconditions (*)

When customer opens url with trailing slash and query string like http://magento-host.com/some-url-key/?foo=bar, Magento redirects to url without trailing slash and truncates query string, so customer is redirected to http://magento-host.com/some-url-key.

  1. Magento version 2.2.5 or 2.2.6
  2. No customizations for the store, Luma + Sample Data

Steps to reproduce (*)

  1. Open any product or category page.
  2. Manually add /?foo=bar&bar=baz to the url and open this link

Expected result (*)

  1. After the page has been loaded, query string remain in url

Actual result (*)

  1. Query string is removed from url

Additional information

  1. The issue is not reproduced when we avoid using url rewrites, e.g. http://magento-host.com/catalog/product/view/id/{product-id}/?foo=bar&bar=baz, and actually there is no redirect in this case.
  2. The issue seems to be happen in \Magento\UrlRewrite\Model\Storage\DbStorage::doFindOneByData
$data[UrlRewrite::REQUEST_PATH] = [
    rtrim($requestPath, '/'),
    rtrim($requestPath, '/') . '/',
];

We are looking for both urls (with trailing slash and without it), but when verifying the result from database we do not check it.

// If request path matches the DB value or it's redirect - we can return result from DB
$canReturnResultFromDb = ($resultFromDb[UrlRewrite::REQUEST_PATH] === $requestPath || in_array((int)$resultFromDb[UrlRewrite::REDIRECT_TYPE], $redirectTypes, true));

Metadata

Metadata

Labels

Component: UrlRewriteEvent: mm19inFixed in 2.4.xThe issue has been fixed in 2.4-develop branchIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions