拒绝直接访问文件夹,并通过htaccess文件文件夹、直接、文件、htaccess

2023-09-02 00:19:10 作者:百事可甜

下面是该方案:

有一个在根文件夹中的的index.php 文件 在一些文件中包含的index.php 这是在包括文件夹。 1的其他文件( submit.php )是为形式的根文件夹提交操作。 There is a index.php file in root folder some files are included in index.php which are in the includes folder. 1 other file (submit.php) is in the root folder for form submit action.

我想通过htaccess的限制,将文件直接用户接入包括文件夹。也为 submit.php 。但是,包括将适用于的index.php 文件。 就像,如果用户键入 www.domain.com/includes/somepage.php ,它会限制它(可能是重定向到一个错误页)。

I want to restrict direct user access to the files in includes folder by htaccess. also for submit.php. But include will work for index.php file. Like, if user types www.domain.com/includes/somepage.php, it will restrict it (may be redirect to a error page).

推荐答案

我只想移动包括文件夹出网页根的,但如果你想阻止直接进入整个包括文件夹,你可以把一个的.htaccess 文件,该文件仅包含该文件夹中:

I would just move the includes folder out of the web-root, but if you want to block direct access to the whole includes folder, you can put a .htaccess file in that folder that contains just:

deny from all

这样,你就无法打开该文件夹中的所有文件,但可以将它们包含在PHP中没有任何问题。

That way you cannot open any file from that folder, but you can include them in php without any problems.