Implementing Clean-urls?



How do we implement clean-urls in php using .htacces?



There are 2 cases we want to use:

1. We want to target to the php extension like this:
http://example.com/home -> http://example.com/home.php

.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]

2. We want to target to index.php and add the extension as the GET veriable to index.php. Something like this happens in CMSes like Drupal too.
http://example.com/home -> http://example.com/index.php?q=home

.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
<code>