Created
June 25, 2013 04:49
-
-
Save skierpage/5856002 to your computer and use it in GitHub Desktop.
Apache mod_rewrite directives to change gitweb URLs to gitblit URLs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RewriteEngine on | |
# Rewrite old gerrit gitweb URLs to work with new git. | |
# Here are some sample URLs that need to continue to work | |
# https://gerrit.wikimedia.org/r/gitweb?p=mediawiki/extensions/Agora.git;hb=HEAD; | |
# https://gerrit.wikimedia.org/r/gitweb?p=mediawiki/core.git;a=blob_plain;f=languages/messages/MessagesEn.php;hb=HEAD | |
# https://gerrit.wikimedia.org/r/gitweb?p=mediawiki/extensions/examples.git;hb=HEAD;f=BoilerPlate/README; | |
# https://gerrit.wikimedia.org/r/gitweb?p=mediawiki/extensions/ArticleFeedback.git;hb=HEAD;f=modules/jquery.articleFeedback/images/star-new-down.png;a=raw; | |
# | |
# Notes | |
# 1. gitblit requires URL-encoding (%2F) of the slashes in the matched | |
# paths to project and file. The [B] option together with | |
# AllowEncodedSlashes does this; it also converts '.' in .git and .php | |
# to "%2e" , gitblit accepts this. (If this causes problems with other URLs | |
# you could use | |
# RewriteMap esc int:escape | |
# and ${esc:%1} for the paths, and probably have to add [noescape] option). | |
# 2. Append an empty query string (which mod_rewrite is smart enough to | |
# drop), otherwise the original query string is appended -- mod_rewrite | |
# lacks a DiscardQueryString option. | |
# 3. We can't have separate RewriteCond for p= and f= because the | |
# RewriteRule can only reference matches from the last RewriteCond. | |
# (You could use [N] to re-run the rewriting process after rewriting | |
# for each parameter ... agggh.) | |
# 4. To avoid complicated "p= at start or preceded with ;", stick ';' on front. | |
# 5. The semicolon-separated parameters p and f can be in any order, so look | |
# for p anywhere and add it back at the front. | |
# 6. gitweb parameters not handled: a=<some other action>, hb=<some | |
# commit>, and #l123 line number fragment. | |
AllowEncodedSlashes NoDecode | |
# Rewrite a gitweb project link (no file). | |
RewriteCond ;%{QUERY_STRING} !;f= | |
RewriteCond ;%{QUERY_STRING} ;p=([^;]*) | |
RewriteRule ^/r/gitweb$ https://git.wikimedia.org/summary/%1/HEAD? [R=301,L,B] | |
# Rewrite a gitweb file link (project and file, in any order). | |
RewriteCond ;%{QUERY_STRING} ;p=([^;]*) | |
RewriteCond ;p=%1;%{QUERY_STRING} ^;p=([^;]*).*;f=([^;]*) | |
RewriteRule ^/r/gitweb$ https://git.wikimedia.org/raw/%1/HEAD/%2? [R=301,L,B] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For Wikimedia's servers, but may be generally useful.