Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Users can create redirects with internal paths that do not exist as the destination. This causes the redirect to go to a 404 page. The module should check internal paths and produce an error message when someone tries to save an internal path that does not exist.
If there is a good use case for allowing non-existent internal paths as a destination, this could be behind a settings option that determines whether or not internal paths are validated.
Comment | File | Size | Author |
---|---|---|---|
#18 | redirect-validate_internal_urls-2327247-18-D7.patch | 1.41 KB | Liam Morland |
| |||
#12 | redirect-validate_internal_urls-2327247-12-D7.patch | 1.41 KB | Liam Morland |
| |||
#10 | redirect-validate_internal_urls-2327247-10-D7.patch | 1.65 KB | kpaxman |
Comments
Comment #1
Liam MorlandIt should probably also check the destination URL prior to sending the redirect response.
Comment #2
lily.yan CreditAttribution: lily.yan commentedAdd a checkbox to allow users to select to validate internal URLs under Configuration » Search and metadata » URL redirects » settings. the checkbox is unchecked by default.
This patch (validate_internal_urls-2327247-2.patch) can validate internal URLs, so redirects cannot lead to 404 pages when the checkbox is checked.
Comment #3
kpaxman CreditAttribution: kpaxman commentedComment #4
lily.yan CreditAttribution: lily.yan commentedThe patch (validate_internal_urls-2327247-4.patch) includes new changes.
1. correct the spelling error on the error message.
2. using drupal_valid_path() instead of get_headers() adds a HTTP request.
Comment #5
ebremner CreditAttribution: ebremner commentedWhen having multilingual module on a site, the validate will fail when choosing all languages. In order to validate must renormalize redirect to node level. See patch (validate_internal_urls-2327247-5.patch) to see the extra normalize.
Comment #7
Liam MorlandLast patch was incremental patch. This is the entire patch.
Comment #9
Liam MorlandReroll.
Comment #10
kpaxman CreditAttribution: kpaxman commentedThe patch in #9 will say the redirect path is not valid if the destination is <front>. Attached is an updated version that bypasses validation for <front>.
Note that I had to use $element['#value'] instead of $value because <front> is not preserved in $value, despite seeming evidence to the contrary earlier in the function. I'll file an additional ticket about this seeming discrepancy.
Comment #11
Chris Matthews CreditAttribution: Chris Matthews commentedThe patch in #10 is 4 years old and no longer applies to the latest 7.x-1.x-dev may be too old to reroll, but I'll add the issue tag anyway.
Comment #12
Liam MorlandComment #13
alex_optimLooks good.
Comment #14
volegerI guess this error message should be more descriptive. Is not really clearly describe for the user why this URL is not valid.
Comment #15
Liam MorlandI think it is written that way to duplicate an error a few lines up.
Anyway, how about "The redirect path %value does not exist."?
Comment #16
voleger+1. I think this one is more correct. The message is related to existence check that trying to prevent causes of 404 error.
Comment #17
timwoodAny chance/interest in porting this to the D8 version? I didn't see a similar D8 issue in the issue queue.
Comment #18
Liam Morland#12 with message like in #15.