Welcome! Log In Create A New Profile

Advanced

Subdomain Rewrites

Posted by vanderkerkoff 
Subdomain Rewrites
April 19, 2013 04:57AM
Hello there

I'm running nginx/0.7.62 on a Ubuntu box.

We've recently changed domain names.

I've got 2 wildcard DNS entries setup pointing at the server

*.subdomain.domainA.com and *.subdomain.domainB.com

I can't quite figure out how to redirect all the traffic from *.subdomain.domainA.com to *.subdomain.domainB.com whilst passing the same value for * onto the new redirect.

Can someone tell me whats wrong with the following code?


server {
listen 80;
server_name ~^(\w+)\.subdomain\.domainA\.com$;
location / {
rewrite ^(.*) http://$1.subdomain.domainB.com$request_uri permanent;
}
}

It currently redirects anything.subdomain.domainA.com to .subdomain.domainB.com

So that suggests (\w+) is not being described by $1. I think I've got a mixture of different versions syntax going on.

Any help, as always, greatly appreciated.
Re: Subdomain Rewrites
April 19, 2013 07:15AM
Update

I have now updated to 1.2.6 in an effort to get this working.

I will now change the syntax to the newest possible.

Back in a bit :-)
Re: Subdomain Rewrites
April 19, 2013 07:41AM
Got it

server {
listen 80;
server_name ~^(?<firstsubdomain>.+?)\.subdomain\.domainA\.com$;
rewrite ^(.*) http://$firstsubdomain.subdomain.domainB.com$request_uri? permanent;
}

Always helps to upgrade, and I always never want to :-)
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 167
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready