Skip to content

URL Rewrites that begin with letters "pub" fail to rewrite/redirect #39755

Open
@sean-cognella

Description

@sean-cognella

Preconditions and environment

  • version 2.4.7-p4
  • normal deployment which uses /pub/ directory for all the static content with latest .htaccess in both the root dir and /pub/ dir

Steps to reproduce

To reproduce:

  • Navigate to admin
  • Marketing -> SEO & Search -> URL Rewrites

Add URL Rewrite with:

  • Custom a Request Path value that begins with three letters: pub (e.g. public-facing-url-that-breaks-sad-cry, publishing-is-so-wonderful.html)
  • Target Path that points at a product detail page
  • Redirect Type: No

Expected result

https://exampleurl.com/public-facing-url-that-breaks-sad-cry loads the product defined by Target Path

Actual result

https://exampleurl.com/public-facing-url-that-breaks-sad-cry does not the product defined by Target Path and fails with a 404 error page

Additional information

knowing how there are both apache .htaccess rewrites plus magento rewrites, it can get a bit messy to figure out where the issue is happening. we were able to trace the problem back to some very old laminas code in: vendor/laminas/laminas-http/src/PhpEnvironment/Request.php

This is the fix we implemented to get things working as one possible option though it does mean we will now have to re-apply the patch after each deployment to ensure it doesn't revert, so perhaps there is a better way you all can come up with to solve for this issue.

         // Directory portion of base path matches.
         $baseDir = str_replace('\\', '/', dirname($baseUrl));
-        if (0 === strpos($requestUri, $baseDir)) {
-            return $baseDir;
+       if (0 === strpos($requestUri, $baseDir)) {
+            // BEGIN CUSTOM
+            // Skip only if baseDir is exactly "pub" or "/pub"
+            if (!in_array($baseDir, ['pub', '/pub'], true)) {
+               return $baseDir;
+            }
+            // END CUSTOM
         }

Maybe there's a more robust or alternative option to fix this more elegantly. Thanks!

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
    Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
    Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
    Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
    Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Activity

m2-assistant

m2-assistant commented on Mar 21, 2025

@m2-assistant

Hi @sean-cognella. Thank you for your report.
To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce.


Join Magento Community Engineering Slack and ask your questions in #github channel.
⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
🕙 You can find the schedule on the Magento Community Calendar page.
📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

added
Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it
on Mar 22, 2025
engcom-Bravo

engcom-Bravo commented on Mar 24, 2025

@engcom-Bravo
Contributor

Hi @sean-cognella,

Thanks for your reporting and collaboration.

We have tried to reproduce the issue i9n latest 2.4-develop instance and we are able to reproduce the issue.Kindly refer the screenshots.

Image

fails with a 404 error page.

Hence Confirming the issue.

Thanks.

added
Issue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmed
Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branch
Priority: P2A defect with this priority could have functionality issues which are not to expectations.
Reported on 2.4.xIndicates original Magento version for the Issue report.
on Mar 24, 2025
github-jira-sync-bot

github-jira-sync-bot commented on Mar 24, 2025

@github-jira-sync-bot

✅ Jira issue https://jira.corp.adobe.com/browse/AC-14296 is successfully created for this GitHub issue.

m2-assistant

m2-assistant commented on Mar 24, 2025

@m2-assistant

✅ Confirmed by @engcom-Bravo. Thank you for verifying the issue.
Issue Available: @engcom-Bravo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

ajay2108

ajay2108 commented on Mar 25, 2025

@ajay2108

@sean-cognella @engcom-Bravo - I tried replicating this issue but found it was working fine on version 2.4.7p4. Please let me know if I have missed something.

Image
Image

sean-cognella

sean-cognella commented on Mar 31, 2025

@sean-cognella
Author

@ajay2108 perhaps you can clarify your stack details in case you are running a different stack? might be worth confirming if your .htaccess configs match m2.4.7-p4 exactly or if you've older values in place? do you have any other custom rewrite logic in apache or .htaccess or elsewhere that might be altering behavior? is your content hosted in magento-root/pub/ or configured in a way different from the latest defaults?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: SEOComponent: UrlRewriteIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Reported on 2.4.xIndicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @sean-cognella@engcom-Bravo@engcom-November@github-jira-sync-bot@ajay2108

        Issue actions

          URL Rewrites that begin with letters "pub" fail to rewrite/redirect · Issue #39755 · magento/magento2