Last active

URL rewriting

  • Download Gist
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# Why rewrite URLs? Read this:
# Apache (.htaccess or httpd.conf)
# Make sure AllowOverride is on for the directory, or put the rewrite rules in httpd.conf
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]
# Nginx (nginx.conf)
try_files $uri /index.php;
# More reading:
Note: Thanks to James ( for his improvements and fixes (

#Lighttpd Rewrite
url.rewrite-once = ( "/(.*)" => "/index.php/$1" )

Using XAMPP for development, I was getting thrown to its splash page any time I attempted to add params to my URL. Removing the leading slash in front of index.php in the RewriteRule resolved this. Modified rule follows.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L] 

Note: This is while using XAMPP in development using klein.php to route in an application that was not in the DocumentRoot. See Gist: for help with dispatching in this scenario.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.