簡體   English   中英

PHP MVC .htaccess重定向

[英]PHP MVC .htaccess Redirect

我想用PHP編寫MVC應用程序,並具有以下文件結構:

/
|-- 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(例如“ / something”)重定向到“ /public/index.php”,而不更改URI
  • 將文件URI(例如“ /css/screen.css”)重定向到“ /public/css/screen.css”,而不更改URI

什么不起作用:

  • 將目錄URI(例如“ / scripts”)重定向到“ /public/index.php”而不是“ / public / scripts”

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

解決方案是:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM