Linux Format

Case-insensitiv­e URLs

-

Q

I have a small content download service for an old game. Unfortunat­ely, it may call for a file using different upper/ lowercase characters and I can’t change that.

Basically I need my webserver to accept a request for a file such as /asd however it’s requested – such as http://localhost/asd, http:// localhost/AsD and so forth. I’ve discovered that it’s possible to do this with Apache, but I don’t want to change webserver. Is it possible with lighttpd? jevgienij,fromsocial­media

A

This is possible with lighttpd and can be carried out in one of two ways. If you’re only serving these files from the server, or all other files are guaranteed to be lower case, you can force lighttpd to consider all filenames as lowercase by adding this line to your configurat­ion file: server.force-lowercase-filenames = “enable”

If, on the other hand, you wish to apply this to only files in a particular directory, you can use the rewrite module. Enable this by adding, or uncommenti­ng, mod_rewrite in your server.modules list. Then create a rewrite rule like this: url.rewrite-once = ( “^/mydir/(.*)” => “/ mydir/${tolower:1}” )

This will replace all strings starting with /mydir/ with their lower case version. Obviously you’ll change that to suit the directory that’s on your server. However, there’s also a neater, if less flexible, version: url.rewrite-once = ( “^/mydir/.*” => “/${tolower:url.path}” )

The first uses a regex backrefere­nce, where the contents of the parenthese­s are used in place of the $1, and you can have more groups like this – $2, $3 and so on – just like sed. The second simply operates on the whole path portion of the URL.

The tolower and associated functions were only added in version 1.4.50 of lighttpd, so you will need to be running the latest. Otherwise you are stuck with using more cumbersome regular expression replacemen­ts or using the global setting.

 ??  ?? Lighttpd can do most things Apache does, but often in a different way.
Lighttpd can do most things Apache does, but often in a different way.

Newspapers in English

Newspapers from Australia