hgwebdir.cgi and clean URLs

Ted Pavlic ted at tedpavlic.com
Thu May 29 13:17:40 UTC 2008


Some of this thread was the result of my confusion.

I was using both hgwebdir and hgweb at the same time, partially because 
I didn't understand that hgwebdir could serve everything itself.

Many of the problems I was having with the standard configuration 
stemmed from me not having all of my ErrorDocuments defined. That was 
causing pushes to fail (because I protect them with HTTP 
authentication). Now everything works, and I don't see any script names 
in my URL. Additionally, any old-style URLs are automatically redirected 
to the correct new-style URL.


On my repo dirs that are served as "http://hg.domain.com/", I have to:

*) Set baseurl to nothing

*) Make sure all ErrorDocuments exist (in particular, 401.shtml)

*) Use the following in my .htaccess. The first two paragraphs are just 
meant to redirect any old-style requests to the new-style format. The 
last paragraph (for me) is necessary.

% =====
#### Mercurial specific stuff

# Make sure any references to /index.cgi are stripped
RewriteCond %{THE_REQUEST} \s/index.cgi
RewriteRule index.cgi/(.*) http://hg.domain.com/$1 [R=permanent,L]

# Next, make sure any references to /repo/index.cgi are stripped
RewriteCond %{THE_REQUEST} \s/([^\/]+)/index.cgi(|/.*)\s
RewriteRule ^.* http://hg.domain.com/%1%2 [R=permanent,L]

# Finally, behind the scenes use index.cgi to serve repos
RewriteRule ^$ index.cgi  [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} !\s/index.cgi
RewriteRule (.*) index.cgi/$1  [QSA,L]
% =====


On my repo dirs that are served as "http://blah/hg/", I have to

*) Set baseurl to /hg

*) Make sure all ErrorDocuments exist (in particular, 401.shtml)

*) Use the following in my .htaccess. It's very similar to the above.

% =====
RewriteBase /hg

# Make sure any references to /index.cgi are stripped
RewriteCond %{THE_REQUEST} \s/hg/index.cgi
RewriteRule ^index.cgi/(.*) http://domain.org/hg/$1 [R=permanent,L]

# Next, make sure any references to /repo/index.cgi are stripped
RewriteCond %{THE_REQUEST} \s/hg/([^\/]+)/index.cgi(|/.*)\s
RewriteRule ^.* http://domain.org/hg/%1%2 [R=permanent,L]

# Finally, behind the scenes use index.cgi to serve repos
RewriteRule ^$ index.cgi  [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.cgi/$1  [QSA,L]
% =====


-- 
Ted Pavlic <ted at tedpavlic.com>



More information about the Mercurial mailing list