the Future of the Web
  • Home
  • Hire Us
  • Articles
  • About
  • Contact
  • Helping visitors with .htaccess

    May 21 2007

    When I changed all my URLs, I put in place something to email me whenever there was a 404 (page not found). This way, if I screwed up something with my forwarding, I'd know.

    It turned out that people were getting 404s mostly for one of two mistakes. Either there was spaces in the URL (an error of copying and pasting perhaps?), or there was a trailing period at the end of the URL (probably from it being part of a sentence, and the period becoming part of the URL when auto-linked).

    The two broken URLs look like this:

    http://www.thefutureoftheweb.com/blog/helping-visitors-with-htac cess
    
    http://www.thefutureoftheweb.com/blog/helping-visitors-with-htaccess.
    

    I thought I'd make things easier for people by auto-correcting these two mistakes. I added a few lines to my .htaccess file like so:

    RewriteEngine on
    
    # remove spaces in URL as a favour to visitors
    RewriteCond %{REQUEST_URI} .+\s+.+
    RewriteRule ^(.+)\s+(.+)$ /$1$2 [L,R=301]
    
    # remove trailing periods on URL as a favour to visitors
    RewriteCond %{REQUEST_URI} \.+$
    RewriteRule ^(.*)\.+$ /$1 [L,R=301]
    

    Unlike my major changes the other day, I'm not obliged to maintain these rewrites forever — after all, they are still mistakes in the URL, and I'm not giving out URLs with spaces and dots in them on purpose. However, I'd rather bring people to the correct page if I can.

    Tags: server htaccess usability 404
    View 1 Comment | Add a comment
  • Comments

    1. Harmen Janssen at 2:08pm on May 21, 2007

    That's a nice solution!
    It adds to the usability of your website, imho.

    Bookmarked :)

    Add a Comment

    Note: HTML tags and entities will be converted so that they are displayed as you type them. This means if you type in <em>, people will see <em>, and if you type &lt;em&gt;, people will see &lt;em&gt;.

  • Request a Quote

  • Jesse Skinner

    Jesse Skinner
    • Hire Me
    • About Me
    • Email Me
    • RSS Feed RSS Icon
  • Recent Articles

    • Parse Accept-Language to detect a user's language
    • Twitter
    • Three years of The Future of the Web
    • Saving data to a file with PHP
    • Easy web scraping with PHP
    • See all the articles
    • IBM: Where and when to use Ajax
    • Code Igniter 1.6.0 Released
    • Update a Dev Site Automatically with Subversion
    • JavaScript Functions are Variables
    • See All...
  • Categories

    • javascript (37)
    • links (19)
    • about (18)
    • web (14)
    • server (10)
    • html (10)
    • css (8)
    • carnival (7)
    • browsers (7)
    • design (4)
    • seo (4)
    • ads (4)
    • standards (4)
    • events (4)
    • work (4)
  • Older Articles

    • May 2008
    • April 2008
    • February 2008
    • January 2008
    • December 2007
    • November 2007
    • September 2007
    • August 2007
    • July 2007
    • June 2007
    • May 2007
    • April 2007
    • March 2007
    • February 2007
    • January 2007
    • December 2006
    • November 2006
    • October 2006
    • September 2006
    • August 2006
    • July 2006
    • June 2006
    • May 2006
    • April 2006
    • March 2006
    • February 2006
    • January 2006
    • December 2005
    • November 2005
    • October 2005
    • September 2005
    • August 2005
    • April 2005
    • See All...
Copyright © 2008 Jesse Skinner | CSS | XHTML | RSS | Help | Impressum | Cutie Quilts | Internet Blog Top Sites