title: (Nginx) Regex pattern to match everything but www
body: <p>Basically, I'm trying to setup nginx with regex so that it:</p>
  
  <ul>
  <li>Matches all subdomains for pyronexus.com &amp; notoriouspyro.com but NOT www (www is redirected to pyronexus.com).</li>
  <li>Gives me a variable I can use to determine what the subdomain and domain entered are (e.g. if someone enters space.pyronexus.com, I would like to have two variables $subdomain and $domain containing space and pyronexus).</li>
  </ul>
  
  <p>So far, I have this: <code>~^(.*)\.(?:pyronexus|notoriouspyro)\.com$</code></p>
  
  <p>But I just can't seem to figure out anything else! Any help would be greatly appreciated.</p>
  
  <p>Edit: Perhaps it would help to show my nginx config file:</p>
  
  <pre><code>server {
      server_name pyronexus.com notoriouspyro.com;
      listen 127.0.0.1:80 default_server;
  
      root /home/nginx/pyronexus.com/public;
      index index.html index.php;
  
      access_log /home/nginx/pyronexus.com/logs/access.log;
      error_log /home/nginx/pyronexus.com/logs/error.log;
  
      include php.conf;
  }
  
  server {
      server_name ~^(www\.)?(.+)$;
      listen 127.0.0.1:80;
  
      return 301 $scheme://$2$request_uri;
  }
  </code></pre>
  
  <p>The first part is the server which I need the regex for, the second part is to try and catch all domains landing on www and redirect them without www.</p>