URL mapping in PHP?

前端 未结 7 1306
孤街浪徒
孤街浪徒 2020-12-05 01:05

I come from a Java background and with any servlets-based technology, it\'s trivial to map a range of URLs (eg /reports/, /secure/.do) to a specified servlet. Now

7条回答
  •  死守一世寂寞
    2020-12-05 01:36

    A trick I use is the $ _ SERVER['PATH_INFO'] (I think you need Apache). This gets you all of the information after the PHP file extension.

    http://www.example.com/page.php/rest/url
    

    the $ _ SERVER['PATH_INFO'] will contain:

    "/rest/url"
    

    The page can then redirect, process some code or whatever based on that string.

    This is good if you don't have access to the Apache Configs or .HTACCESS, Also if things change you can make page.php a directory name for static file placement. Oh and PHP doesn't need to have a .php extension. I've used .api or somesuch in the past.

    http://www.example.com/worker.api/rest/url
    

    That seems to work well for me.

提交回复
热议问题