Remove .html suffix

It would be great to be able to remove the file suffixes (.html .php) etc from web pages in blocs - on flat file sites we can just use mod rewrite in htaccess on apache but in blocs the pages appear to have to have a file suffix… so having a check box that allowed to ‘remove file suffixes’ would be great. This would have to follow through to the navigation, links and sitemap :slight_smile:

2 Likes

Hey @DFore

If you remove the .html how is the web browser suppose to find the site?
I don’t think you can have a link in your menu that goes to a file called “about” without an extension.
I think all such manoeuvres has to be done server side.
In Joomla/Wordpress and such the files have extensions but can be visually hidden, done from the server side.

1 Like

I have browsed a lot of forums and seen article after article on HTML and web pages, but this is the first time I have ever seen a request to have HTML pages with no suffix.

I can’t see any demand for this and I hope it goes the the very end of Norms To do list and is pinned there!

…unless you can really convince me how good this idea is.

Actually, it would be great to have an export with folder names = page names, and inside only index.html / index.php files, so that the web server is able to serve default files.

Old:
/index.html

  • /store.html
  • /contact.html

New:
/index.html

  • /store/index.html
  • /contact/index.html

With this, it is easy to switch from .html to .php if required, and links indexed by web crawlers are not broken.

There is a concept in web design called “speaking urls”. It’s more important with Typo3 etc where you have even weirder urls like xyz.com/index.pHP?id=12345 . There are tools to have better understandable urls for users and search engines to find. With Blocs we don’t have this problem, but,

Mr. "Blocs Addon"s concept would make it even simpler so that a user can type in xyz.com/store instead of xyz.com/store.html to get to the desired page directly. Would be nice to have :wink:

Yes, but that’s not quite what the original request was about. Just generating pages without a suffix won’t do.

The idea of ( optionally ) generating directories for blocsapp pages ( with index.html inside ) would be good. I think it’s been requested before.

Just dropping the suffixes is going to be only something for an advanced user able to properly configure their server - definitely not for the intended blocsapp userbase.

An advanced user could generate a script to remove the html references from the generated html and the filenames.

As I mentioned in the original post this is to allow us to use mod_rewrite on the server - so that in the browser …site.com/contact.html would appear as …site.com/contact . For this to work would require that the menus and links in blocs were as such: …site.com/contact instead of …site.com/contact.html

Sorry if my post wasn’t clear… I didn’t mean the physical file suffixes on the files would be removed - just in the navigation, links and sitemap.

I am not sure adding an htaccess file with three lines of code requires an advanced user…? and having to run a script to update all the links in a site every time we make a change to the site is a real pain.

The request was just to allow us to have the option of using mod_rewrite on the server…

1 Like

I found this and it worked well for my Adobe Muse created website - I intend to try it on my Blocs site later this week.

I found an easy copy and paste code and created a new htaccess file my mac text editor:

RewriteEngine on

RewriteCond %{THE_REQUEST} /([^.]+).html [NC]
RewriteRule ^ /%1 [NC,L,R]

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]

Just save the file as “htaccess” without the quotes (of course) and after uploading to your site root folder change the name to “.htaccess” and done. It worked for me: concatosells.com/test I was so happy this was so simple and easy that this worked - and I am NOT a coder person at all! Oh… and unlike what some others wrote in this timeline… you do not have to change anything about your blocs website, just build as you always do, and don’t rename any of your blocs created file at all.

(12/05/2017) Just a follow-up since I posted this - I have now applied this code to several websites of mine and it works without hitch or glitch with all of them!

2 Likes

I would really like to see this built in as part of Blocs, so that we can choose how the URL appears as part of the project/page settings. I personally like to create a folder for each page with a index.php or index.html inside the folder.

Instead of having URLs like example.com/portfolio.php you end up with example.com/portfolio and there is no need to add .php or .html. It needs something like the attachment below in Blocs.

Another advantage is that if you change from html to php or vice versa the browser will just find it automatically. It’s also worth pointing out that if you are running any kind of promotion they never appear with an index.html URL at the end.

I’d like this also.

I would like the same swell! used the htaccess file but it only remove the html from the home page :frowning:

Great topic, I mentioned some of this in another post but I think this is a perfect place to add these comments.

Some call it Clean URL’s or Search engine friendly URL’s. It’s an ancient practice used with Apache servers and it’s really easy to find this type of hosting.

Static sites can behave quite dynamically using javascript. With HTML5 web storage and application cache it’s never good to assume that an HTML file isn’t dynamic or doesn’t warrant clean urls.

Mod Rewrite
It also handles 404 (missing pages), enables page and image caching, handles rewrites for missing and moved pages. It also provides protection for you site and the file itself.

My htaccess for a static html site.
I’m including a link to a copy of my htaccess file. It’s just a plain text .txt file. To make it work, save it with the name .htaccess (must include the dot.) You’ll want to learn how to show hidden files on your system if your not sure.

Get a copy of my htaccess here.

Where do I place the file?
The file goes in the root directory of your website.

What can this htaccess do?

  • Use UTF-8 encoding for anything served text/plain or text/html
  • Prevents browsing directories
  • Handles Custom error pages
  • Fixes Cross Origin Resource Sharing (Cors) for webfonts served by CDN
  • Enables Compression
  • Leverages Browser Caching
  • Restricts access to source files
  • Enables Rewrite Rules
  • Forces SSL
  • Forces non-www in a generic way
  • Removes the html extension
  • Removes the trailing slash
  • All index to root
  • 301 from example.com/page.html to example.com/page
  • Restricts access to .htaccess and hidden files

As you can see there’s a lot you can and should be doing with your server to help with performance, security, SEO and URL vanity.

Hope this helps.

Ups! I used your file but now looks like this

This isn’t for copy paste so much as it is for learning. Did you update the URL to be your website. (near the top)

Also you’ll want to comment out or remove sections like…

  • force https:// If your site is not https secured.
  • rules for page redirects that won’t be plug and play for you as well.

If anything this will help to get you understanding your site and your server environment better.

Check those things out and if you can’t figure it out I’ll chime back in and assist.

ahh!! haha I just upload it as it was :stuck_out_tongue: Also I have a ssl secured site

So should I live this or should I remove it?

Let’s start simple you can use the rest to increase your knowledge at some point.

just add these lines to an empty .htaccess (must begin with dot. must not have a file extension) and build on top of them.

#Rewrite Rules
RewriteEngine on

#Remove the html extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

#Restrict access to .htaccess and hidden files
RewriteRule "(^|/)\." - [F]

Also you’ll need to post screenshots from this point on. I can’t tell why things aren’t working if I can’t see what you’re doing.

what im doing wrong?

Hey Stew,

Did you …
TURN ON show hidden files on your Mac.
Rename the file to .htaccess (It must have the dot and no other file extension.)
To test it place that file at the root of your site. (local server if you can in case it’s not working for you like MAMP.)

The are other regex ways to achieve similar or same. This method works for me on cheap shared hosting.
After we are sure you have the setup properly, you can try some other regex if this isn’t working.

These Regular Expressions are fun if you enjoy being annoyed. :joy: