有什么办法可以解决吗

问题描述 投票:0回答:1

我想为我的

.php files
添加一些隐私,因为我正在使用包含 .php 文件的联系表单。我想确保即使有人尝试访问这些文件也无法查看。我相信
.htaccess
文件的
.php
权限可能是解决方案。这是我当前正在使用的
.htaccess
文件:

php_value mbstring.http_input auto
php_value date.timezone America/New_York
Options +MultiViews
RewriteEngine on

For .php & .html URL’s:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.php [NC,L]
RewriteRule ^([^.]+)$ $1.html [NC,L]
html css .htaccess security
1个回答
0
投票

在此配置中,

<FilesMatch>
指令用于关注所有具有 .php 扩展名的文件。然后
RewriteCond
检查请求是否属于 .php 文件。如果是,
RewriteRule
会采取行动,发送 403 禁止错误 ([F]) 并终止重写过程 ([L])。

配置:

php_value mbstring.http_input auto
php_value date.timezone America/New_York
Options +MultiViews
RewriteEngine on

# For .php & .html URL’s:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.php [NC,L]
RewriteRule ^([^.]+)$ $1.html [NC,L]

# Prevent direct access to PHP files
<FilesMatch "\.php$">
    # Replace 'yourdomain.com' with your own domain.
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.php\ HTTP/
    RewriteRule .* - [F,L]
</FilesMatch>
© www.soinside.com 2019 - 2024. All rights reserved.