Have you ever come across a really strange-looking URL route? You know, something like www.www.example.com or www.staging.example.com? It’s curious how these things happen. We’re here to help clarify how these odd routes can sometimes be created, often due to placeholder logic and default routing settings. It’s something we notice from time to time, especially when users are setting up custom domains on preview environments for the first time.
Most routing situations typically revolve around the choice between using the apex or the www subdomain. You either direct the non-www to the apex or do the opposite. Platform.sh accommodates both options and offers placeholders to help keep your routes.yaml easy to manage.
"https://www.{default}/":
type: upstream
upstream: "app:http"
"https://{default}/":
type: redirect
to: "https://www.{default}/"
So what's happening with these strange routes?
First, identify your project's `default domain`. Check your default domain with this CLI command:
platform|upsun / | jq .default_domain
"example.com"
This setup often includes the apex domain but not the www subdomain.
When it's time to swap the preview environment domain name:
platform domain:add staging.example.com --environment staging --attach example.com
The `{default}` placeholder will be replaced with the staging domain `staging.example.com`, but the final route will still use the `www` prefix due to the `www.{default}` logic.
If your `default domain` is www.example.com and your routes.yaml is `www.{default}`, it results in repeated www.www routing.
Let's discuss the workaround...
The goal is to have www.example.com and staging.example.com.
Avoid hard-coding `staging.example.com` in your routes, as environment-specific routing isn't supported, leading to odd routes on every environment.
The easiest method is to set your `default domain` to your desired production domain and adjust your routing configuration accordingly:
"https://{default}/":
type: upstream
upstream: "app:http"
"https://example.com/":
type: redirect
to: "https://{default}/"
Then swap out the production domain with the staging domain:
platform domain:add staging.example.com --environment staging --attach www.example.com
We hope this clarifies things. For more help, feel free to open a ticket with our support team.