Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement URL pattern interpreter as used by Django and RoR in PHP
    text
    copied!<p>What's the best way to implement a URL interpreter / dispatcher, such as found in <a href="http://docs.djangoproject.com/en/dev/topics/http/urls/?from=olddocs" rel="nofollow noreferrer">Django</a> and RoR, in PHP?</p> <p>It should be able to interpret a query string as follows:</p> <ul> <li><code>/users/show/4</code> maps to <ul> <li><em>area</em> = <strong>Users</strong></li> <li><em>action</em> = <strong>show</strong></li> <li><em>Id</em> = <strong>4</strong></li> </ul></li> <li><code>/contents/list/20/10</code> maps to <ul> <li><em>area</em> = <strong>Contents</strong></li> <li><em>action</em> = <strong>list</strong></li> <li><em>Start</em> = <strong>20</strong></li> <li><em>Count</em> = <strong>10</strong></li> </ul></li> <li><code>/toggle/projects/10/active</code> maps to <ul> <li><em>action</em> = <strong>toggle</strong></li> <li>area = <strong>Projects</strong></li> <li><em>id</em> = <strong>10</strong></li> <li><em>field</em> = <strong>active</strong></li> </ul></li> </ul> <p>Where the query string can be a specified GET / POST variable, or a string passed to the interpreter.</p> <p>Edit: I'd prefer an implementation that does not use mod_rewrite.</p> <p>Edit: This question is not about clean urls, but about interpreting a URL. Drupal uses mod_rewrite to redirect requests such as <a href="http://host/node/5" rel="nofollow noreferrer">http://host/node/5</a> to <a href="http://host/?q=node/5" rel="nofollow noreferrer">http://host/?q=node/5</a>. It then interprets the value of $_REQUEST['q']. I'm interested in the interpreting part.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload