I think the best way to do this is to accept MVC-style URL manipulations using URIs, not parameters.
In your htaccess use like:
<IfModule mod_rewrite.c> 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] </IfModule>
Then, in your PHP Script, you want to create a small class to read the URI and split it into segments, such as
class URI { var $uri; var $segments = array(); function __construct() { $this->uri = $_SERVER['REQUEST_URI']; $this->segments = explode('/',$this->uri); } function getSegment($id,$default = false) { $id = (int)($id - 1);
Use as
http://mysite.com/posts/22/robert-pitt-shows-mvc-style-uri-access
$Uri = new URI(); echo $Uri->getSegment(1); //Would return 'posts' echo $Uri->getSegment(2); //Would return '22'; echo $Uri->getSegment(3); //Would return 'robert-pitt-shows-mvc-style-uri-access' echo $Uri->getSegment(4); //Would return a boolean of false echo $Uri->getSegment(5,'fallback if not set'); //Would return 'fallback if not set'
Now in MVC Usually http://site.com/controller/method/param , but in an application with a non-MVC style you can do http://site.com/action/sub-action/param
We hope this helps you move forward with your application.
source share