htaccess rewriteRule限制访问某一特定文件夹问题

发布于 2024-08-08 04:17:40 字数 1092 浏览 1 评论 0原文

我在限制文件夹 inc 时遇到问题。

它只是根目录中的 inc 文件夹,而不是层次结构中更高的 inc 文件夹

问题是:

  1. IE 将启动下载/打开对话框, p>

  2. FF 显示包含文件

我的图像文件夹没有这个问题,该文件夹也位于根目录中。

请问我可以用什么逻辑来防止这种情况发生?

Options +FollowSymlinks
RewriteEngine On
Options All -Indexes
IndexIgnore *
# RewriteRule ^inc($|/) - [R=403,L]
RewriteCond %{HTTP_REFERER} !^http://([-a-z0-9]+\.)?taxi-bel\.nl [NC]
RewriteRule \.(gif|png|jpg|css|js)$ - [F,NC,L]

#################################################### ##################################################

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

​############################################ RewriteCond %{HTTP_HOST} ^www.(.) [NC] RewriteRule ^(.)$ http://%1/$1 [R=301,NC,L]

编辑因为

我通过添加此规则解决了问题 DirectoryIndex index.php

将index.php放置在指向错误文件的inc文件夹中, - 或者您可以将其设置为错误页面本身 - 以及问题解决了!

I have problem with getting the folder inc restricted.

It is only the inc folder in the root directory and not the inc folders higher up the hierarchy

Problems are:

  1. IE will start a download/open dialog and

  2. FF displays an include file

I don´t have this problem with the images folder which is also in the root directory.

What logic could I use to prevent this, please?

Options +FollowSymlinks
RewriteEngine On
Options All -Indexes
IndexIgnore *
# RewriteRule ^inc($|/) - [R=403,L]
RewriteCond %{HTTP_REFERER} !^http://([-a-z0-9]+\.)?taxi-bel\.nl [NC]
RewriteRule \.(gif|png|jpg|css|js)$ - [F,NC,L]

#######################################################################

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

#######################################################################
RewriteCond %{HTTP_HOST} ^www.(.) [NC]
RewriteRule ^(.
)$ http://%1/$1 [R=301,NC,L]

Edit because

I solved the problem by adding this rule
DirectoryIndex index.php

and to place an index.php in the inc folder which points to an error file, - or you can make it the error page itself -, and problem solved!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

后来的我们 2024-08-15 04:17:40

您注释掉的规则可以做到这一点:

RewriteRule ^inc($|/) - [F,L]

And I'd宁愿发送 404 而不是 403。但这需要 Apache 2。

The rule you commented out can do that:

RewriteRule ^inc($|/) - [F,L]

And I would rather send a 404 than a 403. But this requires Apache 2.

二手情话 2024-08-15 04:17:40

如果您只想禁止通过网络服务器访问 inc 文件夹及其内容,您只需将 .htaccess 文件放入 inc 文件夹本身并禁止所有来自外部的访问。

Order deny, allow
deny from all

If you only want to disallow accessing the inc folder and its contents via the webserver ayou can simply put a .htaccess file in the inc folder itself and disallow all accesses from outside.

Order deny, allow
deny from all
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文