phpurladdress-bar

how to hide .php from address bar


I use php to build web applications, but i want my web pages without .php extension in the browser's address bar. For eample http://www.example.com/index.php shows like http://www.example.com/index in the browser's address bar.

How can i do this?


Solution

  • Put this in a file named .htaccess in your WWW-root:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(([A-Za-z0-9\-]+/)*[A-Za-z0-9\-]+)?$ $1.php
    

    This works if you're running Apache and have mod_rewrite activated.