Originally Published: Wednesday, 7 February 2001 Author: Marc Perkel
Published to: enhance_articles_sysadmin/Sysadmin Page: 1/1 - [Printable]

Making Apache Case Insensitive Using Samba

Making life easier is always a good idea and a desired goal. Writer Marc Perkel has found a way to make Apache case insensitive using Samba. Here's how you do it.

   Page 1 of 1  

Here's a trick I finally got to work: a way to make Apache requests case insensitive on Linux/Unix servers and work as well as Windows NT servers.

The problems started when I was migrating from NT to Linux. As you know, NT is case insensitive, so anything matched. Thus a request to http://domain.com/INDEX.HTML and http://domain.com/index.html were the same. However upon moving to Linux, the request for INDEX.HTML produced a 404 error, not found.

I changed all my files and references to lower case, but that didn't solve everything. There were still external Web sites that linked to me that were in the wrong case. At first I came up with rules to convert all requests to lower case, but now I have a better solution.

The trick is to use SAMBA and let the server mount itself as a Windows client.

Samba is a service that emulates a Windows NT server. It normally is used to let Windows machines to access Linux files pretending to be a Windows server. Some say that Linux is a better NT server than NT itself. One of the features of Samba is that the file system is not case sensitive. You can save a file in and case and it preserves it. But a file request in any case matches. Thus under Samba, INDEX.HTML and index.html are the same file.

Here's how I do it. I have a directory named /www where my Web sites are stored. I have another directory named /smbwww which I use as an smbfs mount point to mount a Samba share. The idea is to mount /www as /smbwww using Samba services. Thus files under /smbwww are the same as /www but you no longer have to match case to load the Web page.

I created a Samba share named "wwwshare". The "wwwshare" share exports the directory /www. I made a dummy user "smbuser" to have rights to the share using smbpasswd.

smbpasswd -a smbuser mypassword

I also made the share read-only and restricted access to 127. block of IP addresses (allow hosts). Thus it can be loaded only from the localhost and is secure. I use linuxconf to configure the Samba shares.

Then I mount the share as follows:

mount -t smbfs -o username=smbuser,password=mypassword

Thus /www and /smbwww are the same except /smwww is processed through Samba and all your case problems go away. If you want to preserve the old case rules, you can still access /www. You have the best of both worlds. Does it slow you down? Use more processor or resources? Sure, in theory. But I'm running on a Pentium III box in the first place and have excess power to start with.

This process eliminated a problem that had been very annoying and greatly reduced the number of 404 errors on my system. Using the Samba file system also has other side benefits in that it allows me to mount my Web server remote for either Linux or Windows machines and provides encrypted password access to my file system. That's something NFS doesn't have. And it gives me more power to control which users and groups have access to which directory structures. So far I'm very happy with this solution.

Marc Perkel may be contacted at Marc@perkel.com or http://linux.ctyme.com.

   Page 1 of 1