0

I want to change the default 404 page of the python3 module http.server to a custom 404.html page, so it will redirect the client to that page.

I have confirmed the 404.html works, but putting a 404.html in the web root doesn't help.

Any solution?

oguz ismail
  • 1
  • 16
  • 47
  • 69
sudoer
  • 154
  • 7
  • 1
    First of all `http.server` module is not intended for production. It is not designed to be that at all. Placing a file called `404.html` in web root does not mean it will be taken as 404 page from web server at all. You need to specify the webserver what to do in case of 404 event. – Bijay Regmi May 08 '22 at 07:19
  • @Bijay Regmi thx for your answer. then what should i do? i usually start the server with this command, `python3 -m http.server` cuz i am on Linux. – sudoer May 08 '22 at 08:00
  • 1
    Use Nginx if you already have your html files. If you are on debian based systems `sudo apt install nginx` and put your html files in `/var/www/html`. Everything about this is customizable so all you need is do a small bit of research. – Bijay Regmi May 08 '22 at 08:13
  • 1
    https://stackoverflow.com/questions/1024199/nginx-customizing-404-page – Bijay Regmi May 08 '22 at 08:14
  • 1
    In conclusion, is that IMPOSSIBLE with python http.server? Anyway, I am on Xubuntu. Let me figure out how nginx works – sudoer May 08 '22 at 09:08
  • it is not impossible, its just unnecessary work you have to put into, specially if you are trying to set up a production environment when there are industry standard production ready products that you can just use. – Bijay Regmi May 08 '22 at 09:10

0 Answers0