78

I am running apache2 on Debian etch, with multiple virtual hosts.

I want to redirect so that http://git.example.com goes to http://git.example.com/git/

Should be really simple, but Google isn't quite cutting it. I've tried the Redirect and Rewrite stuff and they don't quite seem to do what I want ...

MrWhite
  • 11,643
  • 4
  • 25
  • 40
Hamish Downer
  • 9,142
  • 6
  • 36
  • 49
  • There are many ways you could approach this, but what is exactly what you are trying to accomplish? – WerkkreW May 19 '09 at 17:24

4 Answers4

128

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".

Hamish Downer
  • 9,142
  • 6
  • 36
  • 49
3

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.

Amandasaurus
  • 30,211
  • 62
  • 184
  • 246
2

You can use Redirect directive.

<Directory />
   Redirect permanent / http://git.example.com/git/
   ...
</Directory>
  • 2
    This NOT work! Firstly, tags are used for local filesystem path, not for url. For url use tags. Secondly, "Redirect" matches partial url from the left. Thus /git is also a match, creating a infinite redirect loop. – 把友情留在无盐 Dec 12 '19 at 13:04
0

The accepted answer resolved my issue, but I also found that I had to add a 404 redirect for non-existant pages -- my situation is that have an OwnCloud installation located one level below root (https://example.com/owncloud).

This worked for me, to send everything to my subdirectory:

# redirect from root to subdirectory
RedirectMatch ^/$ /thesubdirectory/

# redirect on 404 to subdirectory
ErrorDocument 404 /thesubdirectory/index.php
J4yne
  • 11
  • 1