Hi, Unless I am not setting this up correctly, all anchors/fragements are being removed when a link is updated. Is there a way to maintain these anchors?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hass’s picture

Title: Anchors/Fragements not maintained » Anchors/Fragements not maintained after auto-correction
Version: 7.x-1.1 » 7.x-1.x-dev
Category: support » feature

Puhhh... that's in correct.

The module only takes the 301 redirect url and if this does not provide the anchors/fragments it get's removed. I'm not sure if it's correct to maintain the anchors/fragments if they are not in the 301. It may be useful if you change your site structure without changing your content. If we keep the anchors/fragments on automatic updates it will fail later as the anchors/fragments is now also verified since v1.1. This means we could add this as a new feature. Can you share a patch, please?

I'd like to hear some others if this is the way how it should work (design wise) as I'm not sure... what are web browsers doing here with the anchors/fragments?

plinto’s picture

I'm not sure I understand, so I will explain my situation.

I recently migrated to drupal, but all the links in the pages are the old urls, so basically almost every link on the website is a 301. I want to update all the links with the new drupal generated url. The problem is some links have anchors (and these achors do exist within the linked page) and they are being stripped.

You mention a patch, I would love to able to write one but don't know drupal well enough yet and don't have the skills

hass’s picture

Mainly I need to know what browsers are doing. Fragments a a bit special. If browser will not keep the fragment on redirects I may not implement it in linkchecker, too. Otherwise if they do, we should also keep the fragment in linkchecker, too.

plinto’s picture

I believe browsers maintain the fragment
Example: If you go to the courses tab on http://www.europe.umuc.edu/undergraduate/bachelors/accounting
All classes have a link with fragment, and all of the links are 301 redirects. If you click one the link is updated and the fragment is maintained

hass’s picture

Status: Active » Needs review
FileSize
1.36 KB

Patch attached (untested)

hass’s picture

And now without tabs.

hass’s picture

And now without tabs.

plinto’s picture

Thanks, I will test the patch right away

hass’s picture

hass’s picture

Any news on your test results?

joecorall’s picture

FileSize
843 bytes

I tested the latest patch, and fragments were not being appended to the end of the new URL.

The test was a drush script with the logic from that patch, with an example old URL and new URL:

#!/usr/bin/env drush
<?php
$old_link_fqdn = 'http://example.com/path#fragment';
$new_link_fqdn = 'http://example.com/new-path';

$old_link_fqdn_options = drupal_parse_url($old_link_fqdn);
$new_link_fqdn_options = drupal_parse_url($new_link_fqdn);
$new_link_fqdn_options['fragment'] = $old_link_fqdn_options['fragment'];
$new_link_fqdn_options['absolute'] = TRUE;
$new_link_fqdn = url($new_link_fqdn_options['path'], $new_link_fqdn_options);

drupal_set_message(print_r($old_link_fqdn_options,1));
drupal_set_message($new_link_fqdn);

And the output shows a failure to add the fragment to the end of the new URL:

Array
(
    [path] => http://example.com/path#fragment
    [query] => Array
        (
        )
    [fragment] =>
)

http://example.com/new-path

So I have attached my own patch which has been tested locally to have "#", and everything afterward, persist in the new URL. I'm submitting the patch to be reviewed by the community.

hass’s picture

Status: Needs review » Needs work