Search code examples
performancehttp-redirect

Directory slash redirects? Does this still happen?


I was reading an article referenced by Jeff Atwood about Yahoo's "Best Practices" for speeding up a website, and I noticed this little gem:

One of the most wasteful redirects happens frequently and web developers are generally not aware of it. It occurs when a trailing slash (/) is missing from a URL that should otherwise have one. For example, going to http://astrology.yahoo.com/astrology results in a 301 response containing a redirect to http://astrology.yahoo.com/astrology/ (notice the added trailing slash). This is fixed in Apache by using Alias or mod_rewrite, or the DirectorySlash directive if you're using Apache handlers.

Does this still happen? The article is pretty old, as the web goes. I think I've been doing this for years. I don't think I've noticed this happening lately, but then again I've never really looked. Is this an Apache thing? Does IIS 7 do this?

I'm scared. Hold me.


Solution

  • Try it!

    Here are some truncated requests run from the terminal.

    curl -I  http://astrology.yahoo.com/astrology
    
    HTTP/1.0 301 Moved Permanently
    Date: Tue, 21 Jun 2011 13:24:24 GMT
    Location: http://shine.yahoo.com/astrology/
    
    
    curl -I http://wordpress.org/extend
    
    HTTP/1.0 301 Moved Permanently
    Server: nginx
    Date: Tue, 21 Jun 2011 13:26:17 GMT
    Location: http://wordpress.org/extend/
    

    Though it seems that IIS does it the other way:

    curl -I http://www.iis.net/overview
    
    HTTP/1.0 200 OK
    Server: Microsoft-IIS/7.0
    
    curl -I http://www.iis.net/overview/
    
    HTTP/1.0 301 Moved Permanently
    Location: http://www.iis.net/overview
    

    Guess it depends how you have it configured, but it's definitely something to optimise.