Infolinks

Tuesday, April 3, 2012

Hide php extension -- URL Rewriting on Apache using htaccess

URL Rewrite using .htaccess on Linux Apache and Wamp Server
URL rewriting can be one of the best and quickest ways to improve the usability and search friendliness of your site. It can also be the source of near-unending misery and suffering. Definitely worth playing carefully with it - lots of testing is recommended. With great power comes great responsibility, and all that.

URL rewriting on Linux Apache and wamp
For rewriting url on Centos Please do these steps.
  1. First go to '/etc/httpd/conf/httpd.conf' and for wamp left click on wamp icon and go to Apache then httpd.conf and uncomment - #LoadModule rewrite_module modules/mod_rewrite.so and #AddModule mod_rewrite.c, so do so please remove trailing #.

  2. Now Edit directory section in this file for directory /var/www/html and change 'AllowOverride none' to 'AllowOverride All'.

    Eg.
    Options Indexes FollowSymLinks
    AllowOverride none
    Order allow,deny
    Allow from all
    ;
    TO

    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    ;

  3. Now make a file in server root directory '/var/www/html' name .htaccess and write these line in this

    Options +FollowSymlinks

    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond %{REQUEST_FILENAME}\.php -f

    RewriteRule ^(.*)$ $1.php


  4. Now this will remove php extension in your file so now if you want to open index.php then write only http://url/index only instead of http://url/index.php