0

我试图阻止使用 htaccess 直接访问我网站上除 index.php 之外的所有 php 文件。到目前为止,我已经有了以下代码,但是它仍然不能阻止表单直接访问 php 文件。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php?page=$1 [L]
</IfModule>

我的解决方案:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond $1 !^(index\.php|.*\.css|.*\.js|.*\.png|.*\.gif|.*\.jpg)
RewriteRule ^(.*)$ index.php?page=$1 [L]
</IfModule>
4

1 回答 1

0

那是因为这些行:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

如果请求的资源是文件或目录,您明确告诉重写模块不运行以下规则

但是,我同意最好将它们完全移出网络根目录。

于 2013-02-02T19:40:18.050 回答