Skip to content

Instantly share code, notes, and snippets.

@josuecau
Created November 4, 2011 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josuecau/1338840 to your computer and use it in GitHub Desktop.
Save josuecau/1338840 to your computer and use it in GitHub Desktop.
Simple PHP routing
RewriteEngine On
#RewriteBase /path/to/dir/
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# add trailing slash
RewriteRule ^.*[^/]$ $0/ [L,R=301]
RewriteRule ^.*$ index.php [NC,L]
<?php
$request_uri = explode('/', $_SERVER['REQUEST_URI']);
$script_name = explode('/', $_SERVER['SCRIPT_NAME']);
foreach ($script_name as $key => $value) {
if ($request_uri[$key] == $value) {
unset($request_uri[$key]);
}
}
$commands = array_values($request_uri);
?>
<pre><?php print_r($commands); ?></pre>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment