2

Okay so first off let me be clear that I have "BASIC" knowledge of (HTML, CSS and JS) and a little bit of Python and am not much aware of various technologies and programming stuffs. So I hope the answer would be easy.

I created a sample folder which has only two HTML files:index.html and sample.html which have almost nothing in them except a hyperlink to each other. In cmd, I used the command: python -m http.server to create a localhost server for the folder. But as expected it gives 404 when I type:localhost:8000/sample on browser and works only with localhost:8000/sample.html. How do I remove the .html from URL?

Programmer
  • 31
  • 2

1 Answers1

2

I was able to achieve this but not in a general way. My code:

from http import SimpleHTTPServer, HTTPServer

class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
    url = "/path-no-html/"
    def do_GET(self):
        if url in self.path:
            self.path += ".html"
    
    SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)

with HTTPServer(('', 8000), MyHandler) as server:
    server.serve_forever()

Example of this being used in ec2instances.info