Welcome! Log In Create A New Profile

Advanced

redirect some subdomains to https using server_name regex

Posted by sonic393 
redirect some subdomains to https using server_name regex
November 14, 2013 08:19AM
Hi

I'm trying for a while now and I've searched google, but I can't seem to find the right solution for my redirect problem.

I have a webserver running nginx, and I'm trying to get all subdomains linked tot this mailserver to redirect to https automatically.

the subdomains are
- mail
- mailserver
- webmail
- connect

I allready setup the correct multidomain certificate so that's handled. I have tried many server_name regexes but none of them work.

server_name ~^(mailserver|mail|connect|autodiscover|webmail)\.mydomainname\.com$;
rewrite ^ https://$server_name$request_uri? permanent;

But when I save this and try one of the above subomains, I just get this full server_name back in my browser address...

I am forgetting something or doing something wrong, but what? Please help...
Re: redirect some subdomains to https using server_name regex
November 14, 2013 08:48AM
Never mind... most of the times, right after you post something to a forum, you will find the answer all of a sudden..

but, to be polite, I will also include the solution (if a better one exists, please correct me)

server {
server_name ~^(?<sub>mailserver|mail|connect|autodiscover|webmail)\.mydomainname\.com$;
rewrite ^ https://$sub.mydomainname.com$request_uri? permanent;
}

The ?<sub> part wil catch the requested subdomain in the list and put it in the $sub variable. Then use this to make the redirect... A couple of hours lost with this one....
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 155
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready