Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think the best way to do this is to adopt the MVC style url manipulation with the URI and not the params.</p> <p>In your htaccess use like:</p> <pre><code>&lt;IfModule mod_rewrite.c&gt; RewriteEngine On #Rewrite the URI if there is no file or folder RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] &lt;/IfModule&gt; </code></pre> <p>Then in your PHP Script you want to develop a small class to read the URI and split it into segments such as</p> <pre><code>class URI { var $uri; var $segments = array(); function __construct() { $this-&gt;uri = $_SERVER['REQUEST_URI']; $this-&gt;segments = explode('/',$this-&gt;uri); } function getSegment($id,$default = false) { $id = (int)($id - 1); //if you type 1 then it needs to be 0 as arrays are zerobased return isset($this-&gt;segments[$id]) ? $this-&gt;segments[$id] : $default; } } </code></pre> <p>Use like</p> <p><a href="http://mysite.com/posts/22/robert-pitt-shows-mvc-style-uri-access" rel="nofollow noreferrer">http://mysite.com/posts/22/robert-pitt-shows-mvc-style-uri-access</a></p> <pre><code>$Uri = new URI(); echo $Uri-&gt;getSegment(1); //Would return 'posts' echo $Uri-&gt;getSegment(2); //Would return '22'; echo $Uri-&gt;getSegment(3); //Would return 'robert-pitt-shows-mvc-style-uri-access' echo $Uri-&gt;getSegment(4); //Would return a boolean of false echo $Uri-&gt;getSegment(5,'fallback if not set'); //Would return 'fallback if not set' </code></pre> <p>Now in MVC There usually like <a href="http://site.com/controller/method/param" rel="nofollow noreferrer">http://site.com/controller/method/param</a> but in a non MVC Style application you can do <a href="http://site.com/action/sub-action/param" rel="nofollow noreferrer">http://site.com/action/sub-action/param</a></p> <p>Hope this helps you move forward with your application.</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