Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a little problem.

I want to be able to use a location such as git.my-domain.org/repo-a to set an environment that is used in git.my-domain.org/ as /repo-a is changed to / using a rewrite rule (which I must use?)

<VirtualHost *:80>
    ServerName git.my-domain.org
    DocumentRoot /usr/share/gitweb

    RewriteEngine On

    <Location /repo-a>
        RewriteRule /repo-a(.*) /$1 [PT]
        SetEnv GITWEB_CONFIG "/var/lib/gitolite/repositories/repo-a.git/gitweb/gitweb_config.perl"
    </Location>

    <Directory />
        AllowOverride All
        Options +FollowSymLinks +ExecCGI
        Order allow,deny
        Allow from all
        DirectoryIndex gitweb.cgi
        AddHandler cgi-script .cgi
    </Directory>
</VirtualHost>

I need to use a rewrite rule because /usr/share/gitweb/repo-a does not exist (or do I?), and I don't have any intention of creating any directories there. What I want is to use SetEnv GITWEB_CONFIG from /daily-backups and use it under /. But it seems that it isn't set, I've also tried using SetEnvIf with no success.

SetEnvIf Request_URI ".*repo-a" GITWEB_CONFIG "/var/lib/gitolite/repositories/repo-a.git/gitweb/gitweb_config.perl"

There is probably an automated way to use a RewriteRule together with SetEnv so that I don't have to create a new for another repository? For example:

SetEnvIf Request_URI ".*repo-a" GITWEB_CONFIG "/var/.../$1.git/gitweb/gitweb_config.perl"

I know I can symlink directories and using /var/lib/.../repo-a.git/gitweb/ as a DocumentRoot instead, but I'd rather avoid this as it would increase the number of .conf files (or be very cluttered).

Question summary

  1. Do I need a rewrite rule because the directory doesn't exist?
  2. How do I pass an environment variable to another "location"?
  3. Is there a way to simplify SetEnvIf or SetEnv to make use of the URI?
share|improve this question

migrated from stackoverflow.com Oct 2 '12 at 10:27

This question came from our site for professional and enthusiast programmers.

1 Answer 1

up vote 0 down vote accepted

You should be able to do:

<VirtualHost *:80>
    ServerName git.my-domain.org
    DocumentRoot /usr/share/gitweb

    RewriteEngine On
    RewriteRule /(repo-?) / [E=GITWEB_CONFIG:/var/lib/gitolite/repositories/$1.git/gitweb/gitweb_config.perl,PT]

    <Directory />
        AllowOverride All
        Options +FollowSymLinks +ExecCGI
        Order allow,deny
        Allow from all
        DirectoryIndex gitweb.cgi
        AddHandler cgi-script .cgi
     </Directory>
</VirtualHost>

This regex only supports repo-a, repo-1 etc. You can widen it but be careful not to swallow too much with .* but depends on how the CGI works.

share|improve this answer
    
Thanks for the help. With your help I was able to add any name of the repository, so that I don't need every repository to start with repo-. As you mentioned .* was a bit troublesome but I figured out how to solve it. RewriteEngine On RewriteRule ^/(.*)/$ - [E=GITWEB_CONFIG:/var/lib/gitolite/repositories/$1/gitweb/gitweb_config.perl] RewriteRule ^/.*/(static/.*)$ /$1 [L] RewriteRule ^/.*/(gitweb\.cgi) /$1 [L] RewriteRule ^/.+$ / –  Senth Nov 13 '12 at 11:32
    
Excellent, I'm glad it worked :) You can show your appreciation with an upvote and accepting my answer :) meta.stackexchange.com/questions/5234/… –  Alastair McCormack Nov 13 '12 at 11:46
    
I would like to upvote you, but I need 15 reputation to vote :/ I'll go through my questions again once I get 15 reputation, although it might take a while. –  Senth Nov 13 '12 at 11:53
    
hehe, don't worry. Thanks for the accept :) –  Alastair McCormack Nov 13 '12 at 11:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.