0
- 的index.php
- CMS-page.php文件
如果請求ULR是
www.example.com/service或
WWW。 example.com/about-us
比cms-page.php應該打開
我該如何處理e。寫什麼,寫什麼來獲得這樣的結果。謝謝 。如何路由動態URL在PHP核心
如果請求ULR是
www.example.com/service或
WWW。 example.com/about-us
比cms-page.php應該打開
我該如何處理e。寫什麼,寫什麼來獲得這樣的結果。謝謝 。如何路由動態URL在PHP核心
在覈心php中,你可以做這樣的事情來實現。
//get request url
$url = rawurldecode($_SERVER['REQUEST_URI']);
//match the request url with above urls.
if(preg_match('/service/', $url) || preg_match('/about-us/', $url)){
//open cms page.
include('cms-page.php');
}
的普遍做法,讓您的網址解碼和重定向部分在一個單獨的PHP文件,然後將其重定向到應該採取行動approriate路由器。 請參閱下面的結構。
URL DECODER -> ROUTER (takes to controller) -> CONTROLLER (determines view) -> VIEW
在笨語法是以下(config.php中): $路線[ '(:任何)'] = 「ControllerClass/ControllerMethod/$ 1」; –