All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

Remove File Extensions Using Htaccess File

Last Updated : Jul 1, 2023

IN - Htaccess | Written & Updated By - Anjali

In this tutorial we will show you how to remove file extensions using .htaccess file.File extensions like .php, .html, .asp etc. All this kind of extensions will be removed only just by editing your .htaccess file.

Remove File Extensions Using Htaccess File

To Remove File Extensions It Takes Only One Step:-

  1. Find and edit your .htaccess file

Step 1. Find and edit your .htaccess file

Edit Your .htaccess file if it is not present then create a one for yourself.Then write these lines.

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
#RewriteRule ^([a-z]+)\/?$ $1.php [NC]


RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html
#RewriteRule ^([a-z]+)\/?$ $1.html [NC]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.asp -f
RewriteRule ^(.*)$ $1.asp
#RewriteRule ^([a-z]+)\/?$ $1.asp [NC]

</IfModule>

// URL Before Editing
http://yoursite.com/index.php

// URL After Editing When Visit
http://yoursite.com/index

In this step we remove the file extensions for three languages .php, .html, .asp you can remove as many as you want.

You can also change your directory or folder configuration using .htaccess file and also you can redirect the user to different page, password protect a specific directory etc using this .htaccess file.

Thats all, this is how to remove file extensions using .htaccess file. You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.

I hope this tutorial on remove file extensions using htaccess helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Anjali

Experienced Computer Programmer with a broad range of experience in technology. Strengths in application development and Object Oriented architecture design, front end programming, usability and multimedia technology. Expert in coding languages such as C, C++ Java, JavaScript, PHP and more.

Follow Anjali On Linkedin 🡪