2016-07-24 33 views
0
  1. 的index.php
  2. CMS-page.php文件

如果請求ULR是
www.example.com/service
WWW。 example.com/about-us

cms-page.php應該打開

我該如何處理e。寫什麼,寫什麼來獲得這樣的結果。謝謝 。如何路由動態URL在PHP核心

+0

在笨語法是以下(config.php中): $路線[ '(:任何)'] = 「ControllerClass/ControllerMethod/$ 1」; –

回答

0

在覈心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