我将所有的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' :) –