Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Case Insensitive Apache

How to make URLs in Apache not sensitive to letter case


Rackmount Computer

7:59 pm on Apr 21, 2013 (gmt 0)

The mod-speling module, if available, provides for fixing mis-matched case but is often not available on shared servers. You can do the same thing with some PHP.

First, create and declare a custom 404 page. Add the following to your .htaccess file (where forwarding-site-nocase.html is my custom 404 page):

AddType application/x-httpd-php .html .htm
ErrorDocument 404 /forwarding-site-nocase.html

Next, add the following code to your custom 404 file, starting at line 1. If there is a blank line first, it fails.

$thedomain = 'http://' . $_SERVER['SERVER_NAME'];
header("HTTP/1.1 301 Moved Permanently");
header( 'Location: ' . $thedomain.$mydir );
function getdir($loc,$tfile)
if (file_exists($startloc.$loc) && $handle = opendir($startloc.$loc))
while (false !== ($file = readdir($handle)))
if ($file != "." && $file != ".." && strncasecmp($loc.$file,$tfile,strlen($loc.$file))==0)
return $loc.$file;
return getdir($loc.$file."/",$tfile);
return false;

If you already have a custom 404 page, just paste the above in starting at line 1. All the headers, DOCTYPE declarations, etc., can stay intact following this code.

See <snip>for an example page that works. Change any of the case following the domain and the URL changes to the appropriate lower case and correctly loads. Change to a non-existent page and the custom 404 page displays.

[edited by: incrediBILL at 9:00 pm (utc) on Apr 21, 2013]
[edit reason] URL removed, see forum charter and site TOS for posting rules [/edit]


Featured Threads

Hot Threads This Week

Hot Threads This Month