分享

利用SVNListParentPath增加http浏览仓库根目录的功能

 rookie 2010-02-26
使用SVNParentPath的时候,直接访问ParentPath的时候,总是得到以下错误提示:
403 Forbidden
Forbidden
You don't have permission to access /svn/ on this server.
下面的办法可以搞定它:
一、首先,Subversion1.3及以后版本支持SVNListParentPath ON,之前的版本只能使用PHP自己做。
二、Location 设置中最后要加上/,应该是<Location /svn/>而不是<Location /svn>否则可能不能访问。
三、通过“http://localhost/svn/” 来访问仓库列表,如果想让“http://localhost/svn”也起作用的话,需要在</Location>的后面增加重定向的设置:RedirectMatch ^(/svn)$ $1/  ,当然也可以采用RewriteEngine之类的办法。
四、修改后的httpd.conf的对应部分如下:
<Location /svn/>
    DAV svn
    SVNListParentPath on
    SVNParentPath e:/svn
#    SSLRequireSSL                 #指定该目录只能通过SSL操作
#    SVNPathAuthz off
    AuthzSVNAccessFile e:/ca/access/file
   
    #try anonymous access first,resort to real
    #authentication if necessary.
    #Satisfy Any
    Require valid-user
   
    #how to authenticate a user
    AuthType Basic
    AuthName "服务器需要身份验证:"
#    AuthUserFile e:/ca/access/svn-auth-file
  AuthMySQLHost localhost
  AuthMySQLUser Bugfree
  AuthMySQLPassword mandarin
  AuthMySQLDB BugFree
  AuthMySQLUserTable BugUser
  AuthMySQLNameField UserName
  AuthMySQLPasswordField UserPassword
#  AuthMySQLMD5Passwords On
  AuthMySQLPwEncryption md5
 
</Location>
RedirectMatch ^(/svn)$ $1/
五、如果使用Subversion1.3以前的版本,或需要定制列表显示的话,可以自己写php脚本来控制仓库列表的显示,TotoiseSVN的帮助文件中有详细描述:
<html>
<head>
<title>Subversion Repositories</title>
</head>
<body>
<h2>Subversion Repositories</h2>
<p>
<?php
    $svnparentpath = "C:/svn";
    $svnparenturl = "/svn";
    $dh = opendir( $svnparentpath );
    if( $dh ) {
        while( $dir = readdir( $dh ) ) {
            $svndir = $svnparentpath . "/" . $dir;
            $svndbdir = $svndir . "/db";
            $svnfstypefile = $svndbdir . "/fs-type";
            if( is_dir( $svndir ) && is_dir( $svndbdir ) ) {
                echo "<a href=\"" . $svnparenturl . "/" .
                        $dir . "\">" . $dir . "</a>\n";
                if( file_exists( $svnfstypefile ) ) {
                    $handle = fopen ("$svnfstypefile", "r");
                    $buffer = fgets($handle, 4096);
                    fclose( $handle );
                    $buffer = chop( $buffer );
                    if( strcmp( $buffer, "fsfs" )==0 ) {
                        echo " (FSFS) <br />\n";
                    } else {
                        echo " (BDB) <br />\n";
                    }
                } else {
                    echo " (BDB) <br />\n";
                }
            }
        }
        closedir( $dh );
    }
?>
</p>
</body>
</html>
Save the lines above to a file svn_index.php and store that file in your web root folder. Next you have to tell Apache to show that page instead of the error:
Uncomment (remove the '#' char) from the following line in your Apache config file:
#LoadModule rewrite_module modules/mod_rewrite.so
Add the following lines just below your <Location> block where you define your Subversion stuff:
    RewriteEngine on
    RewriteRule ^/svn$ /svn_index.php [PT]
    RewriteRule ^/svn/$ /svn_index.php [PT]
    RewriteRule ^/svn/index.html$ /svn_index.php [PT] 六、URL重写的若干非mod_rewrite方法 原文出处:http://www. 作者:HonestQiao  发表于:2005-09-23 23:40:16 1、Alias:重写到本地路径
可以使用Alias把一个指定的Url重写到某一固定的本地路径
Alias /test/ /home/www/test/
那么对http://..../test/ 将对应了/home/www/test/
注意:Alias必须是一一对应的,/test/将不对/test起作用。
2、AliasMatch:重写到本地路径
与Alias类似,但是可以使用正则表达式
AliasMatch ^/test(.*) /home/www/test$1
3、Redirect :重写到网址
Redirect /test/ http://....../test2/
4、RedirectMatch :重写到网址
与Redirect类似,但是可以使用正则表达式
Redirect /test(.*) http://....../test2$1
在不需要很复杂的URL重写时,完全可以使用以上的几条指令来进行。

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/islq/archive/2006/04/17/666911.aspx

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多