How to hide extension in Php using .htaccess?

how to hide extension in php
If this article Helps you, Don't forget to share.

PHP developers basically working on website development and the tasks given by client, but some-time when we are working on security based project then, we should aware about security.

Now a days hackers are very familiar with programming languages and it’s hacking tip and trick but first, they are trying to hack in which language the website is developer/built. So what we should do for keeping away our website for its language dependency. So without wasting any more time todays in this article, I will show you

How to hide extension in PHP?

So let assume that. We are working on a project which details is given below. I will show you directory wise so you can understand easily and quickly.

Project Name (Project Folder Name): My_Project

In the inside of My_Project I will create one index.php file which will automatically called when we run the project. So the directory will be looks like.


Now What i want in this project is, I want to hide .php extension from the index.php, So Let’s do it step by step.

First create a new file in same/root directory (My_Project) and save as “.htaccess“.

Note: File name must be .htaccess

Now after successfully saved file, Write down below lines in that file Or You can copy and paste it directly in your .htaccess file.

RewriteEngine On
RewriteRule ^index/?$ index.php [NC,L]

Let’s understand What is meaning of the lines and why we should write this . Basically .htaccess file is used for given permission for specific task.

So Here we hide the extension from index.php [file.php] so it is called URL Rewriting in the Programming language. So In the first line, we are asking for On the RewriteEngine to rewrite the URL. and in the second line, first, we will put file name without extension (You can write any string or name) like below.

Ex. I want to rewrite index.php To home, So I will write as below

RewriteRule ^home/?$ index.php [NC,L]

And then after We will have to put original file name, You can put number of file in this .htaccess file.

I hope you guys enjoy. If you found this article very helpful Please share it and do comment for any question regarding .htaccess file.

If this article Helps you, Don't forget to share.


  1. Really?
    You explain it useless way, i’d got multiple files, should do i do write one line by file?
    Please, and someone posted this in reddit, amazing….

Leave a Reply

Your email address will not be published. Required fields are marked *

How can i Help you?
Powered by LatestinOne
error: Content is protected !!