Htaccess 添加允许 php 文件
Htaccess add allowed php file
我的 htaccess 文件中有以下代码:
##
## Block all PHP files, except index
##
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteRule !^index.php index.php [L,NC]
我需要允许执行一个特定的 php 文件,该文件可能位于多个不同的目录中。是否可以修改以上内容以允许访问 index.php(在根目录中)以及任何名为 upload.php 的文件,而不管它位于何处?
提前致谢。
您可以在 RewriteRule
中修改否定模式以跳过更多文件,如下所示:
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteRule !(^index\.php|(^|/)upload\.php)$ index.php [L,NC]
因为我们在 upload.php
之前匹配锚点 ^
或 /
,所以我们让它匹配任何位置。
我的 htaccess 文件中有以下代码:
##
## Block all PHP files, except index
##
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteRule !^index.php index.php [L,NC]
我需要允许执行一个特定的 php 文件,该文件可能位于多个不同的目录中。是否可以修改以上内容以允许访问 index.php(在根目录中)以及任何名为 upload.php 的文件,而不管它位于何处?
提前致谢。
您可以在 RewriteRule
中修改否定模式以跳过更多文件,如下所示:
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteRule !(^index\.php|(^|/)upload\.php)$ index.php [L,NC]
因为我们在 upload.php
之前匹配锚点 ^
或 /
,所以我们让它匹配任何位置。