Permanently Redirect all URL’s to Lowercase

Ideally I like to keep all urls in lowercase, but there are a few things that can lead to your site being indexed with a mixture of upper and lower case characters, which in turn can lead to problems with search engines.

How can this happen? Well, for me it was playing around with Joomla's sh404sef component and not checking the settings properly. By default it is set to use the case of category and article titles which resulted in some ugly /Joomla/Page-Title type urls. Whilst the component was installed it wasn't a problem. After removing it (for many reasons) the problems started. When requesting the above url Joomla will serve the page /joomla/page-title and the url in the browser will remain as /Joomla/Page-Title.

If applications do this by default then it only takes a rival company to point several mixed-case links to your site to potentially cause a lot of problems.

So how can it be fixed?

Well, my first thought was to use Apache's mod_rewrite to 301 everything to lowercase, but first of all, this isn't possible and secondly, you need to be careful about 301's as they can be detrimental to your seo efforts when overused.

To make this happen we need Apache's RewriteMap directive which can only be added in the servers httpd configuration file (the standard file or a virtual include). Once the RewriteMap is added there, it can be used in .htaccess RewriteRule's but if you have access to the conf files then you shouldn't be using a .htaccess file for the domain root at all.

Within the domains (virtual) configuration file you need to include the following RewriteMap and Rewrite rule. It will 301 any url which contains at least 1 uppercase char and leave any other urls's alone.

<VirtualHost *:80>
DocumentRoot /home/xxxx/domainroot
ServerName robertwent.com
RewriteEngine On
RewriteMap lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule . ${lc:%{REQUEST_URI}} [R=301,L]
<directory /home/xxxx/domainroot>

Remember that this will also change the case for image and css urls so use it wisely