UPDATE 2023-03-27: This page is obsolete, as it refers to a prior version of this blog. However, it may be of historical interest.

I’ve previously blogged about my canonicaluri plugin that checks to see whether the requested URI is in the canonical form for the type of page being requested, and if necessary does a browser redirect to the canonical form of the URI. However the canonicaluri plugin may be overkill for some people, for example, it presumes use of the extensionless plugin, so that canonical URIs for individual entries do not have file extensions for the default flavour. A simpler alternative to the canonicaluri plugin is the slashredir plugin, which only enforces proper usage regarding trailing slashes.

In particular, the slashredir plugin enforces the following rules:

  • URIs for individual entry pages should not have a trailing slash.
  • URIs for all other pages (including the blog root, category index pages, and archive index pages) should have a trailing slash.

For example, if you request the URI

http://www.example.com/blog/foo

where “foo” is a category, this plugin will force a redirect to the canonical URI

http://www.example.com/blog/foo/

Similarly, if you request the URI

http://www.example.com/blog/foo.html/

where “foo.html” is an individual entry, this plugin will force a redirect to the canonical URI

http://www.example.com/blog/foo.html

Note that this plugin depends on having URI rewriting rules in place (e.g., in the Apache configuration file) to enforce the restriction that a URI should never have more than one trailing slash. The plugin as presently written can’t handle this case properly (even though the code attempts to do so) because it depends on the path_info() function to get the URI path, and the path_info() value has already been stripped of any excess trailing slashes that might have been present in the original URI.

See the plugin code itself for the full documentation. If you encounter problems with the plugin (or if you just use it and like it) please send me email.