对网站访问者隐藏 *.inc.php

发布于 2024-09-02 01:21:54 字数 550 浏览 3 评论 0原文

我有一个脚本 myscript.inc.php 处理所有看起来像 /script-blah 的 url 我通过使用以下 .htaccess 来完成此操作

RewriteEngine On 
RewriteRule ^script-(.*)$ myscript.inc.php?s=$1 [QSA,L]

,但是用户也可以通过输入 /myscript.inc.php?s=blah 来访问它 我想阻止这种情况发生。我尝试过

<Files ~ "\.inc\.php$">
 Order deny,allow
 Deny from all
</Files>

RewriteCond %{REQUEST_URI} \.inc\.php
RewriteRule .* - [F,L,NS]

它们都阻止用户查看 /myscript.inc.php?s=blah 但它们也会导致 /script-blah 返回 403...

有没有办法正确执行此操作?

I have a script myscript.inc.php which handles all urls that look like /script-blah
I accomplish this by using following .htaccess

RewriteEngine On 
RewriteRule ^script-(.*)$ myscript.inc.php?s=$1 [QSA,L]

However users could also access it this way by typing /myscript.inc.php?s=blah
I would like to prevent that. I tried

<Files ~ "\.inc\.php$">
 Order deny,allow
 Deny from all
</Files>

and

RewriteCond %{REQUEST_URI} \.inc\.php
RewriteRule .* - [F,L,NS]

They both prevent users from viewing /myscript.inc.php?s=blah but they also cause /script-blah to return 403...

Is there a way to do this correctly?

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

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

发布评论

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

评论(3

淡淡的优雅 2024-09-09 01:21:54

我使用以下方法来保护我的 .inc.php 文件。将以下内容添加到您的 .htaccess:

#Prevent Users From Accessing .inc.php files in .htaccess
<Files ~ ".inc.php$">
Order allow,deny
Deny from all
</Files>

I use the following method to protect my .inc.php files. Add the following to your .htaccess:

#Prevent Users From Accessing .inc.php files in .htaccess
<Files ~ ".inc.php$">
Order allow,deny
Deny from all
</Files>
苍景流年 2024-09-09 01:21:54

您还可以尝试以下操作(许多开源包都这样做)

  • 在每个文件夹中放置一个空白的 index.html
  • 在 .htaccess 中使用此规则来阻止文件夹读取 Options -Indexes
  • 放置一行,在未找到全局常量的地方终止脚本

例如,这里是 Kohana 的 "丢弃无效访问”。它是所有 PHP 文件中的第一行。

<?php defined('SYSPATH') or die('No direct script access.'); ?>

这行基本上是说“如果没有通过定义 SYSPATH 的 index.php 包含,我们将中止脚本并显示一条友好的消息”

You could also try the following (a number of open source packages do this)

  • place a blank index.html in every folder
  • use this rule in .htaccess to block folder reading Options -Indexes
  • place a line that dies scripts where a global constant isn't found

For example, here is Kohana's "toss out invalid accesses". It is the first line in all PHP files.

<?php defined('SYSPATH') or die('No direct script access.'); ?>

This line basically says "if not included via index.php where SYSPATH is defined, we will abort script and show a friendly message"

烈酒灼喉 2024-09-09 01:21:54

如果它是文件名,您可以重定向

RewriteCond %{REQUEST_FILENAME} =-f 

You could redirect if it is a filename

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