Daniel Washburn

Daniel Washburn

cgit + Apache with Clean URLs Recipe

Introduction

cgit is a web interface for git, written in C.


It acts as a CGI script executed by the Apache httpd webserver. The cgit.cgi script itself can reside either in the web-root (with Options +ExecCGI enabled), or in the more tradtional script-root /cgi-bin/. This recipe assumes the latter, but can be trivially adapted.


By default, a cgit URL might look something like:

http://git.example.org/cgi-bin/cgit.cgi/myrepo/commit/?id=f13c741f9a3f1d8239506a46f9343af8c7910842

This is a recipe for creating shorter and more readable “clean” URLs, under the directory /code/:

http://git.example.org/code/myrepo/commit/?id=f13c741f9a3f1d8239506a46f9343af8c7910842

/etc/httpd/httpd.conf

<Directory "/var/www/htdocs">

    ...

    RewriteEngine On
    RewriteRule ^code/(.*)$ /cgi-bin/cgit.cgi/$1 [L]

    ...

</Directory>

Script-Alias /cgi-bin/ "/var/www/cgi-bin/"

<Directory "/var/www/cgi-bin">

    ...

    Options +ExecCGI
    AddHandler cgi-script .cgi

    ...

</Directory>

/etc/cgitrc

# URL which, if specified, will be used as root for all cgit links.
virtual-root=/code/