如何禁用将尾部斜杠添加到 Apache 中的目录名称的 301 重定向
Apache 2.2.20 自动将所有指向目录且没有尾部斜杠的请求重定向到带有尾部斜杠的相同 URL,如下所示:
The Apache 2.2.20 automaticaly redirects all requests which are points to directories and has no trailing slash to the same URL with trailing slash, like shown below:
GET /some/path/to/dir HTTP/1.1
Host: www.some.org
...
301 Moved permanently
Location: http://www.some.org/some/path/to/dir/
在所有情况下,这是一种很好的行为,但我需要为一个特殊文件夹(不是全部)关闭此功能,但我无法找到.
In all cases it is a fine behavior, but I need to turn off this feature for one special folder (not for all), and can't find were I can do it.
搜索重写"规则一无所获——只有指令 LoadModule mod_rewrite.so.此外,目录树中的目录服务器中没有 .htaccess 文件.是否还有其他指令可以实现?
Searching for 'Rewrite' rules tells founds nothing - only directive LoadModule mod_rewrite.so. Also, there is no .htaccess files in directories server in directory tree. Is there any other directives that make thing?
UPD1 我尝试使用下一个配置通过 HTTP 设置 SVN:
UPD1 I try to set up SVN trough HTTP with next config:
LoadModule dav_svn_module /opt/libexec/mod_dav_svn.so
LoadModule authz_svn_module /opt/libexec/mod_authz_svn.so
NameVirtualHost *:8000
<VirtualHost *:8000>
ServerAdmin admin@some.host.org
ServerName some.host.org
DocumentRoot /path/to/wwwroot
DAVLockDB /opt/var/lock/davlock/svndavlockdb
<Directory /path/to/wwwroot>
Options FollowSymLinks Indexes
# #AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Directory /path/to/wwwroot/svn>
Options FollowSymLinks Indexes
AllowOverride None
Order allow,deny
Allow from all
</Directory>
CustomLog /path/to/wwwroot/log/access_log.txt combined
ErrorLog /path/to/wwwroot/log/error_log.txt
<Location /svn>
#AllowOverride None
#RewriteEngine Off
#RewriteOptions AllowNoSlash
DirectorySlash Off
DAV svn
SVNParentPath /path/to/wwwroot/svn
# SVNListParentPath on
AuthType Basic
AuthName "Subversion Repository"
AuthBasicAuthoritative Off
AuthUserFile /path/to/wwwroot/svn/.htauthfile
<Limit GET OPTIONS REPORT PUT POST DELETE PROPFIND PROPPATCH MKCOL COPY MOVE LOCK UNLOCK>
Require valid-user
</Limit>
</Location>
</VirtualHost>
UPD2 似乎DirectorySlash Off"指令仅适用于some.host.org/svn"而不适用于some.host.org/svn/repo1",some.host.org/svn/repo2" 等 - 子目录不继承此选项.
UPD2 It seems that the "DirectorySlash Off" directive works only for "some.host.org/svn" and not works for "some.host.org/svn/repo1", "some.host.org/svn/repo2" etc - child directories not inherit this option.
UPD3 我尝试将以下几行添加到配置中,但结果相同 - DirectorySlash Off"仅适用于/svn"而不适用于孩子.
UPD3 I try to add the following lines into config, but result is same - "DirectorySlash Off" work only for "/svn" and not for childs.
<LocationMatch "/svn/.*">
DirectorySlash Off
</LocationMatch>
已解决问题解决了.这是我的错误 - 我将 SVN 存储库根目录放在 DocumentRoot 文件夹下,所以 apache 和 web_dav 无法理解,必须由谁来处理请求.这至少适用于 TortoiseSVN 客户端.
SOLVED Problem solved. This is a my mistake - I placed SVN repository root under DocumentRoot folder, so apache and web_dav can't understand, who must handle request. This applies to TortoiseSVN client at least.
来自 SVN 开发者的评论:
Comments from SVN developers:
这意味着您的 httpd.conf 配置错误.通常,当您将 Subversion 虚拟位置"定义为同时存在于两个不同范围内时,会发生此错误.
It means your httpd.conf is misconfigured. Usually this error happens when you've defined the Subversion virtual "location" to exist within two different scopes at the same time.
例如,如果您已将存储库导出为 ,但您还将 DocumentRoot 设置为/www,那么您就有麻烦了.当请求/www/foo/bar 时,apache 不知道是否在 DocumentRoot 中找到名为/foo/bar 的真实文件,或者是否要求 mod_dav_svn 从/www/foo 获取文件/bar存储库.通常前一种情况会获胜,因此会出现永久移动"错误.
For example, if you've exported a repository as , but you've also set your DocumentRoot to be /www, then you're in trouble. When the request comes in for /www/foo/bar, apache doesn't know whether to find a real file named /foo/bar within your DocumentRoot, or whether to ask mod_dav_svn to fetch a file /bar from the /www/foo repository. Usually the former case wins, and hence the "Moved Permanently" error.
解决方案是确保您的存储库不会重叠或位于已作为普通网络共享导出的任何区域内.
The solution is to make sure your repository does not overlap or live within any areas already exported as normal web shares.
您也可能在 Web 根目录中有一个与您的存储库 URL 同名的对象.例如,假设您的 Web 服务器的文档根目录是/var/www,而您的 Subversion 存储库位于/home/svn/repo.然后,您将 Apache 配置为在 http://local.host/myrepo 处为存储库提供服务.如果您随后创建目录/var/www/myrepo/这将导致发生 301 错误.
It's also possible that you have an object in the web root which has the same name as your repository URL. For example, imagine your web server's document root is /var/www and your Subversion repository is located at /home/svn/repo. You then configure Apache to serve the repository at http://local.host/myrepo. If you then create the directory /var/www/myrepo/ this will cause a 301 error to occur.
使用 mod_dir 的 DirectorySlash 指令.来自文档的示例:
Use mod_dir's DirectorySlash directive. Example from docs:
# see security warning in docs
<Location /some/path>
DirectorySlash Off
SetHandler some-handler
</Location>