I am not sure why the WordPress people insist that,
GET /2005/05/29/foo-bar HTTP/1.1
is exactly the same as
GET /2005/05/29/foo-bar/ HTTP/1.1
If you have not spotted the difference, one has a trailing forward slash ‘/’ in the URI and one does not. For one is requesting the content of object ‘foo-bar’ under directory ‘/2005/05/29/’, and another one is requesting the content of the index file under directory ‘/2005/05/29/foo-bar/’. Although many of us would usually ignore the trailing slash, and write out the URL without it, web servers usually will correct this behaviour by replying a 301 permanent redirect to an URL with the trailing slash, if ‘foo-bar’ is indeed a directory.
However, not so with the default mod_rewrite rules generated by WordPress. To save number of rules need to be generated, WordPress short-cuts the regular expression to allow optional trailing slashes at the end of the URL. This results that you can now point to the same entry/archive with or without the trailing slash – which goes against what a search engine would recommend. Here is an extract of Google’s recommendation to the webmasters, under “Quality Guidelines – Specific recommendations”:
Don’t create multiple pages, subdomains, or domains with substantially duplicate content.
Now if I search Google for certain keywords, I sometimes see two results came back from the same domain – same blog entry but one with a trailing slash in its URL, and one does not. For example, mtsend. This is certainly not what I have desired. I used to modify all the mod_rewrite rules generated by WordPress, so that Apache will issue a 301 redirect if the trailing space is missing. However, it is tedious, and not compatible when WordPress upgrades. Moreover, your
.htaccess becomes huge and getting unmaintainable.
Therefore, this simple WordPress 1.5+ plugin is written. It compares the request URI, and if it does not match the permalink, a redirect will be sent back instead. It works not only for individual blog entries, but also yearly/monthly/daily and category archives, so that there is always only be one URL for each of your blog entries and archives.