Getting redirects to work in Apache for Gitweb
April 22, 2009 11:12 PM   Subscribe

I've setup Gitweb as a sub-folder off my primary domain and have pathinfo enabled so that I get nice looking URLs. Everything works fine if I type http://my.domain.com/gitweb/ but if I miss the trailing slash I get 404 errors. Seems like a simple problem, but so far nothing's working!

Here's my gitweb.conf:

$feature{'blame'}{'default'} = [undef];
$feature{'pickaxe'}{'default'} = [undef];
$feature{'search'}{'default'} = [undef];
$feature{'grep'}{'default'} = 1;
$feature{'snapshot'}{'default'} = ['tgz', 'gzip', 'zip'];
$feature{'snapshot'}{'override'} = 1;

$projects_list = "/var/git/gitosis/projects.list";
$export_ok = "";
$strict_export = "true";

$site_name = "The Average Geek's Git Repo";
$fallback_encoding = 'utf-8';
@stylesheets = ("gitweb.css");
$projects_list_description_width = 50;

# This lets it make the URLs you see in the header
@git_base_url_list = ( 'git://my.domain.com');

# Title
$home_link_str = 'The Average Geek';

# nicer-looking URLs
$feature{'pathinfo'}{'default'} = [1];
$my_uri = "http://my.domain.com/gitweb/gitweb.cgi";
$home_link = "http://my.domain.com/gitweb/";


Onto my httpd.conf:

Alias /gitweb/ /var/www/gitweb/
RewriteEngine On
RewriteRule ^gitweb$ gitweb/ [R]

<Directory "/var/www/gitweb/">
AllowOverride AuthConfig
Options +ExecCGI +Indexes
Order allow,deny
Allow from all
DirectoryIndex gitweb.cgi
SetEnv GITWEB_CONFIG "/etc/gitweb.conf"
AddHandler cgi-script .cgi
RewriteEngine On
RewriteBase /gitweb/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.* /gitweb.cgi/$0 [L,PT]
</Directory>


The Rewrite conditions inside the Directory stanza are "recommended" by the gitweb README if the pathinfo option is enabled.

Things I have tried so far (mostly based on recommendations from the #git #httpd IRC channels)

- Various combinations of the RewriteRule for ^gitweb$
- Added a RewriteBase
- Moved the Rewrite Rule for the trailing slash outside the directory stanza

The URL stubbornly remains 404 without a trailing slash.

FWIW, Version Info: Git 1.6.2.3 built from source, running on Debian 5

Ask Mefites - please help!
posted by your mildly obsessive average geek to Technology (3 answers total)
 
Response by poster: In digging through my scattered notes on configuring servers, I found a note mentioning that if I left off the trailing slash when setting up an alias, I wouldn't hit 404 errors. In other words:

Alias /gitweb /var/www/gitweb
and
<Directory "/var/www/gitweb">

instead of what I've mentioned in the question.

Surprisingly, This does work - I can now type http://my.domain.com/gitweb and get the actual repo listing.

But I can't help but think that is not strictly correct - ie requesting "http://my.domain.com/foo" indicates one is looking for the file named "foo" whereas requesting "http://my.domain.com/foo/" is the correct way of requesting for the subdirectory "foo".

I would still like to know how to get the redirect to work if anyone can figure what's wrong with it.
posted by your mildly obsessive average geek at 1:28 AM on April 23, 2009


I'm a bit rusty with Apache, but since nobody else is answering, here goes.

"/gitweb/" and "/gitweb" are different locations as far as Apache is concerned. This is because you're matching what the user entered, not what the URL logically resolves to (just like "/gitweb/index.html" is different from the preceding two).

As far as the user input goes, ".../foo" and ".../foo/" should be identical. Yes, the first is looking for the file named "foo", it sees that that file is a directory (on Unix, at least, files are directories), and it then looks inside that directory for an index.html or, failing that, will generate a directory listing (since you have +Indexes).

I'm not sure how to get the rewrite to work. I never truly understood the voodoo that is mod_rewrite.
posted by mohrr at 6:11 PM on April 23, 2009


Response by poster: mohrr: Thank you for explaining why /foo and /foo/ still works.

Re: voodoo that is mod_rewrite - you and me both.
posted by your mildly obsessive average geek at 8:02 PM on April 23, 2009


« Older Seeking undergraduate research advice   |   Maybe the technical term for this is swelling Newer »
This thread is closed to new comments.