RewriteEngine on

# commit ID
RewriteCond %{QUERY_STRING} (^|&)id=([^&]+)($|&)
RewriteRule ^/cgit/([-._+a-zA-Z0-9/]+)\.git/commit/?$ /$1/c/%2? [R,L]

# plain file at commit ID
RewriteCond %{QUERY_STRING} (^|&)id=([^&]+)($|&)
RewriteRule ^/cgit/([-._+a-zA-Z0-9/]+)\.git/plain/(.*) /$1/raw/%2/f/$2? [R,L]

# plain file at ref
RewriteCond %{QUERY_STRING} (^|&)h=([^&]+)($|&)
RewriteRule ^/cgit/([-._+a-zA-Z0-9/]+)\.git/plain/(.*) /$1/raw/%2/f/$2? [R,L]

# plain file at HEAD
RewriteRule ^/cgit/([-._+a-zA-Z0-9/]+)\.git/plain/(.*) /$1/raw/HEAD/f/$2? [R,L]

# tree at HEAD
RewriteRule ^/cgit/([-._+a-zA-Z0-9/]+)\.git/tree/(.*) /$1/blob/HEAD/f/$2 [R,L]

# main project page
RewriteRule ^/cgit/([-._+a-zA-Z0-9/]+)\.git/?$ /$1? [R,L]
