简体   繁体   English

我如何使用htaccess拒绝从URL直接访问服务器文件夹中的所有php文件和某些html文件?

[英]How can i deny direct access from url to all php file and some html in my server folder using htaccess?

I'm trying to hide all the php and some html file in my server folder only by direct call from url... particularly i need to hide the register.html (this file is for users registration), and other php file.. (these php files contain sensitive data for database connection). 我试图通过直接从url直接隐藏服务器文件夹中的所有php和一些html文件...特别是我需要隐藏register.html(此文件供用户注册)和其他php文件。 (这些php文件包含用于数据库连接的敏感数据)。 How can i do this?? 我怎样才能做到这一点?? Thanks for any help ;) 谢谢你的帮助 ;)

You can use this for register.html : 您可以将其用于register.html

<Files "register.html">
Order Allow,Deny
Deny from all
</Files>

and in the same way for other files. 并以相同的方式处理其他文件。

Create/edit the .htaccess file in the directory where the files are located. 在文件所在的目录中创建/编辑.htaccess文件。

For denying all direct access to all files in the directory , add this: 要拒绝直接访问目录中的所有文件 ,请添加以下内容:

Deny from all

For restricting only a specific file : 限制特定文件

<Files "register.html">
Order Allow,Deny
Deny from all
</Files>

For restricting specific file types , you need to edit the .htaccess file in the webroot folder. 要限制特定的文件类型 ,您需要在webroot文件夹中编辑.htaccess文件。 This rule will deny access to all .php and .html files in myFolder and its subdirectories.: 此规则将拒绝访问myFolder及其子目录中的所有.php.html文件:

RewriteRule ^myFolder/.*\.(php|html)$ - [F,L,NC]

More examples on denying access to file types: https://stackoverflow.com/a/20489058/6817376 有关拒绝访问文件类型的更多示例: https : //stackoverflow.com/a/20489058/6817376

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 拒绝通过htaccess直接访问文件夹和文件 - deny direct access to a folder and file by htaccess 如何使用PHP中的url保护我的图像和文件夹不被直接访问? - How to protect my image and file folder from direct access using url in PHP? 拒绝从直接网址访问文件夹 - Deny access to a folder from direct url 如何使用.htaccess停止使用Apache直接访问文件夹? - How can I stop direct access of a folder with Apache using .htaccess? 如何拒绝访问目录中的所有文件,但允许访问其他目录中的特定php文件呢? - How can I deny access to all files in directory but allow access from specific php file in other directory? 如何阻止 URL 直接访问文件夹中的所有文件,但仍允许用户下载? - How can I block direct URL access to all file in a folder, but still allow it to be downloaded by users? 如何拒绝访问 htaccess 中的请求 url? - How can i deny access to request url in htaccess? 拒绝直接访问文件夹或文件,但允许index.php访问它 - Deny direct access to a folder or file, but allow index.php to access it 如何拒绝直接访问目录,但允许通过php脚本访问目录? - How can I deny direct access to a directory, but allowing it from a php script? 如何使用 .htaccess 访问一个文件:拒绝所有人 - How to access one file with .htaccess : deny from all
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM