27
our $my_url = $cgi->url();
28
our $my_uri = $cgi->url(-absolute => 1);
29
30
-# if we're called with PATH_INFO, we have to strip that
31
-# from the URL to find our real URL
32
-# we make $path_info global because it's also used later on
30
+# Base URL for relative URLs in gitweb ($logo, $favicon, ...),
31
+# needed and used only for URLs with nonempty PATH_INFO
32
+our $base_url = $my_url;
33
+
34
+# When the script is used as DirectoryIndex, the URL does not contain the name
35
+# of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
36
+# have to do it ourselves. We make $path_info global because it's also used
37
+# later on.
38
+#
39
+# Another issue with the script being the DirectoryIndex is that the resulting
40
+# $my_url data is not the full script URL: this is good, because we want
41
+# generated links to keep implying the script name if it wasn't explicitly
42
+# indicated in the URL we're handling, but it means that $my_url cannot be used
43
+# as base URL.
44
+# Therefore, if we needed to strip PATH_INFO, then we know that we have
45
+# to build the base URL ourselves:
46
our $path_info = $ENV{"PATH_INFO"};
47
if ($path_info) {
35
- $my_url =~ s,\Q$path_info\E$,,;
36
- $my_uri =~ s,\Q$path_info\E$,,;
48
+ if ($my_url =~ s,\Q$path_info\E$,, &&
49
+ $my_uri =~ s,\Q$path_info\E$,, &&
50
+ defined $ENV{'SCRIPT_NAME'}) {
51
+ $base_url = $cgi->url(-base => 1) . $ENV{'SCRIPT_NAME'};
52
+ }
53
}
54
55
# core git executable to use
2924
# the stylesheet, favicon etc urls won't work correctly with path_info
2925
# unless we set the appropriate base URL
2926
if ($ENV{'PATH_INFO'}) {
2911
- print '<base href="'.esc_url($my_url).'" />\n';
2927
+ print "<base href=\"".esc_url($base_url)."\" />\n";
2928
}
2929
# print out each stylesheet that exist, providing backwards capability
2930
# for those people who defined $stylesheet in a config file