Skip to content

Instantly share code, notes, and snippets.

@Hexodus
Created March 12, 2016 13:05
Show Gist options
  • Save Hexodus/144de06fde12a09c005d to your computer and use it in GitHub Desktop.
Save Hexodus/144de06fde12a09c005d to your computer and use it in GitHub Desktop.
Rewrites all url requests to index.php and stores the path in the url variable which is being processed into $uri variable (to prevent empty values).
//.htaccess code
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
//PHP part
// extracts the path from url and stores it in $uri
if (isset($_GET["url"]))
$uri = substr_count($_GET["url"], "/") >=1 ? explode("/", $_GET["url")) : $_GET["url"];
else
$uri = "/";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment