[英]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.