Created
November 4, 2011 07:16
-
-
Save josuecau/1338840 to your computer and use it in GitHub Desktop.
Simple PHP routing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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