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