Brian F Love
Learn from a Google Developer Expert focused on Angular, Web Technologies, and Node.js from Portland, OR.
Learn Angular the right way with Ultimate Courses

Lowercase Your URIs

For SEO purposes, it is often necessary to enforce lowercase URIs on your website. Google (and I believe all other search engines) are case sensitive. In other words, they will recognize the following URLs as two separate and distinct pages:

This is especially problematic if you are using a case insensitive file system such as Windows. Further, as these pages are seen as separate and distinct and contain the same content, you may be penalized for duplicate content. In essence, you are splitting the value of the content between the pages that are distinct, which will water down the SEO value of the page.

The common solution to this problem is to enforce lowercase URIs on your website. We will look at implementing this using Apache's mod_rewrite module, IIS rewriting (available in IIS 7 and greater), and the ISAPI rewrite extension for IIS.

Apache mod_rewrite Module

First, we need to declare a RewriteMap in our httpd.conf file. The httpd.conf file is commonly located at: /private/etc/apache2/httpd.conf. Add the following lines to the end (or anywhere you prefer) of your httpd.conf file.

# Add RewriteMap for redirecting to lowercase URIs
<IfModule mod_rewrite.c>
RewriteMap lc int:tolower

Next, create the RewriteRule to redirect uppercase URLs to lowercase ones.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule ^(.*)$ ${lc:$1} [R=301,L]

Let me explain each line of the code above.

  • Line 1: Filter the rule so that it is not applied to a physical file located on the server
  • Line 2: Filter the rule so that it is not applied to a physical directory located on the server
  • Line 3: Filter the rule so that it is only applied to requests whose URI contains an uppercase letter
  • Line 4: Using the RewriteMap we declared in the httpd.conf file previously, redirect to the lowercase URI using a 301 status code (permanent redirect), noting that this is the last rule that should match.

IIS Rewrite

Add the following code to your web.config file located in the root of your web folder.

<rule name="LowerCaseRule" stopProcessing="true">
<match url="[A-Z]" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{URL}}" />

Helicon's ISAPI Rewrite Extension

We actually use both Apache modrewrite (for development on OS X) and the ISAPI rewrite extension (for Windows servers). Thankfully there is fairly good cross support between the two. There is one notable difference between Apache's modrewrite module and the ISAPI rewrite extension: for Apache mod_rewrite the RewriteMap must be declared at the server (or virtual host) level, and for ISAPI rewrite it must be declared with the RewriteCond in the .htaccess file for your website.

We simply add the following code to the .htaccess file to redirect all uppercase URI requests to lowercase.

RewriteMap lc int:tolower
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule ^(.*)$ ${lc:$1} [R=301,L]

In summary, all methods are fairly easy to implement. The only catch is the difference in support for the RewriteMap declaration between Apache's mod_rewrite module and Helicon's ISAPI Rewrite extension. I hope this helps with your SEO efforts!

Brian F Love

Hi, I'm Brian. I am interested in TypeScript, Angular and Node.js. I'm married to my best friend Bonnie, I live in Portland and I ski (a lot).