You need to use an .htaccess
file if you are using apache. If you are using IIS then you can configure it in IIS.
Have a look at this.
Your .htaccess
file would need to look something like this:
IndexIgnore * # prevent directory listing
Order deny,allow
Allow from *
# ------------------------------------------
# Rewrite so that php extentions are not shown
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
You cannot simply create a .htaccess
file in windows because of file constraints, so open a text editor (Notepad ++ or your programming IDE) and create a new file called .htaccess
. The .
is important in front of the file name.
Edit
Do not have duplicate file names. IE contact.php
and contact.js
as the htaccess
will not know which one to serve, which (depending on your apache) will either return an error page or it will serve one of them only.
As @AedixRhinedale pointed out in the comments below:
Just a note from Apache: You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. Any directive that you can include in a .htaccess file is better set in a Directory block, as it will have the same effect with better performance