如何在Core php中路由动态URL

  1. index.php
  2. cms-page.php

if Request ULR is
www.example.com/service or
www.example.com/about-us

than cms-page.php should be open

how do i route . what to write and where to write to get such result . Thanks .

In core php, you can do something like this to achieve.

//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');
}

In general Practice, Keep your url decoding and redirecting part in a seperate php file and then redirect them to router which should take approriate action. Please see the below structure.

URL DECODER -> ROUTER (takes to controller) -> CONTROLLER (determines view ) -> VIEW