我正在GitList (Git的PHP web浏览器)和GIT智能HTTP(S)在同一域git.domain.ext下。 以下是实际设置:
到现在为止还挺好。 一切正常。
我想达到的是以下几点:
以下是我的Apacheconfiguration:
<VirtualHost *:443> ServerName git.domain.ext DocumentRoot /home/user/www/git.domain.ext SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER SetEnv GIT_PROJECT_ROOT /home/user/git/ SetEnv GIT_HTTP_EXPORT_ALL ScriptAlias /git/ /usr/lib/git-core/git-http-backend/ <Location /> AuthName "Git Authentication" AuthType Basic Require valid-user AuthUserFile /home/user/git/.htpasswd </Location> <LocationMatch "^/git/.*/git-receive-pack$"> AuthType Basic AuthName "Git Access" Require valid-user AuthUserFile /home/user/git/.htpasswd </LocationMatch> [..] </VirtualHost>
以下是/home/user/www/git.domain.ext下的.htaccess
AuthName "Git Authentication" AuthType Basic Require valid-user AuthUserFile /home/user/git/.htpasswd <IfModule mod_rewrite.c> Options -MultiViews RewriteEngine On RewriteCond %{REQUEST_URI} ^(.*)\.git RewriteRule ^(.*)\.git /git/$1.git [R=301,L] RewriteRule ^(.*) /gitlist/ [R=301,L] </IfModule>
使用原始/git/*.git工作的Git操作:
git clone https://[email protected]/git/test.git Cloning into 'test'... Password for 'https://[email protected]': remote: Counting objects: 343, done. remote: Compressing objects: 100% (322/322), done. remote: Total 343 (delta 110), reused 149 (delta 12) Receiving objects: 100% (343/343), 1.13 MiB | 1.36 MiB/s, done. Resolving deltas: 100% (110/110), done.
不幸的是,与想要的/*.git混帐操作不起作用:
git clone https://git.domain.ext/test.git Cloning into 'test'... Password for 'https://[email protected]': fatal: https://[email protected]/test.git/info/refs?service=git-upload-pack not found: did you run git update-server-info on the server?
但是,似乎redirect工作:
curl --user user:pass https://git.domain.ext/test.git <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>301 Moved Permanently</title> </head><body> <h1>Moved Permanently</h1> <p>The document has moved <a href="https://git.domain.ext/git/test.git">here</a>.</p> [..]
谢谢你的帮助。
事实certificate,这始终是一个mod_rewrite错误:-)
为了使工作,我在我的.htaccess中使用以下:
<IfModule mod_rewrite.c> Options -MultiViews RewriteEngine On RewriteCond %{REQUEST_URI} ^(.*)\.git RewriteRule ^(.*)\.git /git/%{REQUEST_URI} [L] RewriteRule (.*) /gitlist/ [R,L] </IfModule>
问题出在以前的RewriteRule ^(.*)\.git /git/$1.git [R=301,L] ,这是产生404错误。 奇怪的是,我可以发现他们只用 – curl的动词。
据我所知,作为客户端的git不处理redirect。 是否有任何理由,你想重写发生redirect,而不是沉默重写(即没有R=302选项)?