Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Perfect PHP .htaccess rewrites
# What this does is enable rewriting, then checks if your trying to access something that exits
# if not it will take you to the index, with the path your requesting attached to the url varible
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
/* What this does is take that url variable and break it into a high usable $_urlvars variable that you can then use to load files or pass information with */
$_urlvars = explode('/',$_REQUEST['url']);
$_urlvars['_'.$k] = $v;
foreach($_urlvars as $k => $v){
$_urlvars[$v] = (isset($_urlvars[$k+1])?$_urlvars[$k+1]:'');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment