Last Updated: February 25, 2016
·
835
· gerbenjacobs

Clean URLs with parameters

Why would you want clean URLs that also allows parameters? Well for me the answer was to create an API.

RewriteEngine on
RewriteBase /api/
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php/?route=$1&%{QUERY_STRING} [L]

This will route anything to the route variable but also send the original query string.

http://example.com/api/users?user_id=365

Will give you a $route of '/users' and a $_GET['user_id'] of '365'. (Or however you gather your vars in your language)