我將所有的url請求指向前端控制器。 url請求看起來像example.com/controller/action/etc
。問題是,使用程序內的相關URL。如果url請求中只有一個斜槓,這可以正常工作,但如果有多個斜槓,則相對URL將被破壞。使用「乾淨的URL」時使用相對URL?
在位置example.com/controller
,相對網址other-controller
正常工作,將用戶帶到example.com/other-controller
。
在位置example.com/controller/action
,相對地址other-controller
不起作用,使用戶example.com/controller/other-controller
。
有關如何解決此問題的任何建議?希望我可以做到這一點,而無需使用絕對路徑或一些網址生成代碼,每次我想在應用程序中創建一個網址。
如果它的事項,我目前使用此代碼的.htaccess重定向進來的請求到前端控制器:
# Point all to index.php except existing files
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
縮小的網址會很好。唯一的問題是,如果我將應用程序保存在任何一個子文件夾中......'example.com/someapp/controller/action' – dqhendricks
這是真的,但您也可以使用'mod_rewrite' :) –