Skip to content

Instantly share code, notes, and snippets.

@hemant-tivlabs
Created September 21, 2020 04:41
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 hemant-tivlabs/353c0728216d3314bdbd52a8ad378d20 to your computer and use it in GitHub Desktop.
Save hemant-tivlabs/353c0728216d3314bdbd52a8ad378d20 to your computer and use it in GitHub Desktop.
An .htaccess rewrite helper file that helps pass URI fragments as parameters to a single file
<IfModule mod_rewrite.c>
RewriteEngine on
#RewriteBase /
## If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
## If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
## If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
## don't do anything
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)?$ ./index.php?param1=$1&param2=$2&param3=$3&param4=$4 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)?$ ./index.php?param1=$1&param2=$2&param3=$3 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)?$ ./index.php?param1=$1&param2=$2 [L,QSA]
RewriteRule ^([^/]+)?$ ./index.php?param1=$1 [L,QSA]
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment