How to get Apache2 to redirect to a subdirectory

Solution 1:

Feel a bit silly - a bit more googling turned up the answer I was after:

RedirectMatch ^/$ /git/

Basically redirecting the root, and only the root.

This code could do in a .htaccess file (there is a tag for this, so I assume that is the original use case). But if you can edit ,the main server apache config then put it in the section for your website probably inside a <VirtualHost> section.

The docs for RedirectMatch say that the context can be "server config, virtual host, directory, .htaccess".

Solution 2:

You've got the correct answer there with the redirect. You have to be careful when redirecting everything to somewhere else, since you can get recursive redirects there. This happens if you want to put up a maintenance page.


Solution 3:

You can use Redirect directive.

<Directory />
   Redirect permanent / http://git.example.com/git/
   ...
</Directory>