Case Insensitive Permalinks Plugin for WordPress

For a while I have been creating and sending links to History Keeper to /projects/HistoryKeeper/. 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:

< ?php /* Plugin Name: unFocus.Insensitivity Plugin URI: /projects/ Description: A plugin to make permalinks case insensitive. Version: 1.0a Author: Kevin Newman Author URI: /projects/ */ function unFocus_insensitivity() { if (preg_match('//', $_SERVER)) { $_SERVER = strtolower($_SERVER); $_SERVER = strtolower($_SERVER); } } 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):

< ?php $_SERVER = substr( $_SERVER, strpos( $_SERVER, ':80' ) +3 ); $_SERVER = $_SERVER;

include('index.php'); ?>

The archive – unFocus.Insensitivity

Update: Fixed the download link.


Comments

Brandon Wason

June 18, 2009 at 02:16 PM

Thanks for the plugin. It works great and did exactly what I wanted it to!


Kevin Newman

June 21, 2009 at 07:13 AM

Glad I could help! 🙂


Mark A. Poncelet

September 01, 2009 at 04:19 PM

Great post. We owe you a beer!


Kevin Newman

September 02, 2009 at 03:54 AM

Sweet! I’ll take a nice Bard’s Tale Golden Dragon Lager! 🙂


Martin Riley

January 08, 2010 at 05:22 PM

Sir, you are a gentleman and a scholar! Many thanks for this.


Kevin Newman

January 08, 2010 at 08:24 PM

This post is so old, but seems to still be useful. I may have to put this up on wordpess.org.


לימודים

June 21, 2010 at 06:53 PM

Doesn’t seem to work anymore…


Kevin Newman

June 23, 2010 at 04:32 AM

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.


Brian Katz

October 01, 2010 at 10:49 PM

Wish to express our thanks. Thanks!!!!!


Sagive

October 20, 2010 at 03:43 AM

bummer… doesesnt work?

needed a plugin that does the opposite.

would it if i change to lower to upper ?


Kevin Newman

October 20, 2010 at 04:24 PM

It should be possible to do that with a plugin called redirection and a simple regex to convert everything to uppser case. I’d say look into that: http://urbangiraffe.com/plugins/redirection/


Chris

February 16, 2011 at 07:12 AM

Checked it out tonight and sad to say, it did not work. Any further updates coming?


Kevin Newman

March 17, 2011 at 02:18 AM

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?


PA

August 16, 2011 at 06:50 AM

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.


Kevin Newman

August 30, 2011 at 11:44 PM

I’m glad it worked for you. 🙂


brian

February 29, 2012 at 06:06 PM

Nice! Thanks hommie!


Megha

June 12, 2012 at 12:43 PM

Great work Kevin.. Your code might be old, but it still do work!

Thanks a lot.

Megha


Brittany

October 26, 2012 at 02:26 PM

Just wanted to say a BIG THANK YOU for this! Exactly what I needed.


Giorgos

December 07, 2013 at 09:36 PM

Excellent! It took me 3 days to find a solution to this issue, THANKS MR NEWMAN!


Nicky Moorhead

September 10, 2014 at 08:50 AM

September 2014 and this plugin is still working a treat. Thank you sir!


Emily Capito

March 23, 2016 at 06:28 PM

THANK YOU! This worked like a charm – it’s virtually never this easy to troubleshoot a WordPress problem.