Forum Moderators: phranque
I want to do a 301 redirect for some urls on my site. The case is to change any character in uppercase to lowercase in the url.
For eg:
Current: http://domain.com/widgets/A.html to
Required: http://domain.com/widgets/a.html
OR
Current: http://domain.com/widgets/M-1.html to
Required: http://domain.com/widgets/m-1.html
The case change will occur only for the html files and not the directories as the directories are all in the lowercase, but some html files are in uppercase.
Can anyone provide me with a simple code that I can use in my .htaccess file?
Perhaps two coding options could work here:
- Change any character in the entire url from uppercase to lowercase.
OR
- change any character in the "*.html" part of the url from uppercase to lowercase. (Only this case applies for me)
Please assist! TIA
[edited by: jdMorgan at 2:08 pm (utc) on May 17, 2004]
[edit reason] Fixed thread title [/edit]
The problem is that RewriteMap is not available in an .htaccess context. If you can put the code into your server's httpd.conf file, then the tolower: function given in the RewriteMap example (see Apache mod_rewrite documentation) will work nicely.
Otherwise, see this thread [webmasterworld.com] for a method that works in .htaccess. But note the warnings about speed degradation for the most general case of converting any number of uppercase letters anywhere in the URL to lowercase, and adapt the code for your needs to avoid this.
Jim
I don't quite understand how to do it and my server admin is out of town for a few days. I do play around with the httpd.conf and other configuration files and am aware of the basic tricks.
However if you could provide me with exact steps and code that i need to follow to make this happen, I would be pleased to try it out myself :)
TIA
p.s. - Thanks Jim for fixing the thread title :)
Please review our charter [webmasterworld.com]. Hopefully, we can point you in the right direction.
Something like this might do what you want, but you'll have to research it and test it.
RewriteMap lowercase int:tolower
RewriteCond ${lowercase:%{REQUEST_URI}¦NONE} ^(.+)$
RewriteRule .* http:www.yourdomain.com%1 [R=301,L]
RewriteMap lowercase int:tolower
RewriteRule .* http:www.yourdomain.com${lowercase:%{REQUEST_URI}} [R=301,L]
Jim
[edit] changed internal rewrite to requested 301 external redirect [/edit]