2017-04-20 109 views
0

我想用PHP編寫一個MVC應用程序,並具有以下文件結構:PHP MVC的.htaccess重定向

 
/
|-- application 
| | 
| ... 
| 
|-- public 
| |-- css 
| | |-- screen.css 
| | `-- print.css 
| |-- scripts 
| | `-- wlan.sh 
| |-- bugfixes 
| | `-- audiofix.sh 
| `-- index.php 
`-- .htaccess 

這是我的.htaccess文件:

RewriteEngine On 
RewriteBase /public 

RewriteCond %{REQUEST_URI} !^/public/ [NC] 
RewriteRule ^(.*)$ /public/$1 [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ /public/index.php [L] 

什麼工作:

  • 在不更改URI的情況下將虛擬URI(如'/ something')重定向到'/public/index.php'
  • 重定向文件URI,如 '/css/screen.css' 到 '/public/css/screen.css' 不改變URI

沒有什麼作品:

  • 重定向目錄URI,如「/腳本'to'/public/index.php'而不是'/ public/scripts'

我已經試過了一切。現在我需要幫助。

回答

0

的解決方案是:

RewriteEngine On 

# Stop processing if already in the /public directory 
RewriteRule ^public/ - [L] 

# Static resources if they exist 
RewriteCond %{DOCUMENT_ROOT}/public/$1 -f 
RewriteRule (.+) public/$1 [L] 

# Route all other requests 
RewriteRule (.*) public/index.php [L] 

感謝:https://stackoverflow.com/a/41516968/3699361