Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

robj's avatar
Level 9

Vapor - redirect secondary tld to primary tld

Hi,

Does anyone have any elegant ways of getting, say, mydomain.co.uk to redirected to mydomain.com in vapor?

Thanks, RobJ.

0 likes
6 replies
martinbean's avatar

@robj Most domain registrars will let you configure canonical redirects like this at the DNS levels you’re not needlessly sending the request to a web application, booting that web application, and that web application then having to return a redirect response.

robj's avatar
Level 9

@martinbean Yes - it's another moving part though. Feels like something you should be able to do in Vapor, I mean they redirect www.domain.tld to domain.tld - that's a config in nginx or something, right?

martinbean's avatar

@robj But again, you’re sending a request to a web framework, that then has to boot a process and the entire Laravel framework, just to redirect; when you redirect before any of that by doing the redirect at the DNS level.

robj's avatar
Level 9

@martinbean Yup, I didn't suggest otherwise, I said it was another moving part - Vapor already redirects www to root and that behaviour is configurable, so, the idea that it could do it for different tld's etc in line with its current capability isn't ridiculous.

ce10r8mn's avatar

@martinbean A full HTTP redirect with relative path and query parameters preserved cannot be done at the DNS level. Cloud domain name providers that allow these services run an Apache/NGINX server in the background when you enable this service.

Is there a way to have this cleanly set up using Vapor? I have 4-5 Production domains that need to be redirected to a single master domain.

1 like

Please or to participate in this conversation.