Dealing with a move to a case sensitive server (linux) from a case-insensitive one (windows)

In order to avoid 404 pages showing up for incorrect letter cases, all file names should be lower case and when not matching from an old link an htaccess process to convert uri to lower case.

1 – The .htaccess file

Code (text):
  1. RewriteEngine On
  2. RewriteBase /
  3. RewriteCond %{REQUEST_FILENAME} !-f
  4. RewriteRule .* http://www.domain.com/badRequests.php [L]

2 – badRequests.php

PHP:
  1. <?php
  2. // get the lowercase version of the URI
  3. $lower = strtolower($_SERVER[‘REQUEST_URI’]);
  4. // If the URI isn’t the same as the lowercase version, redirect to the lowercase version
  5. if($_SERVER[‘REQUEST_URI’] !== $lower) {
  6.     header(‘Location: ‘.$lower);
  7.     die();
  8. }else{
  9.     //Otherwise give a 404 error
  10.     header(“HTTP/1.0 404 Not Found”);
  11.     die();
  12.     //You could remove the die() line above of course to allow this to execute
  13.     //This will send the user to the errordocument.php file, where you can show
  14.     //your custom error document file if you wish
  15.     header(‘Location: /errorDocument.php’);
  16.     die();
  17. }

3 – an optional errorDocument.php file containing your error message

Leave a Reply

Your email address will not be published. Required fields are marked *