Hide php extension with Apache

Published: 13 years ago

  • Snippet Length: 10 minutes
  • Difficulty: Easy
  • Knowledge: PHP, Linux Administration, Vim Editor

Ever wanted to get some pretty URLs without ever showing the file extension of the php

1. First step is to create a .htaccess in the root of your website if theres not one already there we can create it via the following line

sudo vim .htacesss

2. Once inside the file we will need to turn the apache mod re-direct engine on

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
</IfModule>

3. Save the .htaccess

:wq!

4. You can now try created a file called test.php in the base of your web folder and see if its reachable by accessing www.yourdomain.co.uk/test if you recieve

comments powered by Disqus
:?>