如何阻止对.html文件的直接访问? (.htaccess) [英] How to block direct access to .html files? (.htaccess)

查看:204
本文介绍了如何阻止对.html文件的直接访问? (.htaccess)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想阻止对多个文件的直接访问,但能够访问index.html

I want to block direct access to multiple files, but being able to access in index.html

例如:我想阻止对所有文件的访问在 http://www.mywebsite.com/pages 中,例如 contact.html about.html ...,并且只能由 index.html( http://www.mywebsite.com/

For example: I want to block access to all the files located in "http://www.mywebsite.com/pages" such as "contact.html" "about.html"... and only be accessed by "index.html" (http://www.mywebsite.com/)

,并在可能的情况下阻止对图像文件夹的访问( http://www.mywebsite.com/images ),但仍然可以使用 index.html中的图像

and if possible, to block access to images folder (http://www.mywebsite.com/images) but still being able to use the images in "index.html"

我要重定向到首页( index.html )或直接访问这些文件时发送404状态代码...我有一个404找不到页面,称为 notfound.html

I want to redirect to home page (index.html) or send a 404 status code when these files are directly accessed... I have a 404 not found page called "notfound.html"

文件:

index.html

页(在 index.html 中包含很少的用作链接的.html页面)
图片(包含 index.html 中使用的图片)

pages (contains few .html pages used as links in index.html) images (contains images used in index.html)

推荐答案

尝试以下操作:在index.html而不是notfound.html上重定向

Try this : redirect on index.html instead of notfound.html

RewriteEngine On

RewriteCond %{HTTP_REFERER} !^http://www.mywebsite.com/index.html
RewriteRule .*\.html$ index.html
RewriteCond %{HTTP_REFERER} ^http://www.mywebsite.com/index.html
RewriteRule (.*)\.html$ $1.html

在其他.htaccess中的图像目录中:

In images directory in other .htaccess :

options -indexes
ErrorDocument 403 http://www.mywebsite.com/index.html

但是您为什么想要去做这个? ;)

But why do you wish to do this? ;)

这篇关于如何阻止对.html文件的直接访问? (.htaccess)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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