This guide is to help users who were previously on a case insensitive web server and hosting many directories and files on their server mixed with upper and lower case letters who wish to move to a server that has case sensitivity such as Linux, or more specifically Ubuntu running Apache.

In this scenario, the Ubuntu Apache server is also running a Multi-site WordPress, running multiple domains on the same server so the traditional ways of configuring the vhosts file may not possible.

The trick is to set up a rewrite rule that essentially takes any URL provided to the server, and interprets it as a lowercase URL.

This seems pointless at first, but the trick is that the files being migrated to the Multi-site WordPress server, can be copied in just lower case form.

I found the easiest trick is to simply zip up all of the files, and then unzip them.

zip -0 -r foo.zip foo/
unzip -LL foo.zip

This will zip up the foo directory (including the directory itself) that contains all of the files and folders, and then UNZIP it all using the -LL flag which makes it all lowercased folders and files.

You can then perform the command:

cp -r /foo/* /var/www/html

to move the contents of everything that was inside the foo folder, directly into the html folder.

This will take care of having a migrated set of data that’s strictly in lower cased form.

The next step is to have Apache actually reference the lower case version each time a request is made.

For that we’ll need to sure mod_rewrite is enabled if it’s not already by running:

sudo a2enmod rewrite
sudo service apache2 restart

Next, we’ll need to edit the global apache2 conf file

sudo nano /etc/apache2/apache2.conf

At the bottom of the file include the lines:

RewriteEngine On
RewriteMap  lc int:tolower

Next, we’ll need to edit the .htaccess file used by WordPress

This should be found in the root of our webserver directory that WordPress is hosted on.

sudo nano /var/www/html/.htaccess

At the top of the file under the Options -Index (if it exists as the first line)

Place the lines of:

RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]

The RewriteCond will check if any characters in the URL contain a capital letter.

If there is a capital letter found, it will run the function lc (defined in the apache2.conf file) that will convert the string $1, which is the regex group defined by (.*)  which is the whole URL in this case, to a lower case string.

It will then perform a redirect 301, and the L will indicate that this the LAST thing involved with this RewriteCond and RewriteRule set.