How to remove file extensions from URL using htaccess?


Hi guys,

In this tutorial, i will let you know how to remove files extensions like .php, .html, .htm etc using htaccess file in php. So here i will write code of RewriteRule and it will remove file extensions from URL.

As we know, if you are working on core php project or simple html pages and upload it to server. it will work like as bellow link:

https://hdtuto.com/cat/laravelexample.html

https://hdtuto.com/cat/laravelexample.php

As you can see both way you can access your page as you created using html or php. But you can remove .html and .php from url using htaccess like you can make url like this way:

https://hdtuto.com/cat/laravelexample

So now as bellow you can learn how to remove .html and .php from url so let's see bellow solution:

Remove .php Extensions: .htaccess

RewriteEngine On

RewriteCond % !-f

RewriteRule ^([^\.]+)$ $1.php [NC,L]

Remove .html Extensions: .htaccess

RewriteEngine On

RewriteCond % !-f

RewriteRule ^([^\.]+)$ $1.html [NC,L]

Remove .htm Extensions: .htaccess

RewriteEngine On

RewriteCond % !-f

RewriteRule ^([^\.]+)$ $1.htm [NC,L]

For GoDaddy Users: .htaccess

Options +MultiViews

RewriteEngine On

RewriteCond % !-d

RewriteCond % !-f

RewriteRule ^([^\.]+)$ $1.php [NC,L]

I hope it can help you....






April 3, 2018 | Category : PHP HTML
Related Posts