Domain-Based Routing for Multi-Site Deployments

2025-05-24

web-developmentfasthtml

Domain-Based Routing for Multi-Site Deployments

Today I learned you can deploy the same page but have it behave differently based on the domain it's accessed from. This lets you run multiple sites from a single deployment!

The Use Case

I wanted my personal site (isaacflath.com) and consulting site (kentro.tech) to be the same Railway deployment, but show different content on the index route depending on which domain was used.

The Solution

Check the host header in the request and route accordingly:

@rt
def index(request):
    host = request.headers.get("host", "")
    if 'kentro.tech' in host:
        from consulting import consulting_index
        return consulting_index()
    else:
        return aboutme()

How It Works

  1. Single Deployment: Both domains point to the same Railway app
  2. Host Header Detection: The browser sends the domain in the host header
  3. Conditional Routing: Different functions are called based on the domain
  4. Fallback Logic: Default behavior if domain doesn't match

My usage

  • isaacflath.com → Personal about me page
  • kentro.tech → Consulting services page
  • Same backend, same deployment, different user experience

Let's Connect

© 2025 Isaac Flath • All rights reserved