#22231 closed New feature (wontfix)

Subdomain support in Sitemaps

Reported by: anilashanbhag@… Owned by: nobody
Component: contrib.sitemaps Version: master
Severity: Normal Keywords:
Cc: pirosb3 Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no


Google currently supports adding subdomain urls to sitemaps.
For example example.com/sitemap.xml can contains links to sub1.example.com and sub2.example.com.

Reference: https://productforums.google.com/forum/?hl=en#!msg/webmasters/w4gMRNFHMlA/24pUYqi69mkJ

The current django sitemaps framework cannot handle without having to override the get_urls function. One possible easy fix which I am using currently is:

for item in self.paginator.page(page).object_list:
    loc = self.__get('location', item)
    if not '://' in loc:
        loc = "%s://%s%s" % (protocol, domain, loc)

instead of

for item in self.paginator.page(page).object_list:
    loc = "%s://%s%s" % (protocol, domain, self.__get('location', item))

This basically checks if the past returned by location is an absolute path. If yes, it does not append the root domain to it.

Change History (3)

comment:1 Changed 19 months ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

If this fix sounds good, I can probably submit a pull request for the same.

comment:2 Changed 19 months ago by pirosb3

  • Cc pirosb3 added

Is anyone doing this? if not I will prepare a patch.

comment:3 Changed 19 months ago by aaugustin

  • Resolution set to wontfix
  • Status changed from new to closed

This isn't an API, it's a hack.

Generally speaking, I'm not convinced that django.contrib.sitemaps should attempt to do this. Django has a fairly strong assumption that a single instance serves a single domain. The current excepted way to serve multiple domains is with multiple instances and django.contrib.sites.

Note: See TracTickets for help on using tickets.
Back to Top