Commit 7159e216 authored by james_kerrigan's avatar james_kerrigan Committed by pifagor

Issue #2968055 by james_kerrigan, TwEeD, garyh, darrell_ulm, Chris Matthews,...

Issue #2968055 by james_kerrigan, TwEeD, garyh, darrell_ulm, Chris Matthews, cyberlily, aamortimer, pifagor, alex_optim, rpayanm: How to remove 301 redirected paths from sitemap?
parent 86000db0
......@@ -318,7 +318,15 @@ function xmlsitemap_settings_form($form, &$form_state) {
'#description' => t('When enabled, this will add all sitemaps to the robots.txt generated by <a href="@drupal-robotstxt">the RobotsTxt</a>.', array('@drupal-robotstxt' => 'https://www.drupal.org/project/robotstxt')),
'#default_value' => variable_get('xmlsitemap_robotstxt', 1),
);
// Allow to skip pages that might have 301 redirect set.
if (module_exists('redirect')) {
$form['xmlsitemap_redirect'] = array(
'#type' => 'checkbox',
'#title' => t('Skip pages that have 301 redirects set.'),
'#description' => t('Prevents pages which are 301 redirects to be saved in sitemap.'),
'#default_value' => variable_get('xmlsitemap_redirect', 0),
);
}
$form['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced settings'),
......
......@@ -207,6 +207,15 @@ function xmlsitemap_generate_chunk(stdClass $sitemap, XMLSitemapWriter $writer,
while ($link = $links->fetchAssoc()) {
$link['language'] = $link['language'] != LANGUAGE_NONE ? xmlsitemap_language_load($link['language']) : $url_options['language'];
$parsed_url = drupal_parse_url($link['loc']);
// Skip nodes which are 301 redirected.
if (variable_get('xmlsitemap_redirect')) {
$relative_redirect = redirect_fetch_rids_by_path($link['loc'], $link['language']->language, TRUE);
$alias_redirect = redirect_fetch_rids_by_path(ltrim(url($link['loc']), '/'), $link['language']->language, TRUE);
// If node contains a 301 redirect we skip it.
if (!empty($relative_redirect) || !empty($alias_redirect)) {
continue;
}
}
// Remove query or fragment.
$link['loc'] = $parsed_url['path'];
if ($url_options['alias']) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment