简体   繁体   English

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

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

Hello guys first of all sorry for my bad english!. 大家好,首先抱歉我的英语不好! I'm having trouble with running a specific php file in server and I want to configure .htaccess to allow user to run the file. 我在服务器中运行特定的php文件时遇到问题,我想配置.htaccess以允许用户运行该文件。 example: www.mywebsite.com/theme/test.php 例如:www.mywebsite.com/theme/test.php

this is my .htaccess file and when I check my site it return "404 Not Found" ` 这是我的.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]

` Is there any way to fix the problem ? “有什么办法可以解决这个问题吗?

Your problem is that the rule labeled "Block all PHP files, except index" will route all requests for PHP files to the index file. 您的问题是标记为“阻止所有PHP文件,索引除外”的规则将所有PHP文件请求路由到索引文件。 Here are two ways to fix this. 以下是解决此问题的两种方法。

Simple, One-Off Solution 简单的一次性解决方案

You can simply add this rule before any other RewriteRule lines: 您可以在任何其他RewriteRule行之前添加此规则:

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

More Flexible Solution 更灵活的解决方案

The idea below takes a different approach and works with your existing whitelisting rules. 下面的想法采用不同的方法,并与您现有的白名单规则一起使用。 This might be better if you are goi to have multiple patterns or something more complex than a single file to worry about. 如果您需要多个模式或比单个文件更复杂的东西担心,这可能会更好。

For your "white listed folders" rule, add the condition 对于“白名单文件夹”规则,请添加条件

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

So the block becomes 所以块变成了

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

Otherwise, the rule labeled "Block all PHP files, except index" will route to the index file. 否则,标记为“阻止所有PHP文件,索引除外”的规则将路由到索引文件。

Bro, maybe you can try with this: 兄弟,也许你可以试试这个:

RewriteRule /Route/to/Your.php

Your problem happens because you are denying all the files .php 您的问题发生是因为您拒绝所有文件.php

Lucky with that. 幸运的是。

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

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