繁体   English   中英

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

[英]How to give access execute specific php file in server?

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

这是我的.htaccess文件,当我检查我的网站时,它会返回“404 Not Found”

<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]

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

您的问题是标记为“阻止所有PHP文件,索引除外”的规则将所有PHP文件请求路由到索引文件。 以下是解决此问题的两种方法。

简单的一次性解决方案

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

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

更灵活的解决方案

下面的想法采用不同的方法,并与您现有的白名单规则一起使用。 如果您需要多个模式或比单个文件更复杂的东西担心,这可能会更好。

对于“白名单文件夹”规则,请添加条件

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]

否则,标记为“阻止所有PHP文件,索引除外”的规则将路由到索引文件。

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

RewriteRule /Route/to/Your.php

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

幸运的是。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM