문제

I apologise for the blatant ignorance of this question but I've been charged with fixing something in Django that I have NO experience with!

We're getting an issue with URLs and duplicated content.

If we visit "www.hello.com/services/" then we get our full page rendered, absolutely fine.

If we visit "www.hello.com/services" then we get the same content but with a default that seems to be set in a line:

class PageTitleNode(template.Node):?
 ?
    def render(self, context):?
        try:?
            meta_info = MetaInfo.objects.get(url=context['request'].path)?
        except ObjectDoesNotExist:?
            return u'This is our default page title'?
        return u"%s - hello.com" % meta_info.title

The main problem with this is that Google is indexing two almost identical pages and it's bad SEO according to our client's overpaid online strategy partner.

I know it's vague but if anyone can help then much rejoicing will be had.

Thanks for reading!

도움이 되었습니까?

해결책

I think your consultant is correct. One URL = one resource. Having two urls on one resource is quite dirty anyway. This is why Django features automatic redirect from non trailing slash to urls with trailing slashes. Under certain conditions.

I'm pretty sure your url definition regexp for /services/ lacks the trailing slash. Anyway, you should use trailing slashes only:

  1. Ensure APPEND_SLASH is set to True: from django.conf import settings; print settings.APPEND_SLASH

  2. Ensure that all your url regexps have the trailing slash, e.g. url(r'foo' ...) is bad, and url(r'foo/' ...) passes barely because of possible conflicts and url(r'foo/$' ...) is better

  3. Ensure all MetaInfo objects have url with trailing slash, e.g. MetaInfo.objects.exclude(url__endswith='/') should return MetaInfo without trailing slash in url

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top