How to create friendly URL in php?

后端 未结 8 1844
一整个雨季
一整个雨季 2020-11-21 11:06

Normally, the practice or very old way of displaying some profile page is like this:

www.domain.com/profile.php?u=12345

where u=12345

8条回答
  •  北恋
    北恋 (楼主)
    2020-11-21 11:56

    There are lots of different ways to do this. One way is to use the RewriteRule techniques mentioned earlier to mask query string values.

    One of the ways I really like is if you use the front controller pattern, you can also use urls like http://yoursite.com/index.php/path/to/your/page/here and parse the value of $_SERVER['REQUEST_URI'].

    You can easily extract the /path/to/your/page/here bit with the following bit of code:

    $route = substr($_SERVER['REQUEST_URI'], strlen($_SERVER['SCRIPT_NAME']));
    

    From there, you can parse it however you please, but for pete's sake make sure you sanitise it ;)

提交回复
热议问题