How to Remove File Extensions Like .php and .html From Your URL using .htaccess


To change the way websites load in 'yourdomain.net.au/page1.html' to 'yourdomain.net.au/page1', or to turn 'yourdomain.net.au/admin.php' to 'yourdomain.net.au/admin':

Step 1 -
Access your .htaccess file.

Step 2 - Add the below code to the top of the file:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Step 3 - Select Save.


Note: If you'd like to remove other file extensions, you would add a similar line, replacing '<File_Extension>' with the extension in question:

RewriteRule ^([^\.]+)$ $1.<File_Extension> [NC,L]


Did you find this article useful?