Is there any way to not use file extensions in the url without ending up in a 404

Website URL

https://djdonnyg.42web.io

Error Message

It’s not really an error but, when I visit the contact page for example I go to “/contact.html” in the url bar, I wanted to know if there is a way to make it be “/contact” only. If I just type “/contact” currently it redirects me to a 404 page.

Hi and welcome to the forum! Please create a .htaccess file on your domain’s htdocs folder or, if it exists, edit it with the following content:

Options +MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R,L,NC]

These rules should enable access to your PHP and HTML files without any extension added in your URL and redirect every request to a PHP/HTML file with an extension to the equivalent without any extension added.

6 Likes

Thanks! That worked!

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.