Is there a way to remove the ".html" extension with .htaccess using repl.it?
I tried updating my site to use an .htaccess
file to remove the .html
file extension from the URL. This did not work and I'm just getting the replit 404 pages. Here's my code:
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.html -f RewriteRule ^(.*)$ $1.html [NC,L]
Is there an issue with my code or does repl.it not support .htaccess
rules? If it's repl.it not allowing it, is there any way I can do this without an .htaccess
just as easily? Thanks. (I'm also wondering, if I link my repl to an actual domain will this issue still occur?)
This question is old but for any future users looking to do this - You do not have to use .htaccess files. You can just create a folder with your desired name and place into it an index.html
If there are still people who are wondering how to achieve this, it now is possible to use an htaccess file with a static HTML,CSS,JS project. Here's the code I used to redirect all .html links to static endpoints:
RewriteCond %{THE_REQUEST} \.html RewriteRule ^(.*)\.html$ /$1 [R=301,L]
@bzzt Is not working for me, :(
Can you show us an example?
@nifhtnep71 create a .htaccess file copy paste that code in that file then remove .html extensions from all the files and it should work, if it still doesn't work feel free to ask me again :) hope I am not too late
I mean, I would just code a simple backend.
Flask
orexpress
or whatever.But yeah, repl should add
.htaccess
working. (idk if your code is wrong btw)@a5rocks I've tried my code on GitHub pages and it works fine. Any info on where I could learn to use flask or Express for this
@GavHern Well, I would just do something simple with Flask such as
Relevant SO question: https://stackoverflow.com/questions/20646822/how-to-serve-static-files-in-flask
If you are using the code above, put all your html files in a "website" directory, all your css in a "css" directory, and all your js in a "js" directory
The only thing is that Flask is dynamic, and so your site will be slightly slower. If you really want to counteract that, I would look into https://repl.it/languages/polygott, installing nginx using
install-pkg nginx
or whatever, and then customizing the command to allow.htaccess
. If you do that, and post it on https://repl.it/feedback, I'm pretty sure repl will update html/css/js repls to allow.htaccess
@GavHern I might be a little too late but for any new users: Replit doesn't show a 404 page with that .htaccess code is bcs it doesn't give a 404 error this is how .htaccess code is supposed to work:
If the server gives a 404 error the .htaccess will tell the browser that this is the 404 page, but replit dosent give a 404 error but instead replit servers show their own 404 page so if the htaccess dosent get a 404 error it will think that page exists so it wont redirect to our 404 page
i hope i was able to explain you correctly, you can blame replit for this, but you can easily create a 404 page with js,please refer to this(https://replit.com/@Coder100/Easy-404-error-page-ayayayayayaya-pogger-sub?c=135352)