Django, APPEND_SLASH, and the 301 HTTP Status Code

This may be common knowledge for folks who are much more versed in Django than myself, but here’s a short post of something I ran into today with a web application of mine that’s using Django.

Checking my website out in Google’s Webmaster Tools I noticed that it’s report on my sitemap.xml file contained a “Redirect error” warning because some of the URLs contained in my sitemap returned a 301 HTTP status code. This “error” apparently caused the Google crawler not to crawl the links on the pages that returned a 301 response (I assumed this because in the Webmaster Tools my “Pages crawled per day” numbers were significantly lower). Obviously not good for SEO efforts.

Doing a little searching online, I found that in the default Django setup the APPEND_SLASH setting from the CommonMiddleware plugin will (as it’s name implies) append slashes to the end of requested URLs if it’s not present, however this functionality redirects the visitor to the URL containing the trailing slash and returning a 301 response. The URLs in my sitemap.xml file did not contain a trailing slash.

Wanting to keep the settings in the application as close to default as possible, I simply edited my sitemap.xml file making sure my URLs had trailing slashes and the Google crawler balked no longer.

This entry was posted in Uncategorized. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. Posted February 17, 2010 at 12:50 AM | Permalink

    Adam, thanks for this post. I have been trying to figure out why some URLs of my Django application were returning 301 redirects and never realized it was because of the missing trailing slash.

    All the best.

    Wayne

  2. Gabe
    Posted April 29, 2010 at 9:13 AM | Permalink

    I turned this option off, because it was redirecting to http instead of https when appending the slash resulting in a bad request.

    If you have any idea if there is a setting to make it redirect correctly, i would appreciate it.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>