Home > Linux, Technical, apache, server, web > Lower-case all URLs with Apache mod_rewrite

Lower-case all URLs with Apache mod_rewrite

February 5th, 2010

Search engines, like Google, will index URLs on your site in a case-sensitive fashion, so www.yoursite.com/iamtest shows up as a different page than www.yoursite.com/iAmTest. This has negative consequences for your search rankings as these different URLs will be interpreted as duplicate content.

In this case we want to re-direct our users and any bots to the same version of the URL (i.e. all lowercase). If you are running Apache, make sure mod_rewrite is installed and make the following changes to your configuration.

1. In your server config or virtual host file:
RewriteMap lc int:tolower

2. In your .htaccess file at the root of your site:

# Lower-case and 301 all requests
RewriteEngine On
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule ^(.*)$ /${lc:$1} [L,R=301]

Note: Beware that some standard files are mixed case and might be broken by doing this (such as AC_RunActiveContent.js).

Linux, Technical, apache, server, web , , , , ,

  1. IT-Pulse
    March 26th, 2010 at 23:38 | #1

    Hello,

    I have written in my blog about your article and extended the code with two Rewrite Conditions.
    -> http://www.it-pulse.eu/2010/03/apache-mod-rewrite-gross-kleinschreibung.html

  1. No trackbacks yet.