And why do you have to do it at the .htaccess level?
I have repeatedly encountered the fact that the attempt to convert registers via .htaccess led to the fact that the corresponding Apache process was eating out all the memory that could reach. I don’t know what it was connected with, but I myself observed such a problem and came across descriptions on the Web.
As an alternative, I have come across such a rather smart method, which is much less expensive in memory: https://www.simonholywell.com/post/2012/11/force-lowercase-urls-rewrite-php/
Its essence is that requests that contain uppercase and are not a file on disk are redirected to a special PHP script:
RewriteEngine on RewriteBase / # force url to lowercase if upper case is found RewriteCond %{REQUEST_URI} [AZ] # ensure it is not a file on the drive first RewriteCond %{REQUEST_FILENAME} !-s RewriteRule (.*) rewrite-strtolower.php?rewrite-strtolower-url=$1 [QSA,L]
And the file itself contains the following code:
<?php if(isset($_GET['rewrite-strtolower-url'])) { $url = $_GET['rewrite-strtolower-url']; unset($_GET['rewrite-strtolower-url']); $params = http_build_query($_GET); if(strlen($params)) { $params = '?' . $params; } header('Location: http://' . $_SERVER['HTTP_HOST'] . '/' . strtolower($url) . $params, true, 301); exit; } header("HTTP/1.0 404 Not Found"); die('Unable to convert the URL to lowercase. You must supply a URL to work upon.');
You can also try using the mod_speling module. As stated in the documentation: "If, after scanning the directory, ... only one document is found that "almost" matches the request, then it is returned in the form of a redirection response" If all you need is case conversion - enable CheckCaseOnly on directive.