diff --git a/xmlsitemap.generate.inc b/xmlsitemap.generate.inc
index b7cf4ed..662fda8 100644
--- a/xmlsitemap.generate.inc
+++ b/xmlsitemap.generate.inc
@@ -192,8 +192,9 @@ function xmlsitemap_generate_chunk(stdClass $sitemap, XMLSitemapWriter $writer,
       'xmlsitemap_link' => $link,
       'xmlsitemap_sitemap' => $sitemap,
     );
+    $link_parts = parse_url($link['loc']);
     // @todo Add a separate hook_xmlsitemap_link_url_alter() here?
-    $link_url = url($link['loc'], $link_options + $url_options);
+    $link_url = url($link_parts['path'], $link_options + $url_options) . (isset($link_parts['query']) ? '?' . $link_parts['query'] : '');

     // Skip this link if it was a duplicate of the last one.
     // @todo Figure out a way to do this before generation so we can report