Reputation: 27
I'm trying to get rid of the .html in the url of pages, and I found that code in the .htaccess file is the only way doing so and I've tried nearly every method and code online but it just wouldn't work.
Made an .htaccess file and put it in the public_html file. The general code I'm using is:
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^.]+)$ $1.html [NC,L]
But I've tried many many many other variations of the code so I think the issue isn't with the code but the way the file is getting loaded in to the website?
And yes, all my hrefs are shortened without the .html: ex/ <li><a href="/contact">Contact</a></li>
The main error is in that I always get a 404 error - not found for when I try to go to a page, ex/ website.com/contact. But website.com/contact.html works fine or cannot get / error
I've tried this on both my hosted website and testing through vscode live server and I feel like it's an issue not with the .htaccess file somehow? Since this solution works for nearly everyone but me.
Upvotes: 1
Views: 712
Reputation: 1288
#remove html file extension-e.g. https://example.com/file.html will become https://example.com/file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
is what worked for me, from plothost , you seem to be missing a line.
Upvotes: 0