(Solved) Switching Pages - Removing .HTML at end?

At the moment, when I switch a page, it adds .HTML after every page.

I’d like my page to just appear http://demo.com/page instead of http://demo.com/page.html

Also, I noticed sometimes the page does not load at all when .html is loaded, but when I remove .html at the end, it works. It’s strange.

You can do it by exporting your site and adding .htaccess file in which you can set it up.


.htaccess

RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ $1.html [NC,L]

You’re welcome :slight_smile:

3 Likes

Thank you, I really appreciate it :slight_smile:

Note:
Websites published on Webflow will have extension-less (without .html) URLs by default. When you export code from Webflow we give the files extensions (add .html) because you can’t have extension-less files on a local machine (unless you set up a local server, but that can be very hard for some folk).

I understand why the files need a file ending when downloaded, but how can we reverse the .html file addition when we upload via FTP?

I know a .htaccess file would clear up the problem, but I would really prefer a method that’s part of the webflow file system or at least works well within it.

1 Like

Hey Bartosz, Where do I put this in my site? I want to export and host it without having to add .html to every page if entering directly.

Thanks!

Hello Dave @DFink :smile:
You need to create a .htaccess file on your external server and put it in there.

is that a type of file or should it just be named with that extension?


Just like this ;)

Thanks so much! Got it working. Hate that mac doesn’t like files that start with a . and you have to show hidden files. But it works!

1 Like

Hey @bartekkustra - would this interfere with a custom 404 page when exported and hosted on our own server? I’ve just got this and this 404 code in my .htaccess file and it throws an error 500 instead of a 404.

Here is the entire contents of my .htaccess file:

RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ $1.html [NC,L]

ErrorDocument 404 /404.html

Thanks so much for the help!

What I think might be the issue is that in .htaccess you specify which document should be shown once the error occur. But if the document is not available at the given directory it might get into an infinite loop that tries to show a 404-page that you can’t find a 404 page that you can’t find a 404 page… etc.

Try removing the / sign from /404.html and check how that works. If you find troubles with that contact me using details in my profile.

Good luck!

This fixed it:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html

ErrorDocument 404 /404.html

1 Like

I understand this is fixed with the .htaccess file, but wouldn’t it be easier to create new folders and place the html of the page inside (called index.html)? It would have to reference the css and js folders using “…/”, but I think it would be a better solution than .htaccess.

1 Like

I’m a little confused too. Why not use the standard Web tricks for this? They require nothing special server-side: base tag, relative URIs, folders with index.html files, etc. Much, much better than using .htaccess and (uuugh) mod_rewrite.

It would be really nice to be able to just serve up the downloaded files and get a working site with the intended URLs intact.

1 Like

OK, sorry for the whining :slight_smile: After an hour of trying to get the rewrite rule translated for nginx (the server I use), I found out about “try_files”. It’s nifty and provides a partial solution:

location / {
  try_files $uri $uri/index.html $uri.html =404;
}

That tries each option in order until it finds a file. Otherwise (last option) it returns a 404. For example for “/foo” it tries “/foo”, then “/foo/index.html”, then “/foo.html” which will work with the Webflow style.

The only problem left is that all the links on the pages use the .html, thus promoting crawlers to index that instead of the desired URLs. I can parse and rewrite all the html files after downloading, but IMO I shouldn’t have to.

Hello,

I used this codes on my .htacess and it still has the extension behind. help pls? http://geddit.sg is the website that I have exported the files to.