John Crawford John Crawford - 10 months ago 45
Apache Configuration Question

Force lower case of URLs - Override previous rules

I have inherited a rather scary looking .htaccess file that is filled with previous rules. What I am trying to do is simply make every single URL lowercase for SEO reasons. Currently Google Webmasters is complaining about duplicate pages. eg: has the same content as To solve this I placed the following lines into my vhosts.conf

#Make URL's lower case
RewriteEngine On
RewriteMap lowercase int:tolower
RewriteCond \$1 [A-Z]
RewriteRule ^/(.*)$ /\${lowercase:\$1} [R=301,L]

But due to one of the many rules I have in my .htaccess file this rule isn't working. Can I add that above rule and ensure that it overrides any other rules?

Answer Source

You can add it above any other rules in your htaccess file but the rewrite map definition must be in your vhost config, so in vhost:

RewriteEngine On
RewriteMap lowercase int:tolower

And in the very top of your htaccess file:

RewriteCond $1 [A-Z]
RewriteRule ^(.*)$ /${lowercase:$1} [R=301,L]

(note that you don't need to leading slash)