Convert url to lower case using Apache HTTP

If your site respond to urls that contain uppercase and lowercase characters (the same page responds to urls: yourdomain.com/my-Url, yourdomain.com/my-url), taking into account SEO parameters that is not good since the search engines are case-sensitive so you'd have more than one page indexed with the same content. A trick you can use is to convert all urls to lowercase, so:

Put in the server config

Centos / Fedora / RHEL: /etc/httpd/conf/httpd.conf
Debian / Ubuntu: /etc/apache2/apache2.conf

RewriteEngine On
RewriteMap lowercase int:tolower
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{REQUEST_URI} !.(css|js|php|[jm]pe?g|png|[yx]ml|
    json|gif|ico|pdf|swf|html|flv|doc|pps|rar|zip|eps|
    odt|wmv|avi|tar(.(bz|gz))?|gz)$
RewriteCond %{REQUEST_URI} ^.*[A-Z].*$
RewriteCond %{HTTP_HOST} ^(.*)$
RewriteRule ^(.*)$ http://%1${lowercase:$1} [L]

Note that the first condition excludes all URLs that contain parameters and the second all URLs that make requests to images, pdf, doc, flash, other

Then in each virtual host
RewriteEngine On
RewriteOptions Inherit

Further reading

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.