We have a lot of direct mail that need vanity urls. This required constant management of these urls almost every week. We needed to make them case-insensitive due to our audience and some direct mail that somehow got out the door with capitals. We started going down the route of regex “^/(?i)” in front of url to make case-insensitive. The caused a problem because I was wanting power users to be able to manage these redirects in the future through a plugin. I also called our hosting company WPEngine to add the apache/nginx module to make on server side have case-insensitive but because of their standard builds they were not able to implement. So that lead me to find this article that created a plugin that looked for caps and made lower on the init of WordPress. Here is the code below and also link to the source.
http://code.rawlinson.us/2012/01/force-wordpress-to-be-case-insensitive.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<?php /* Plugin Name: case-insensitive-url Plugin URI: http://www.unfocus.com/projects/ Description: A plugin to make wordpress case insensitive in regards to urls. Version: 1.0a Author: Kevin Newman Author URI: http://www.unfocus.com/projects/ */ function case_insensitive_url() { 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', 'case_insensitive_url'); ?> |