Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I need to add urls with query string to sitemap, for example "node?page=2" via API.
I setup $xmllink array with 'loc'='node?page=2', but via this way in XML I see "node%3Fpage%3D2" instead of normal url.
How I can correctly save the query string into xml sitemap item?
Comment | File | Size | Author |
---|---|---|---|
#20 | xmlsitemap-query-and-fragment-1918478-20.patch | 1.2 KB | pifagor |
|
Comments
Comment #1
MurzHow to reproduce:
And after this we will see in sitemap.xml:
Comment #2
MurzI have solve this problem for me via this patch for function xmlsitemap_generate_chunk(stdClass $sitemap, XMLSitemapWriter $writer, $chunk) {
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #4
mh86 CreditAttribution: mh86 commentedEncountered the same issue (query parameter was encoded by url() and thus did not work any more).
Made a patch out of #2. Maybe there is a nicer way to do that.
Comment #5
mh86 CreditAttribution: mh86 commentedUpdated my patch. The $loc_query variable needs to be re-initialized on every iteration.
Comment #6
Anonymous (not verified) CreditAttribution: Anonymous commentedYou misspelled the word "twice" in your comments as "twiche".
Comment #7
mh86 CreditAttribution: mh86 commented+ "Readd". Two typos in two comments ;-)
Thanks for that note. The patch needs an update.
Comment #8
Ari Linn CreditAttribution: Ari Linn commentedI've run into the same problem, so thanks for telling me where to look for the issue. However, I suggest using parse_url() to determine whether a url has a query part.
Comment #9
Murz@Ari Linn, thanks for the hint, your version is more simple and works well. Here is updated patch with your version of solution. Please re-test it and commit to head.
Comment #10
wojtha CreditAttribution: wojtha commentedComment #11
ivan.lewas CreditAttribution: ivan.lewas as a volunteer commentedWhat about hash attributes? So a link like this: node/50/#comment10 can be rendered correctly.
Comment #12
ULikeApples CreditAttribution: ULikeApples commentedUpdate patch for version "7.x-2.2"
Comment #14
firewaller CreditAttribution: firewaller commentedUpdate patch for version 7.x-2.3. Also leverages url() query and fragment keys with drupal_parse_url() rather than appending to string.
Comment #15
artem_sylchuk@firewaller thanks for a patch, it helped me a lot.
Unfortunately you've created a p0 patch and it should be p1, see: https://www.drupal.org/node/707484
Attached the updated patch version.
Comment #16
pifagorComment #18
pifagorComment #19
alex_optimLooks good
Comment #20
pifagorPatch Failed to Apply, I recreate patch
Comment #22
pifagor