Skip to content

Instantly share code, notes, and snippets.

@pgooch
Created August 11, 2012 07:08
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 pgooch/3321959 to your computer and use it in GitHub Desktop.
Save pgooch/3321959 to your computer and use it in GitHub Desktop.
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