重写URL以匹配Locationmatch

时间:2013-02-27 20:07:04

标签: apache rewrite

我需要一些重写帮助。

需要应用两个规则: 1.将RewriteCond基于HTTP_USER_AGENT 2.添加URL的路径以匹配LocationMatch

我现在正在打破的是什么:

RewriteCond %{HTTP_USER_AGENT} ^git
RewriteRule ^(.*)$ /git/$1 [L]

删除RewriteRule并立即查询路径工作正常,但运行此规则会导致apache“无法找到文件”。

匹配是一个LocationMatch <LocationMatch "/git/">,所以我不确定RewriteRule是否可以指向它?

完整配置:

<VirtualHost *:80>
DocumentRoot /home/subgit/repos

    <Directory /home/subgit/repos>
        Options       None
        AllowOverride none
        Order         allow,deny
        Allow         from all
    </Directory>

CustomLog /home/subgit/logs/access_log combined
SuexecUserGroup subgit subgit

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^git
RewriteRule ^(.*)$ /git/$1 [L]

RewriteCond %{QUERY_STRING} service=git-receive-pack [OR,NC]
RewriteCond %{REQUEST_URI} ^/git/.*/git-receive-pack$ [NC]
RewriteRule .* - [E=AUTHREQUIRED:yes]

ScriptAlias /git/ /home/subgit/bin/gitolite-suexec-wrapper.sh/

 <LocationMatch "/git/">
    Order Allow,Deny
    Deny from env=AUTHREQUIRED
    Allow from all
    Satisfy Any
    AuthType Basic
    AuthName "subgit"
    AuthBasicProvider file
    AuthUserFile /home/subgit/etc/subgit
    Require valid-user
  </LocationMatch>
</VirtualHost>

由于

1 个答案:

答案 0 :(得分:4)

解决方案是使用[PT]而不是[L]。