我有三個檔案夾——Model、Views 和 Controller——并且我已經將 index.php 檔案存盤在 Views 檔案夾中。我無法路由檔案。我在 .htaccess 檔案中嘗試了以下代碼
RewiteEngine On
RewiteCond %{REQUEST_FILENAME} !-f
ReWriteRule ^(.*)$ index.php
uj5u.com熱心網友回復:
假設您的專案結構如下所示:
Model
Controller
Views -> index.php
您可以.htaccess在根檔案夾中使用此檔案:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ view/ [L]
RewriteRule (.*) Views/$1 [L]
</IfModule>
這會將所有流量發送到Views檔案夾。
.htaccess檔案夾內還有另一個這個檔案Views:
<IfModule mod_rewrite.c>
Options -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
index.php這會發送帶有漂亮 URL 的所有流量拋出檔案。
提示:
但我建議更改您的結構,如下所示似乎更好:
public -> index.php #will include bootstrap.php
assets
.htacess
app --->> Model
Controller
View
Helper
bootstrap.php #contains autoload and includes
...
.htaccess
所以所有流量都會通過 throwpublic/index.php并且應用程式檔案夾和服務與公共和資產是分開的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/434000.html
