Remove .html extension in url - html

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

Yo should do it in this way:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC, L]

SOLVED
As someone said, .htaccess file doesn't work on Replit. I've done following:
Made folder for every .html file
Moved that file inside of the folder I made
Renamed the file to index.html

Related

.htaccess file to remove .html from url not working

I'm trying to get rid of the .html in the url of pages, and I found that code in the .htaccess file is the only way doing so and I've tried nearly every method and code online but it just wouldn't work.
Made an .htaccess file and put it in the public_html file. The general code I'm using is:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.html [NC,L]
But I've tried many many many other variations of the code so I think the issue isn't with the code but the way the file is getting loaded in to the website?
And yes, all my hrefs are shortened without the .html: ex/ <li>Contact</li>
The main error is in that I always get a 404 error - not found for when I try to go to a page, ex/ website.com/contact. But website.com/contact.html works fine or cannot get / error
I've tried this on both my hosted website and testing through vscode live server and I feel like it's an issue not with the .htaccess file somehow? Since this solution works for nearly everyone but me.
#remove html file extension-e.g. https://example.com/file.html will become https://example.com/file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
is what worked for me, from plothost , you seem to be missing a line.

rewrite everything except files and directories

i want to create a .htaccess rewriting rule for everything except existing files or folders, but cannot figure out what the problem seems to be.
My Code now is this.
RewriteEngine on
RewriteCond %{REQUEST_URI} !(-f|-d)$
RewriteRule .* index.html
i dont want to create a rule for everything except the allready existing files and folders in case i create aything else on the server.
the rewriting works properly but the exeptions do not.
the right code for this need is
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f #exeption for files
RewriteCond %{REQUEST_FILENAME} !-d #exeption for dirs
RewriteRule .* index.html

.htaccess file not removing file extension online

I am trying to remove the .html extension from my file name. This was working locally for me but stopped working, Online it did not work at all. The code I am using to remove the .html file extension is:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC]
AddType text/x-component .htc
Anyone have any other solution?

Moving From Development to Live Site breaks CSS

Using CodeIgnitor to manange this site I have configured the css in the following location:
{link rel="stylesheet" type="text/css" href="<? echo base_url();?>application/assets/css/public.css" />
Firebug shows me that the link points exactly where it should, unfortunately,
The problem is I keep getting 403 errors when it tries to load it.
my .htaccess file looks like this, and by the way, I don't really know what I'm looking at here:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|application/assets/js|application/assets/css|application/assets/images)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
RewriteCond $1 ^(images|js|css)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./public/$1 [L,QSA]
How do I get this CSS to load?
Additional Info:
In that the assets folder there is also a js folder and an images folder and the favicon is NOT being pulled from that images folder either.
It sounds like the configuration on that folder and/or the server are refusing you access to read the file.
http://en.wikipedia.org/wiki/HTTP_403
Try navigating directly to the css file and you can easily confirm that you are getting a 403 error, if so it is to do with permissions.
Try accessing your development site remotely rather than from the same machine and you may see the same error there.

modrewrite to remove the file extension but still load the page

I have a subdomain with .php pages in it. I just want to remove the .php I have written some code gathered from other posts on stack, so far I have this
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} (\.php(.*)\sHTTP/1)
RewriteRule ^(.+)\.php$ /$1 [R=301,L,QSA]
this rewrites
subdomain.example.com/weddings.php
to
subdomain.example.com/weddings
However it also creates a 404 page not found error. Am I doing something wrong?
Solved it. anyone struggling with the same thing here is my solution
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
found it on
http://css-tricks.com/snippets/htaccess/remove-file-extention-from-urls/
a fantastic website.