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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Liam Morland’s picture

It should probably also check the destination URL prior to sending the redirect response.

lily.yan’s picture

Add 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.

kpaxman’s picture

Status: Active » Needs review
lily.yan’s picture

The 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.

ebremner’s picture

When 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.

Status: Needs review » Needs work

The last submitted patch, 5: validate_internal_urls-2327247-5.patch, failed testing.

Liam Morland’s picture

Status: Needs work » Needs review
FileSize
1.58 KB

Last patch was incremental patch. This is the entire patch.

Status: Needs review » Needs work

The last submitted patch, 7: redirect-validate_internal_urls-2327247-7-D7.patch, failed testing.

Liam Morland’s picture

Status: Needs work » Needs review
FileSize
1.58 KB

Reroll.

kpaxman’s picture

The 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.

Chris Matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

The 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.

Checking patch redirect.admin.inc...
Hunk #1 succeeded at 492 (offset 27 lines).
Hunk #2 succeeded at 499 (offset 27 lines).
error: while searching for:
    '#description' => t('Only redirects managed by the redirect module itself will be deleted. Redirects managed by other modules will be left alone.'),
    '#disabled' => variable_get('redirect_page_cache', 0) && !variable_get('page_cache_invoke_hooks', TRUE),
  );

  $form['globals'] = array(
    '#type' => 'fieldset',

error: patch failed: redirect.admin.inc:636
error: redirect.admin.inc: patch does not apply
Liam Morland’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
1.41 KB
alex_optim’s picture

Looks good.

voleger’s picture

Status: Needs review » Needs work
+++ b/redirect.admin.inc
@@ -508,6 +507,13 @@ function redirect_element_validate_redirect($element, &$form_state) {
+      form_error($element, t('The redirect path %value is not valid.', array('%value' => $value)));

I guess this error message should be more descriptive. Is not really clearly describe for the user why this URL is not valid.

Liam Morland’s picture

I think it is written that way to duplicate an error a few lines up.

Anyway, how about "The redirect path %value does not exist."?

voleger’s picture

+1. I think this one is more correct. The message is related to existence check that trying to prevent causes of 404 error.

timwood’s picture

Any chance/interest in porting this to the D8 version? I didn't see a similar D8 issue in the issue queue.

Liam Morland’s picture

Status: Needs work » Needs review
FileSize
1.41 KB

#12 with message like in #15.