Problem/Motivation
When an external redirect is created using the Redirect module on certain Drupal sites installed in a 4-character subdirectory path (for example, /arts, /math, /hire, /news, and /open), the redirect is saved successfully but fails when accessed.
For example, on a site with the base URL: https://example.ca/arts
a redirect is created with:
Path: /test-redirect
Destination: https://abc.com/subpathThe redirect is created without errors. However, when a user visits: https://example.ca/arts/test-redirect
Drupal throws the following exception instead of redirecting to the external URL:
InvalidArgumentException: The URI '://example.ca/arts' is invalid.
You must use a valid URI scheme.
Drupal\Core\Url::fromUri()Steps to reproduce
Step 1: Use a Drupal site installed in a subdirectory, for example: https://example.ca/arts
Step 2: Enable the Redirect module, and navigate to admin/config/search/redirect
Step 3: Create a redirect with the following values:
Path: /test-redirect
Destination: https://abc.com/subpathStep 4: Save the redirect and visit: https://example.ca/arts/test-redirect
Expected result: The user is redirected to: https://abc.com/subpath
Actual result: Drupal throws an exception:
InvalidArgumentException: The URI '://example.ca/arts' is invalid.
You must use a valid URI scheme.
Drupal\Core\Url::fromUri()Proposed resolution
Skip redirect-chain processing for external redirect destinations in RedirectRepository::findByRedirect(). External URLs should not be treated as local paths. Returning early for external URLs prevents the URI scheme from being removed and resolves the exception.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 3633941-external-redirects-fail.patch | 728 bytes | lily.yan |
Comments
Comment #2
lily.yan commentedComment #3
lily.yan commentedI created a patch based on 8.x-1.11 that fixes this issue. I tested it in my local environment and verified that external redirects work correctly after applying the patch.
Attached patch: 3633941-external-redirects-fail.patch