The Linux Page

Why would Redirect and RedirectMatch in Apache2 not work?

As we are working on a new website, we had a problem where a redirect would not work. I tried both: a simple Redirect and a RedirectMatch as follow:

Redirect / http://finball.m2osw.com/
RedirectMatch permanent ^(.*)$ http://finball.m2osw.com$1

Both of these entries would not work at all.

I verified, to make sure, that the alias module was turned on. It was.

ls -l /var/apache2/mods-enabled

This did list the alias.conf and alias.load entries as expected.

So? What else?

Well... This was installed on a new server and we left the default entry in there:

ls -l /var/apache2/sites-enabled

would show:

lrwxrwxrwx 1 root root 35 Feb 11 10:37 000-default.conf -> ../sites-available/000-default.conf

and somehow the default entry had priority over our virtual entry! I think that is because the default had no ServerName entry.

I just deleted the default, because really I don't need all sorts of weird accesses accepted, and it started to work as expected. The RedirectMatch was doing its job.