0

I have read this thread a method that will actually take any URL on my site and translate it to lower case. I was planning to then use that, and modify it as needed, to make sure that the last part of URLs don't change (so my PHP Get variables can remain however they are meant to be, but anything that is a directory will be made into lowercase on the server's end).

Unfortunately it produces a 500 internal server error.

So that there is an example or two:

www.domain.com/FirstDirectory1/ThisDirectory2/page.php?var=sdmkfsDFLMSD

turns into

www.domain.com/firstdirectory1/thisdirectory2/page.php?var=sdmkfsDFLMSD

or

www.Domain.com/firstdirectory1/ThisDireCTory2/Page.php?var=sdmkfsDFLMSD

turns into:

www.domain.com/firstdirectory1/thisdirectory2/Page.php?var=sdmkfsDFLMSD

Community
  • 1
  • 1
Shackrock
  • 4,601
  • 10
  • 48
  • 74

1 Answers1

0

first you need to include the external function tolower in your context by adding this directive to your <virtualhost> config (and not .htaccess file):

RewriteMap lc int:tolower

then in your .htaccess:

   RewriteEngine On
   RewriteCond %{REQUEST_URI} [A-Z].+/.+\.php
   RewriteRule (.+)(/.+\.php)$ ${lc:$1}$2 [NC,R=301,L]

note that Apache is case sensitive, so example.com/Directory/ and example.com/directory/ point to different locations, if you have a directory named Dir/ using the above directives will result a 404 Error. if you want to make it case insensitive, enable CheckSpelling module by adding this directive on the top of htaccess:

CheckSpelling On
Amine Hajyoussef
  • 4,381
  • 3
  • 22
  • 26
  • Where is the config on a WHM/Cpanel CentOS 5 server? – Shackrock Apr 23 '13 at 01:06
  • Ok so I have gotten that rewriteMap included successfully now, according to those instructions. I restarted Apache and tried the code in .htaccess as you call for but no luck... It doesn't seem to do anything actually. Any ideas? – Shackrock Apr 24 '13 at 20:49
  • have you added the "rewriteEngine on" directive?(look at my answer above), also, place the .htaccess in the root directory of your website. – Amine Hajyoussef Apr 25 '13 at 02:34
  • Yep, RewriteEngine On is already in there because I'm using it to do some other things (like force direct to HTTPS).... do you think that the other rewrites may be interfering? – Shackrock Apr 25 '13 at 20:51
  • Update: even with no other rewrite conditions or rules in the .htaccess file, it still doesn't seem to work, I get a 404 not found error. – Shackrock Apr 26 '13 at 00:38
  • surely your directory name have an Upper letter, Apache is case sensitive, so example.com/Directory/ and example.com/directory/ point to different locations, if you want to make it case insensitive, add "CheckSpelling On" on the top of htaccess. this should solve your problem, however it's a bad idea to use mixed uppercase and lowercase names in directories. – Amine Hajyoussef Apr 26 '13 at 01:37
  • `CheckSpelling On` gives a 500 server error again. I agree that it would be a fix (or `CheckCaseOnly on`), but I get a 500 server error each time with that. I use ALL lowercase, but I want people to arrive at the lowercase directory if they type it with uppercase is all. So `domain.com/haha` is given when somebody types `DOMAIN.COM/HAHA` – Shackrock Apr 26 '13 at 15:51