如何防止目录访问并在php中显示禁止错误 [英] how to prevent directory access and show forbidden error in php

查看:24
本文介绍了如何防止目录访问并在php中显示禁止错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  1. I am new to .htaccess, i want to know how to use .htacces to prevent direct access via url of my folder e.g. localhost/mycart/images/ OR localhost/mycart/css should show forbidden message.

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

currently i've put index.php in every folder of my website and echo the messages is it good way to do it.

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

when i access my website like www.mycart/index.php/css or www.mycart/index.php/images it show website without images and css why and how to fix it?

推荐答案

我用过

# disable directory browsing
Options -Indexes

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

Conversely, to enable directory browsing, use the following directive:

# enable directory browsing
Options +Indexes

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

Likewise, this rule will prevent the server from listing directory contents:

# prevent folder listing
IndexIgnore *

最后,IndexIgnore 指令可用于防止显示选择的文件类型:

And, finally, the IndexIgnore directive may be used to prevent the display of select file types:

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

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

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

It also contains many other useful commands to be used in .htaccess for security and performance enhancement.

这篇关于如何防止目录访问并在php中显示禁止错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆