How To Make SEO-Friendly URLs Using Apache mod_rewrite And PHP
erics, Posted December 15th, 2011 at 11:48:03am
Below information copied without permission from Josh Sharp’s site because it is too valuable to lose – great work Josh, and THANKS!
1 2 3 4 |
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] |
Note: Only rewrite if the requested file is not an existing directory (-d) or a file (-f)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
include('app/classes.php'); include('app/app.php'); //init our app $App = new App; //grab the mod_rewrite url $url = $_REQUEST['url']; //if the url is empty then the user has navigated just to root if ($url == ''){ //start with default controller $App->setController('home'); } else { //grab each part of our URL - controller, action, and identifier $path = explode('/',$url,3); //pass these onto the app to handle $App->setController($path[0],$path[1],$path[2]); } |
Leave Your Comment
All fields marked with "*" are required.