Opened 19 years ago
Closed 15 years ago
#3048 closed enhancement (wontfix)
sitemaps and prepend_www
| Reported by: | simonbun | Owned by: | Adrian Holovaty |
|---|---|---|---|
| Component: | Contrib apps | Version: | |
| Severity: | trivial | Keywords: | sitemaps |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
The sitemaps module reads the current_site.domain value to determine the <loc> node. This yields <loc>http://mydomain.mytld/mypath/</loc>. I use the PREPEND_WWW setting however, and google does not validate my sitemap because it expects the submitted URL's to contain the 'www' subdomain.
May i suggest the trivial enhancement to take the PREPEND_WWW setting into account and prepending the 'www' to the current_site.domain value when necessary?
I'm not fully up to speed on the django core to patch it myself.
Change History (7)
comment:1 by , 19 years ago
comment:3 by , 19 years ago
Indeed, that's my interim solution, but it breaks some functionalities of the sites contrib.
comment:4 by , 19 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
Which functionalities of the sites contrib does it break? The solution proposed by Esaj should work.
comment:5 by , 19 years ago
Well, for one the documentation says:
send_mail('Thanks for subscribing to %s alerts' % current_site.name,
'Thanks for your subscription. We appreciate it.\n\n-The %s team.' % current_site.name,
'editor@%s' % current_site.domain,
[user.email])
which would render 'editor@…'
Other than that, i'm using
if current_domain == 'foo.com'
throughout my projects.
Granted, its not hard to change that, and its just my personal problem.
Aside from this all though, a domain to me is still in 'domain.tld' form, not including the 'www' host. Unless you interpret domain as fully qualified domain.
comment:6 by , 15 years ago
| Resolution: | invalid |
|---|---|
| Status: | closed → reopened |
I have same issue now. I cannot use www in current_site.domain (I have used this variable in many places) and google webmaster tools reject all addr in sitemap because lack of 'www'.
Why we cannot have something like:
--- django_old/contrib/sitemaps/__init__.py 2008-11-19 08:44:26.000000000 +0300
+++ django_new/contrib/sitemaps/__init__.py 2010-11-24 18:57:34.000000000 +0300
@@ -1,4 +1,5 @@
from django.core import urlresolvers, paginator
+from django.conf import settings
import urllib
PING_URL = "http://www.google.com/webmasters/tools/ping"
@@ -29,7 +30,10 @@
from django.contrib.sites.models import Site
current_site = Site.objects.get_current()
- url = "http://%s%s" % (current_site.domain, sitemap_url)
+ domain = current_site.domain
+ if settings.PREPEND_WWW and not domain.startswith('www.'):
+ domain = 'www.' + domain
+ url = "http://%s%s" % (domain, sitemap_url)
params = urllib.urlencode({'sitemap':url})
urllib.urlopen("%s?%s" % (ping_url, params))
@@ -62,9 +66,12 @@
def get_urls(self, page=1):
from django.contrib.sites.models import Site
current_site = Site.objects.get_current()
+ domain = current_site.domain
+ if settings.PREPEND_WWW and not domain.startswith('www.'):
+ domain = 'www.' + domain
urls = []
for item in self.paginator.page(page).object_list:
- loc = "http://%s%s" % (current_site.domain, self.__get('location', item))
+ loc = "http://%s%s" % (domain, self.__get('location', item))
url_info = {
'location': loc,
'lastmod': self.__get('lastmod', item, None),
and
--- django_old/contrib/sitemaps/views.py 2008-11-19 08:44:26.000000000 +0300
+++ django_new/contrib/sitemaps/views.py 2010-11-24 18:57:58.000000000 +0300
@@ -4,6 +4,8 @@
from django.core import urlresolvers
from django.utils.encoding import smart_str
from django.core.paginator import EmptyPage, PageNotAnInteger
+from django.conf import settings
+
def index(request, sitemaps):
current_site = Site.objects.get_current()
@@ -15,10 +17,13 @@
else:
pages = site.paginator.num_pages
sitemap_url = urlresolvers.reverse('django.contrib.sitemaps.views.sitemap', kwargs={'section': section})
- sites.append('%s://%s%s' % (protocol, current_site.domain, sitemap_url))
+ domain = current_site.domain
+ if settings.PREPEND_WWW and not domain.startswith('www.'):
+ domain = 'www.' + domain
+ sites.append('%s://%s%s' % (protocol, domain, sitemap_url))
if pages > 1:
for page in range(2, pages+1):
- sites.append('%s://%s%s?p=%s' % (protocol, current_site.domain, sitemap_url, page))
+ sites.append('%s://%s%s?p=%s' % (protocol, domain, sitemap_url, page))
xml = loader.render_to_string('sitemap_index.xml', {'sitemaps': sites})
return HttpResponse(xml, mimetype='application/xml')
This fix works well for me, but it will be great to have this into official django repo.
comment:7 by , 15 years ago
| Resolution: | → wontfix |
|---|---|
| Status: | reopened → closed |
This has already been closed by a core dev. Please move discussion to the developers mailing list if you wish to argue why the functionality should now be added.
Surely you should set current_set.domain to use the 'www' prefix?