Home > Back-end >  Remove .html extension in url
Remove .html extension in url

Time:12-04

Today I tried to remove html file extension from my website, for example:
example.com/page.html to example.com/page

I watched some tutorials, but nothing seems to work... I created .htaccess file in root directory
Copied code (also tried different ones):

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]

It didn't work when I opened my website as file, with Live Server (VS Code extension) or actual website (hosted on Replit)

Any idea, why it doesn't work? Any help appreciated...
See whole repository

Edit: Someone said, I have to remove .html file extension. I get error that the file is not found

CodePudding user response:

Yo should do it in this way:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.] )$ $1.html [NC, L]

CodePudding user response:

SOLVED As someone said, .htaccess file doesn't work on Replit. I've done following:

  1. Made folder for every .html file
  2. Moved that file inside of the folder I made
  3. Renamed the file to index.html
  • Related