diff --git a/xmlsitemap.generate.inc b/xmlsitemap.generate.inc
index 747347a..87c969d 100644
--- a/xmlsitemap.generate.inc
+++ b/xmlsitemap.generate.inc
@@ -173,9 +173,20 @@ function xmlsitemap_generate_chunk(stdClass $sitemap, XMLSitemapWriter $writer,
       'xmlsitemap_link' => $link,
       'xmlsitemap_sitemap' => $sitemap,
     );
+
+    // Extract query parameters so that they do not get encoded twiche by url().
+    if (strpos($link['loc'], '?')) {
+      list($link['loc'], $loc_query) = explode('?', $link['loc']);
+    }
+
     // @todo Add a separate hook_xmlsitemap_link_url_alter() here?
     $link_url = url($link['loc'], $link_options + $url_options);
 
+    // Readd query parameters.
+    if (isset($loc_query)) {
+      $link_url .= '?' . $loc_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
     // back to the user about this.
