Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have this .htaccess files:

ErrorDocument 404 /index.html
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On

RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule (.*) http://mydomain.com/$1 [L,R=301]

RewriteCond %{REQUEST_URI} index.php$
RewriteCond %{QUERY_STRING} ^search=([A-Za-z0-9\+]+)$
RewriteRule ^(.*)$ /mystring-%1.html? [R=301,L]
RewriteRule ^myfolder-([^+]+)\+([^.]+)\.html$ /mp3-$1-$2.html [R=301,L]
RewriteRule ^myfolder-(.*).html$ index.php?search=$1&a=1 [L]
RewriteRule ^myfolder-([a-zA-Z0-9_-]+)-([^-]*)\.htm$ /index.php?search=$1&page=$2 [L]
</IfModule>

I want to redirect all of the Upercase and all case to lowercase URL like this:

/myfolder-sample-URL.html to /myfolder-sample-url.html

share|improve this question
    
To implement such redirect using mod_rewrite and .htaccess you need to use RewriteMap directive which cannot be placed in .htaccess -- only in server config / VirtualHost context. Do you have access to server config? Can you change it? If no -- then you can only implement it when executing the actual page (using PHP/ASP.NET etc). –  LazyOne Aug 23 '11 at 23:45
    
Thanks for suggestion, Yes I have acces to RewriteMap, so... what should I do now? –  pelajar Aug 25 '11 at 1:41

1 Answer 1

up vote 6 down vote accepted

To implement such redirect using mod_rewrite and .htaccess you need to use RewriteMap directive which cannot be placed in .htaccess -- only in server config / VirtualHost context. If you have such access:

1. Place this line inside <VirtualHost> block for your site:

RewriteMap lc int:tolower

2. Place this in your .htaccess:

RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule . ${lc:%{REQUEST_URI}} [R=301,L]

This will redirect (301 Permanent Redirect) any URL that has at least 1 capital letter (Latin letters only) in path part of URL (query string is ignored) to the same but in lower case.

For example:

http://mydomain.com/myfolder-sample-URL.html
=> 
http://mydomain.com/myfolder-sample-url.html

http://mydomain.com/myfolder-sample-url.HTML
=> 
http://mydomain.com/myfolder-sample-url.html

but will do nothing for these URLs:

http://mydomain.com/myfolder-sample-url.html?say=MEOW
http://MYDOMAIN.com/myfolder-sample-url.html

If you want to restrict it to .html files only:

RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule ^.+\.html$ ${lc:%{REQUEST_URI}} [NC,R=301,L]

Where to place: I would place it after domain name redirect rule:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule (.*) http://mydomain.com/$1 [L,R=301]

RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule . ${lc:%{REQUEST_URI}} [R=301,L]

# your other rules

I also recommend using rel="canonical" links:

<link rel="canonical" href="PROPER_URL_HERE" />

If you do not need redirect, but rather ability to serve the file regardless of the file name case (case insensitive file names), then you can use mod_spelling ( http://httpd.apache.org/docs/current/mod/mod_speling.html ) and CheckCaseOnly On directive.

share|improve this answer
    
Many thanks.... –  pelajar Sep 13 '11 at 13:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.