如何在服务器中授予执行特定 php 文件的权限?

How to give access execute specific php file in server?

大家好,首先抱歉我的英语不好!我在 运行 在服务器中设置特定 php 文件时遇到问题,我想配置 .htaccess 以允许用户 运行 该文件。 示例:www.mywebsite.com/theme/test.php

这是我的 .htaccess 文件,当我检查我的网站时它 return“404 未找到”`

<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine on

##
## You may need to uncomment the following line for some hosting environments,
## if you have installed to a subdirectory, enter the name here also.
##
# RewriteBase /

##
## Black listed folders
##
RewriteRule ^bootstrap/.* index.php [L,NC]
RewriteRule ^config/.* index.php [L,NC]
RewriteRule ^vendor/.* index.php [L,NC]
RewriteRule ^storage/cms/.* index.php [L,NC]
RewriteRule ^storage/logs/.* index.php [L,NC]
RewriteRule ^storage/framework/.* index.php [L,NC]
RewriteRule ^storage/temp/protected/.* index.php [L,NC]
RewriteRule ^storage/app/uploads/protected/.* index.php [L,NC]

##
## White listed folders
##
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} !/.well-known/*
RewriteCond %{REQUEST_FILENAME} !/storage/app/uploads/.*
RewriteCond %{REQUEST_FILENAME} !/storage/app/media/.*
RewriteCond %{REQUEST_FILENAME} !/storage/temp/public/.*
RewriteCond %{REQUEST_FILENAME} !/themes/.*/(assets|resources)/.*
RewriteCond %{REQUEST_FILENAME} !/plugins/.*/(assets|resources)/.*
RewriteCond %{REQUEST_FILENAME} !/modules/.*/(assets|resources)/.*
RewriteRule !^index.php index.php [L,NC]


##
## Block all PHP files, except index
##
 RewriteCond %{REQUEST_FILENAME} -f
 RewriteCond %{REQUEST_FILENAME} \.php$
 RewriteRule !^index.php index.php  [L,NC]

##
## Standard routes
##

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^ index.php [L]

` 有什么办法可以解决这个问题吗?

兄弟,也许你可以试试这个:

RewriteRule /Route/to/Your.php

您的问题发生是因为您拒绝了所有文件。php

幸运的是。

您的问题是标记为 "Block all PHP files, except index" 的规则会将对 PHP 文件的所有请求路由到索引文件。这里有两种方法可以解决这个问题。

简单的一次性解决方案

您可以在任何其他 RewriteRule 行之前简单地添加此规则:

RewriteRule ^theme/test\.php - [L,NC]

更灵活的解决方案

下面的想法采用不同的方法并适用于您现有的白名单规则。如果您要处理多个模式或比单个文件更复杂的问题,这可能会更好。

对于您的 "white listed folders" 规则,添加条件

RewriteCond %{REQUEST_FILENAME} !/theme/test\.php

所以方块变成了

##
## White listed folders
##
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} !/.well-known/*
RewriteCond %{REQUEST_FILENAME} !/storage/app/uploads/.*
RewriteCond %{REQUEST_FILENAME} !/storage/app/media/.*
RewriteCond %{REQUEST_FILENAME} !/storage/temp/public/.*
RewriteCond %{REQUEST_FILENAME} !/theme/test\.php
RewriteCond %{REQUEST_FILENAME} !/themes/.*/(assets|resources)/.*
RewriteCond %{REQUEST_FILENAME} !/plugins/.*/(assets|resources)/.*
RewriteCond %{REQUEST_FILENAME} !/modules/.*/(assets|resources)/.*
RewriteRule !^index.php index.php [L,NC]

否则,标记为 "Block all PHP files, except index" 的规则将路由到索引文件。