From 3887fbb84bd274fb2a1f35c1ba0ce11ad67798aa Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Fri, 11 Apr 2014 22:40:36 -0700 Subject: [PATCH] config: make the /w/ prefix optional for gitweb URLs When mod_rewrite is enabled, a GitWeb URL that matches an existing repository but lacks the leading /w/ prefix will be automatically handled by GitWeb. Alternatively, with a minor tweak to the sample configuration such URLs can be redirected instead of being served directly. --- Girocco/CGI.pm | 2 +- Girocco/Config.pm | 7 +++++++ Girocco/Util.pm | 2 ++ apache.conf | 11 +++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Girocco/CGI.pm b/Girocco/CGI.pm index e06afc2..4e9fe54 100644 --- a/Girocco/CGI.pm +++ b/Girocco/CGI.pm @@ -117,7 +117,7 @@ $extraheadhtml$vulnrandpad EOT diff --git a/Girocco/Config.pm b/Girocco/Config.pm index c62ac92..595cc6b 100644 --- a/Girocco/Config.pm +++ b/Girocco/Config.pm @@ -192,6 +192,8 @@ our $webroot = "/home/repo/WWW"; our $cgiroot = "/home/repo/WWW"; # A web-accessible symlink to $reporoot (corresponds to $httppullurl, can be undef) +# If using the sample apache.conf (with paths suitably updated) this is not required +# to serve either smart or non-smart HTTP repositories to the Git client our $webreporoot = "/home/repo/WWW/r"; @@ -243,6 +245,11 @@ our $rsakeylength = undef; ## URL addresses # URL of the gitweb.cgi script (must be in pathinfo mode) +# If mod_rewrite is enabled and the sample apache.conf configuration is used +# (with paths suitably updated), the trailing "/w" is optional for all browsers +# that send a User-Agent string WITHOUT (case insensitively) "git/". Alternatively +# a minor change to the sample apache.conf can redirect (301 or 302) URLs without +# the "/w" to a URL with it where appropriate. our $gitweburl = "http://repo.or.cz/w"; # URL of the extra gitweb files (CSS, .js files, images, ...) diff --git a/Girocco/Util.pm b/Girocco/Util.pm index b1a305f..8fcd498 100644 --- a/Girocco/Util.pm +++ b/Girocco/Util.pm @@ -215,12 +215,14 @@ sub url_base { # the host:port part otherwise return the entire argument. sub url_path { my $url = shift || ''; + my $no_empty = shift || 0; # See RFC 3968 $url = $1 if $url =~ m,^(?: [A-Za-z][A-Za-z0-9+.-]*: ) # scheme (?: // ) # // separator (?: [^\@]+\@ )? # optional userinfo (?: [^/?#]+ ) # host and port ((?:[/?#].*)?)$,x; # path and optional query string and/or anchor + $url = '/' if $no_empty && $url eq ''; return $url; } diff --git a/apache.conf b/apache.conf index 0b92fc9..eee64ae 100644 --- a/apache.conf +++ b/apache.conf @@ -27,6 +27,17 @@ ScriptAlias /w /home/repo/WWW/gitweb.cgi ScriptAlias /h /home/repo/WWW/html.cgi + + # Make the leading /w optional if the rest names an existing repo + RewriteEngine On + RewriteCond %{HTTP_USER_AGENT} !git/ [NC] + RewriteCond /srv/git/$1/HEAD -f + # Might want to use [NC,L,R] instead of [NC,PT] maybe even [NC,L,R=301] + RewriteRule \ + ^/(?!w/)((?:[a-z0-9+._-]+(? + Options FollowSymLinks AllowOverride None -- 2.11.4.GIT