Search code examples
serverlocalhosthosts

Get content from local server when accessing a custom local url (http://localost:8080 from http://localhost/testing)


I apologize if i'm being vague, but i don't know how to ask in more technical terms.

I have a server running on my local machine on a random (known) port. I started it with python -m SimpleHTTPServer 8080. I want to be able to type http://localhost/testing or any url (if the solution is simpler) and get that content that's served on the above mentioned port. The url i'm accessing needs to be <something/somethingelse> (have a slash in there). Reason being, i'm doing some url manipulation and need to test different scenarios.

ex: server is serving content on http://localhost:8080 - i want to type http://localhost/testing in the browser url and get whatever's served on localhost:8080.

I couldn't do it with hosts mapping. I'm on a mac.


Solution

  • The question would be much clearer if you used complete URLs. I'm guessing what you're asking for is a redirect or a proxy:

    From http://localhost/testing To: http://localhost:8080

    The solution would be to install a web server (separate from the python SimpleHTTPServer) that is configured to listen on port 80 and redirect based on URL path, e.g.

    if URL path == /testing, then redirect to http://localhost:8080

    Depending on your platform, you might use nginx (linux/macos) or IIS (windows). You might even be able to use nginx on Windows if you're using WSL. Instructions for installing and configuring those packages.

    Configuring a simple redirect is far easier than a proxy.