4

Is it possible to serve not a index of a directory but rather an html file using Python SimpleHTTPServer on path '/'?

Having directory with one file login.html serves a directory index on path '/'.

python -m SimpleHTTPServer 7800

screenshot

I want a content of login.html on '/'.

Is that possible?

2 Answers 2

5

SimpleHTTPServer (or http.server in Python3) will serve a directory unless that directory contains a file called index.html, in which case it will serve that instead.

So just rename login.html to index.html and it should do what you want.

Sign up to request clarification or add additional context in comments.

Comments

1

By default http server looks for index.html file and loads it. Otherwise it will serve the directory structure.

You can extend SimpleHTTPServer and write your own class with proper routing. I would prefer this.

But alternatively you could also add a redirect in index.html.

<html>
<body>
    <!-- redirect on load -->
    <script>
        window.onload = function () {
            window.location.href = "login.html";
        }
    </script>
</body>
</html>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.