define('DISALLOW_FILE_EDIT', true); Case Insensitive Permalinks Plugin for WordPress – unFocus Projects – Kevin Newman and Ken Newman

Case Insensitive Permalinks Plugin for WordPress

For a while I have been creating and sending links to History Keeper to When I moved that page into WordPress the URL became lower case, and case sensitive. This can be a problem for those used to Windows and IIS non-case sensitive URLs. To get around the problem, I added a hack to my 404.php error handler (more on that later) that would detect capitals in the permalink URL, convert it to lowercase, and then forward the user to the new page with a php Location header (http redirect). That seemed like a clunky solution, so I made a WordPress plugin that does pretty much the exact same thing, only it’s in a plugin! So that makes it less clunky. Well whatever.

Here’s the code:
[cc lang=’php’ ]
< ?php /* Plugin Name: unFocus.Insensitivity Plugin URI: Description: A plugin to make permalinks case insensitive. Version: 1.0a Author: Kevin Newman Author URI: */ function unFocus_insensitivity() { if (preg_match('/[A-Z]/', $_SERVER['REQUEST_URI'])) { $_SERVER['REQUEST_URI'] = strtolower($_SERVER['REQUEST_URI']); $_SERVER['PATH_INFO'] = strtolower($_SERVER['PATH_INFO']); } } add_action('init', 'unFocus_insensitivity'); ?>
Pretty simple really. Honestly, it doesn’t really even need to use a WordPress hook, just the two lines that convert the $_SERVER variables would do it (assuming those aren’t locked down in the php.ini). But I wanted to learn the plugin API anyway. There is an archive download at the end of this post, just unzip the enclosed file, and put it in your plugin directory, upload it and turn it on. No other configuration necessary.

If there is any interest, I was thinking about adding a config option that would allow you to either forward to the all lowercase URL, or to do what it does now, which is to behave pretty much the way IIS does for any other static files it hosts.

Also, if there’s interest, I may try to figure a way to work this WordPress IIS Permalink 404 handler into the plugin, if it’s possible (IIS users would set their custom 404 handler redirect URLs to redirect to /wordpresslocation/index.php instead of /wordpresslocation/404.php, which is how you do it now):
[cc lang=’php’ ]
< ?php $_SERVER['REQUEST_URI'] = substr( $_SERVER['QUERY_STRING'], strpos( $_SERVER['QUERY_STRING'], ':80' ) +3 ); $_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI']; include('index.php'); ?>
The archive – unFocus.Insensitivity

Update: Fixed the download link.

Author: Kevin Newman

I'm the lead developer at adcSTUDIO located in Kingston NY (in Livingston Manor NY before that). I do all kinds of things there, from robust server side work to the much more enjoyable client side development in HTML/JavaScript/Flash (RIAs, HTML5, etc.) and all the other tech-buzz-phrases of the moment. My brother came up with the idea for which was originally meant be a place to discuss and blog about whatever topics we both found interesting, from politics to technology, to art and design. Time was scarce, and I need a place to host History Keeper, and unFocus Projects - a sub focus of was born, and eventually migrated to the font page. Oh, and I'm on Twitter (@Touvan) and Google+.

25 thoughts on “Case Insensitive Permalinks Plugin for WordPress”

    1. With all the work that has gone into core, and into IIS for that matter, this really shouldn’t be needed. Also, I no longer maintain this, since I’m on Apache hosting now.

    1. I haven’t worked on this in quite a long while. My site now works without it, and urls are not case sensitive. Since it’s already like that here, I’m not sure how I’d approach an update. One note; I am using a plugin called Redirection. Perhaps that disables case sensitivity?

  1. This plugin is exactly what I was looking for. It saved me from having to change the domain in books that had already been submitted for publication.

Leave a Reply

Your email address will not be published. Required fields are marked *