Reputation: 804
I have hundreds of subdomains set up for environments in Route53 for AWS that look like this:
<appX>.dev.internalurl.us
<appX>.qa.internalurl.us
<appX>.pt.internalurl.us
<appX>.internalurl.us
The issue is that our production internal urls are missing the 'prod' env in the url which requires us to add conditionals to all our config scripts, like:
if 'prod.' in url: url = url.substring('prod.', '')
What I'd like is:
<appX>.prod.internalurl.us to go to <appX>.internalurl.us automatically.
EDIT:
I added a CNAME to route prod.internalurl.us to internalurl.us like so:
*.prod.internalurl.us > internalurl.us
but this obviously won't work since I need a capture group on the wildcard! It's ignoring the first "appX" subdomain.
I don't want to have to enter in hundreds of CNAMES,so am looking for a catch-all redirect for one sub-domain level to its parent.
Is there a way to do this with CNAME or does it require running an nginx proxy at prod.internalurl.us to make this work?
Upvotes: 1
Views: 1219
Reputation: 15530
The solution that may help is simple enough. To find it out let me ask a question. Why do you need this functionality on DNS level?
What I'd like is:
.prod.internalurl.us to go to .internalurl.us automatically.
CNAME doesn't help with conditional URL rewrite, there is no such logic on that layer. What helps is HTTP layer 301 redirect can be managed via Nginx:
server {
server_name ~^(?<app>.+)\.prod\.internalurl\.us$;
return 301 http://$app.internalurl.us$request_uri;
}
There is no proxy but HTTP 301 redirect instead.
Upvotes: 1