如何在Apache2.4中使用DAV和DirectoryIndex?
在我的apache配置中,我有一个如下配置的虚拟主机:如何在Apache2.4中使用DAV和DirectoryIndex?,apache,webdav,Apache,Webdav,在我的apache配置中,我有一个如下配置的虚拟主机: Alias /mediamanager /storage/files/mediamanager <Directory /storage/files/mediamanager> DirectoryIndex /mediaManagerIndex.php DAV On # ... And some authentication directives ... # </Directory> Alias/medi
Alias /mediamanager /storage/files/mediamanager
<Directory /storage/files/mediamanager>
DirectoryIndex /mediaManagerIndex.php
DAV On
# ... And some authentication directives ... #
</Directory>
Alias/mediamanager/storage/files/mediamanager
DirectoryIndex/mediaManagerIndex.php
达文
# ... 还有一些认证指令#
其思想是,有人可以通过WebDAV客户端和简单的web浏览器访问这些文件,在这种情况下,一些漂亮的目录视图是由PHP脚本生成的
这在Apache2.2中工作得很好,但最近我升级到Apache2.4,现在它坏了。我高度怀疑自己已经2岁了,看不到治疗方法。拟添加的解决方法:
<Limit PROPFIND>
DirectoryIndex never-encounterable-file-name.html
</Limit>
DirectoryIndex never-Encounable-file-name.html
不适合我。可能是因为我仍然想要一个目录索引。如果我删除我的DirectoryIndex
目录,WebDAV将再次工作(此目录中不存在index.html或类似文件),但我当然失去了将我的PHP文件用作目录索引的能力。我试图在
中指定我的DirectoryIndex,但没有效果
是否有任何方法可以使DAV和DirectoryIndex在Debian上的Apache 2.4中同时工作(如果可能的话,无需更改源代码和重新编译)?要解决此问题,请禁用WebDAV站点的目录索引 在您的sites available/site.conf文件中,将
DirectoryIndex disabled
添加到
声明中,如下所示:
<Directory /path/to/my/webdav/dir>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Require all granted
DirectoryIndex disabled
</Directory>
对我来说,以下配置解决了这两个问题:
- WebDAV又开始工作了
- 目录索引,如果用户使用web浏览器访问存储库
GET
请求方法
以下代码必须放在apache配置文件的服务器配置或虚拟主机上下文中
# Turn off (automatic) Directory-Indexing
DirectoryIndex disabled
RewriteEngine On
# Rewrite rules for the root directory
RewriteCond "%{REQUEST_METHOD}" "(GET)"
RewriteRule "^/$" "/index.php" [L]
# Rewrite rules for other sub-directories
RewriteCond "%{REQUEST_METHOD}" "(GET)"
# The following line checks, if the index.php file exists
RewriteCond "%{DOCUMENT_ROOT}/$1/index.php" "-f"
RewriteRule "^/(.*)/$" "/$1/index.php" [L]
别忘了重新加载Apache 这是我当前使用的解决方案,位于WebDav服务使用的目录树根目录下的
.htaccess
文件中。在这种情况下,我不使用PHP,只使用html文件,但它可以很容易地进行调整:
# Turn off automatic directory indexing
Options -Indexes
DirectoryIndex disabled
# Redirect directory requests to index.html, only for GET requests
RewriteEngine On
RewriteCond %{REQUEST_METHOD} "GET"
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ $1index.html [L]
为了始终启动请求的PHP文件,只需将最后一行的“index.html”替换为PHP文件名:
RewriteRule ^(.*)$ $1mediaManagerIndex.php [L]
这是一种无法解决您的特定问题的方法,但另一种可能解决此问题的方法是放弃apache的webdav处理程序,并切换到类似的方式,但如果用户使用普通的旧web浏览器访问存储库,我希望建立目录索引是的,这很好。只需通过其他端口配置WebDAV即可。所以port:80仍然会定期为站点提供目录索引。但是您可以通过另一个端口访问WebDAV,比如说443。然后在您的配置文件中,您将只向该端口的VirutalHost添加DirectoryIndex disabled。这可能是一个紧急解决方案,但它有一个缺陷,我需要告诉用户两个URL:一个用于WebDAV,另一个用于使用web浏览器。(这在概念上是不必要的,Apache2.2已经证明了这一点,而Apache2.2在实际工作中也是如此。)耶!明亮的作品用户明确表示他想让php处理
DirectoryIndex
。因此,禁用它不是一个选项。
RewriteRule ^(.*)$ $1mediaManagerIndex.php [L]