18
  1. 我是 .htaccess 的新手,我想知道如何使用 .htacces 来防止通过我的文件夹的 url 直接访问,例如 localhost/mycart/images/ 或 localhost/mycart/css 应该显示禁止消息。

  2. 目前我已经将 index.php 放在我网站的每个文件夹中,并回显消息是这样做的好方法。

  3. 当我访问我的网站时,如 www.mycart/index.php/css 或 www.mycart/index.php/images 它显示没有图像和 css 的网站为什么以及如何修复它?

4

3 回答 3

40

我用过

# disable directory browsing
Options -Indexes

相反,要启用目录浏览,请使用以下指令:

# enable directory browsing
Options +Indexes

同样,此规则将阻止服务器列出目录内容:

# prevent folder listing
IndexIgnore *

最后,可以使用 IndexIgnore 指令来阻止选择文件类型的显示:

# prevent display of select file types
IndexIgnore *.wmv *.mp4 *.avi *.etc

来自: 防止未经授权的目录浏览来自愚蠢的 HTACCESS 技巧

它还包含许多其他有用的命令,可用于.htaccess增强安全性和性能。

于 2012-05-27T09:48:59.963 回答
10

您可以简单地将以下内容添加到您的 .htaccess

# Don't listing directory
Options -Indexes
ErrorDocument 403 http://www.your-website-home-page.com/
# Follow symbolic links
Options +FollowSymLinks

# Default handler
DirectoryIndex index.php

这将在文件浏览时仅加载 index.php 文件。如果没有找到 index.php 文件,则发生 403 错误(访问受限)并将用户发送到主页

于 2012-05-27T12:20:29.310 回答
9

如果要拒绝访问所有文件:

deny from all

如果要禁用目录列表:

IndexIgnore *
于 2012-05-27T09:47:12.933 回答