How to Remove PHP/HTML Extension From Url

.htaccess

These days programmers do not want to show the file extension in URL. Now the problem is how to hide or remove these extensions from the URL without coding the lengthy program or using the complex way. To remove the extension from URL, use the .htaccess file. This one is the simplest way for removing the extensions from the URL.

How to create .htaccess file
To create .htaccess file. Go to your project root directory create a new file and rename it as .htaccess then save it in project root directory

 

.htaccess

To hide the php and HTML extension from the URL, paste the below code in your .htaccess file

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

Sathishka Priyad

Software Engineer | Researcher | Blogger Founder of — Tech Orbit

Leave a Reply

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

x Shield Logo
This Site Is Protected By
The Shield →