[Plugin: XML Sitemap & Google News Sitemap Feeds] Trailing slash with permalink-structure /%post
-
Hi RavanH,
Thanks for the multi-site network functionality of your plugin. – It will help to realize the vision of a multi-lingual installation of our current information portal. ??
As WordPress can sometimes be very greedy on URL-handling, I ran into the following issue comprising the combination your sitemaps(-news).xml redirect and the /%postname%/ permalink structure. FYI: The sitemap serves just fine, but https://mydomain.com/sitemap.xml gets redirected to https://mydomain.com/sitemap.xml/ Please note the trailing slash which some spiders would probably mis-interpret.
After a bit of research I implemented the following code which seems to solve the problem:
In the constructor of XMLSitemapFeed.class.php I’ve added
// REMOVE TRAILING SLASH add_action('pre_get_posts', array(__CLASS__, 'remove_redirect_canonical') );
And the following function tells WordPress to remove the built-in canonical redirect if we’re handling a sitemap-feed.
//remove trailing slash function remove_redirect_canonical() { global $wp_query; if (is_feed() && in_array($wp_query->get('feed'), array('sitemap', 'sitemap-news'))) remove_action('template_redirect', 'redirect_canonical'); }
Hope this will help others, too.
A feature suggestion: What do you think about an exclude-filter for your query_posts calls? – That way we could easily leave out a list of posts/pages and Google wouldn’t return an error in the Webmaster-Tools because a sitemap-item is blocked for example by robots.txt.
Greetz,
Berny
- The topic ‘[Plugin: XML Sitemap & Google News Sitemap Feeds] Trailing slash with permalink-structure /%post’ is closed to new replies.