Implementing Clean-urls?

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


14 points

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



0 points

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>

Anonymous's picture
Created by Anonymous

Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.