[英]mod_rewrite all non-files queries in public folder to ../index.php
我有以下文件夾邏輯:
.htaccess
index.php
composer.json
(etc. with all processing files)
public/
.htaccess
design/
files/
(etc. with all static files)
在.htaccess中都包含以下內容:
(.htaccess:)
RewriteEngine on
RewriteRule ^(.*)$ public/$1 [L]
(public/.htaccess)
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
當在MAMP上進行開發並且在生產中不需要時,第一個.htaccess很有用,因為大多數網站直接為公用文件夾提供服務。
提出此請求的原因,而不是使用include '../index.php';
的public/index.php
文件include '../index.php';
例如,Slim使用$_SERVER['PHP_SELF']
,它將通過強制/ public進入URL來中斷路由。 解決此問題的一種骯臟方法是更改vendor / slim / slim文件夾中的文件,這應該是一個相對較大的忘記。
(在寫問題時,我最終發現了一個我想分享的舒適解決方案)
(.htaccess)
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !index.php
RewriteRule ^(.*)$ public/$1 [L]
(public/.htaccess)
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ ../index.php/$1 [L,QSA]
在開發中
在生產中,僅執行第二步和第三步。
這樣,動態文件與靜態文件嚴格分開。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.