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....
Do you like below Tutorials ?
- PHP Convert Date String to Datetime Object
- Laravel Validation Different Value Example
- Jquery Redirect to URL After Specific Time Example
- User Roles and Permissions in Laravel Example
- How to Get Value of Selected Option in Vue JS?
- Laravel Change Password OLD Password Validation Example
- Vue JS Get String Length Example
- How to Active and Inactive Status in Laravel?