homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Case Insensitive Apache
How to make URLs in Apache not sensitive to letter case
Rackmount Computer

Msg#: 4566850 posted 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]


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved