git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] gitweb: fix base url set if PATH_INFO is used, add a / at the end

From
DADaniel Abrecht <git-git@nodmarc.danielabrecht.ch>
Date
Feb 14, 2023, 10:15 UTC
Message-ID
<522571c427c937ef52bb69b88cb3dea1@nodmarc.danielabrecht.ch>
In-Reply-To
<xmqqfsbel9sf.fsf@gitster.g>
Am 2023-02-10 00:05, schrieb Junio C Hamano:
Show 14 quoted lines
> Daniel Abrecht <git-git@nodmarc.danielabrecht.ch> writes:
>> +	# the browser will strip away the last component for relative URLs.
>> +	# Add the / if it's missing.
> 
> The above is not an incorrect statement per-se, but if $base were
> pointing at the document, we would likely break if we add an extra
> slash.  Don't we want to say something like
> 
> 	# $base_url at this point points at a directory, not a
>         # single document, and later is used in the <base> tag.
>         # Make sure it ends in a '/'.  Otherwise, we'd lose the last
>         # component when forming a relative URL.
> 
> perhaps?

After thinking about this for a while, I realized that this isn't as simple as I thought.

I'm currently using apache and some rewrite rules so I can access projects at /git/myproject.git/ (See my config below). So in my case, $base_url is /git at this point, and I need to add a /.

But if I didn't have those rewrite rules, I could instead access the repos using /git/gitweb.cgi/myproject.git/ . In that case, $base_url would be /git/gitweb.cgi at this point, so it does refer to the script / document. The assets are still at /git/ and not at /git/gitweb.cgi/, so links are relative to /git/gitweb.cgi/ but assets are relative to /git/. It seams relative URLs are only used for assets, so the $base_url should really be /git/gitweb.cgi or alternatively just /git/ there, and just adding a slash would be wrong in that case.

Given this, I no longer think I should change the way it currently is. I will just override $base_url in my config file instead.

<Macro gitweb $location>
   SetEnv GITWEB_CONFIG /etc/gitweb.conf
   SetEnv GIT_HTTP_EXPORT_ALL
   ScriptAliasMatch \
   "(?x)^/.*/(.*\.git/(HEAD | \
       info/refs | \
       objects/(info/[^/]+ | \
          [0-9a-f]{2}/[0-9a-f]{38} | \
          pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
       git-(upload|receive)-pack))$" \
   /usr/lib/git-core/git-http-backend/$1
   Alias $location/ /usr/share/gitweb/
   RewriteRule 
^$location/.*\.git/(HEAD|info|objects|refs|git-(upload|receive)-pack) - 
[E=GIT_PROJECT_ROOT:%{DOCUMENT_ROOT}$location/,PT,END]
   RewriteRule ^$location/(.*\.git(/.*)?)?$ $location/gitweb.cgi/$1 
[E=GIT_PROJECT_ROOT:%{DOCUMENT_ROOT}$location/,L,PT]
   <Location $location>
     Require all granted
     AllowOverride None
   </Location>
   <Directory /usr/share/gitweb/>
     Options +FollowSymLinks +ExecCGI
     AddHandler cgi-script .cgi
   </Directory>
</Macro>
<VirtualHost *:443>
   Use VHostSSL projects.dpa.li
   DocumentRoot /var/www/projects.dpa.li/
   Use gitweb /git
</VirtualHost>
Previous: Junio C Hamano
Message 2 of 2 in “Re: [PATCH v2] gitweb: fix base url set if PATH_INFO is used, add a / at the end”
  1. Junio C HamanoFeb 9, 2023
  2. Daniel AbrechtFeb 14, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.