Hide .html on search bar


#1

I am new to codeing (expecially html) and I want to hide my html like this website however mine looks like this: I found this http://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/ however it doesn’t work.


#2

Also I was wondering how to change the 404 from


#3

For hiding the .html file extension, take a look at this: How to Remove HTML File Extensions in URLs Without an .htaccess File


#4

You can use an Express Router to do so:

const Router = Express.Router();

const path = require('path');
const fs = require('fs');

Router.get('*', async (req, res) => {
  var trimmedPath = req.url.replace(/^\/|\/$/, '').trim().split('/..').join('');
  trimmedPath = path.resolve(path.join(__dirname, 'views', trimmedPath + '.html'));
  if (fs.existsSync(trimmedPath)) fs.readFile(trimmedPath, (err, data) => {
    if (err) return res.status(500).end('<h1>Error 500 - Internal Server Error</h1><p>We are terribly sorry, something went wrong. Copy and paste the long weird text below and send it to their respective owners. We have highly trained monkeys to handle with this drama. No screenshots, screenshots frighten them.</p><pre>' + aes.encrypt(error.stack, 'UsForTheWorld321') + '</pre>');
    data = data.toString();
    return res.status(200).end(data);
  });
});

App.use(Router);
// And finally, for 404 stuff.
App.get('*', async (req, res) => {
  res.status(404).end('<h1>Error 404 - File not found</h1><p>Nothing was found with that url. Try something else.</p>');
});