Reputation: 10041
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: www.example.com/AbC1.php has the same content as www.example.com/abc1.php. 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?
Upvotes: 4
Views: 10080
Reputation: 9856
I didn't want this to apply to existing files and folder names, so I changed the .htaccess part of Jon Lin's excellent solution to:
RewriteCond $1 [A-Z]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /${lowercase:$1} [R=301,L]
Upvotes: 1
Reputation: 143906
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)
Upvotes: 9