• Posts
  • RSS
  • ◂◂RSS
  • Contact

  • Redirecting all subdomains to www in nginx with virtual hosting

    June 17th, 2011
    nginx, tech
    If you look for how to redirect to 'www.example.com', you see people writing something where you have to know the hostname, or you have to know all subdomains. What if we need to be much more general, because this server hosts multiple domains, someone might come in on arbitrary subdomain, and we want all requests to go to 'www.REQUESTED_DOMAIN.com'? I came up with the following (it goes in the 'server' block'):
            server_name   ~^(?<subdomains>.+\.)?(?<domain>[^.]+\.[^.]+)$;
    
            if ($subdomains != www.) {
              rewrite  ^/(.*)$  http://www.$domain/$1  permanent;
            }
      
    This will do:
    • www.example.com: no change
    • example.com: www.example.com
    • mail.example.com -> www.example.com
    • mail.example2.com -> www.example2.com
    • foo.bar.baz.example.com -> www.examplecom
    Note that it assumes only one level of tld. So if your site is '.co.uk' or something, it will redirect all requests to 'www.co.uk', which is unlikely to be what you want.

    Recent posts on blogs I like:

    Interview with Kat Woods: decision-making about having kids

    Realizing what you don't want The post Interview with Kat Woods: decision-making about having kids appeared first on Otherwise.

    via Otherwise July 5, 2022

    Decision theory and dynamic inconsistency

    Here is my current take on decision theory: When making a decision after observing X, we should condition (or causally intervene) on statements like “My decision algorithm outputs Y after observing X.” Updating seems like a description of something you do…

    via The sideways view July 3, 2022

    10x (engineer, context) pairs

    Your actual output depends on a lot more than just how quickly you finish a given programming task. Everything besides the literal coding depends deeply on the way you interact with the organization around you.

    via benkuhn.net June 9, 2022

    more     (via openring)


  • Posts
  • RSS
  • ◂◂RSS
  • Contact