Removing .html file extension from URL?

I have exported my Webflow site and I’m hosting on a 3rd party server. When I go to my site it includes .html after the URL on every page. I’ve looked at every other answer on the forums and no one seems to have come up with a solid solution. I know that I’m going to have to write a URL redirect in the .htaccess file to remove that file extension, but I’m not sure what the correct code is. I’ve tried almost every piece of code everyone has suggested but haven’t had any luck. Should I see changes immediately or does it take time for the code to kick in on the server?
Anyone else have any ideas on what I can put in the .htaccess file to fix this?

I just want my URL to go from yourdomain.com/index.html to yourdomain.com/index

Appreciate any answers!

Thanks,
Zack

Hey @zackrabie,

Try this rule in your .htaccess file:

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

Let me know if that helps :smile:
Cheers,
Dave

Hey @cyberdave,

After spending almost all of yesterday trying to solve this I was able to fix my problem. Here’s the solution for anyone who is having the same problem as I did:

  1. After exporting your webflow code, go through your entire codebase and change every href that has an .html file extension to not have any extension at all. So “index.html” becomes “index”. A quick way to do this is open every HTML file in Sublime Text, use “Find in File” (Cmd + Shift + F), and find “.html” and replace with “” (empty string).

  2. Now in your public_html file, create an .htaccess file if not already created. Then make sure the top of the file begins with:
    RewriteEngine on

  3. Add this code underneath the previous:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+)$ $1.html [NC,L]

5 Likes

Hi @zackrabie, yes, those are the correct steps, sorry, I thought you were just needing the part to remove the .html extension, not the whole workflow. You nailed it !

Cheers,
Dave

Your code is correct btw, @cyberdave. Thanks for your response. The trick is making sure all .html extensions are removed from the hrefs in your HTML documents. That is the only thing that worked for me.

2 Likes

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