Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to have GitList (PHP web viewer for git) and GIT Smart HTTP(S) under the same domain git.domain.ext. The following is the actual setup:

  • GIT Smart HTTP URLs are the form git.domain.ext/git/reponame.git
  • GitList is served through git.domain.ext/gitlist

So far, so good. Everything works.

What I would like to achieve is the following:

  • Any request of the form git.domain.ext/*.git should instead go to git.domain.ext/git/*.git
  • Any other request should default to git.domain.ext/gitlist

The following is my Apache config:

 <VirtualHost *:443>
    ServerName git.domain.ext
    DocumentRoot /home/user/www/git.domain.ext

    SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER
    SetEnv GIT_PROJECT_ROOT /home/user/git/
    SetEnv GIT_HTTP_EXPORT_ALL

    ScriptAlias /git/ /usr/lib/git-core/git-http-backend/

    <Location />
            AuthName "Git Authentication"
            AuthType Basic
            Require valid-user
            AuthUserFile /home/user/git/.htpasswd
    </Location>
    <LocationMatch "^/git/.*/git-receive-pack$">
            AuthType Basic
            AuthName "Git Access"
            Require valid-user
            AuthUserFile /home/user/git/.htpasswd
    </LocationMatch>
    [..]
 </VirtualHost>

The following is the .htaccess under /home/user/www/git.domain.ext

AuthName "Git Authentication"
AuthType Basic
Require valid-user
AuthUserFile /home/user/git/.htpasswd


<IfModule mod_rewrite.c>
    Options -MultiViews

    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^(.*)\.git
    RewriteRule ^(.*)\.git /git/$1.git [R=301,L]

    RewriteRule ^(.*) /gitlist/ [R=301,L]
</IfModule>

Git operations with the original /git/*.git work:

git clone https://user@git.domain.ext/git/test.git
Cloning into 'test'...
Password for 'https://user@git.domain.ext':
remote: Counting objects: 343, done.
remote: Compressing objects: 100% (322/322), done.
remote: Total 343 (delta 110), reused 149 (delta 12)
Receiving objects: 100% (343/343), 1.13 MiB | 1.36 MiB/s, done.
Resolving deltas: 100% (110/110), done.

Unfortunately, git operations with the wanted /*.git don't work:

git clone https://git.domain.ext/test.git
Cloning into 'test'...
Password for 'https://user@git.domain.ext':
fatal: https://user@git.domain.ext/test.git/info/refs?service=git-upload-pack not found: did you run git update-server-info on the server?

However, it seems that the redirect works:

curl --user user:pass https://git.domain.ext/test.git

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://git.domain.ext/git/test.git">here</a>.</p>
[..]

Thanks for your help.

share|improve this question

2 Answers 2

As I understand it, git as a client doesn't handle redirects. Is there any reason you want that rewrite to happen as a redirect rather than as a silent rewrite (i.e. without the R=302 option)?

share|improve this answer
    
No reason at all. I am not an expert on this stuff. Unfortunately, removing the R option (thus, keeping only [L]) does not solve the problem. curl reports a 302 to /git/test.git but git clone fails with the same message (keeping /test.gif in the error message). –  dgraziotin Feb 4 '13 at 10:05
up vote 0 down vote accepted

As it turned out, it is always a mod_rewrite error :-)

To make work, I used the following in my .htaccess:

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^(.*)\.git
    RewriteRule ^(.*)\.git /git/%{REQUEST_URI} [L]
    RewriteRule (.*) /gitlist/ [R,L]
</IfModule>

The problem was in the previous RewriteRule ^(.*)\.git /git/$1.git [R=301,L], which was generating 404 errors. Strangely enough, I could spot them only using --verbose with curl.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.