title: Is a good practice using variable subdomains?
body: <p>I have a web page, and now I've thought add subdomains so to have more readable urls</p>
  
  <p>For example, if my main page is <code>www.myshop.com</code> add  </p>
  
  <pre><code>product1.myshop.com
  category1.myshop.com
  etc...
  </code></pre>
  
  <p>It is hosted on Digital Ocean, and is runing under: <em>Ubuntu, nginx, unicorn, and POstgreSql database, developed with Ruby on Rails</em></p>
  
  <p>Once I've read docs about subdomains, I have realized that I can have <strong>variable subdomains</strong>, What I've tried is :</p>
  
  <p>1) Add a "A" record with * in "Domain configuration of Digital Ocean</p>
  
  <p>2) Modify nginx configuration file, adding a new line as I did for "www" subdomain, but with " * "</p>
  
  <pre><code>server {
     listen 80;
     server_name myshop.com;
     return 301 $scheme://www.myshop$request_uri;
  
     # NEW LINE ---&gt;
     return 301 $scheme://*.myshop$request_uri; 
  }
  </code></pre>
  
  <p>After that, within Ruby on Rails program, catching anything (category,product-name...etc as subdomains) before <code>myshop.com</code> is easy, and there I could redirect to category web pages or product web page, or or whatever automatically !</p>
  
  <p>so, for example, if user types <code>whells.myshop.com</code> I will redirec to www.mysop.com/categories/wheels</p>
  
  <p>(of course, the great thing is the <em>wheels</em> is a value in table)</p>
  
  <p><strong>without the need to register the names of subdomain</strong>, in Digital Ocean or in ngingx configuration file</p>
  
  <p>But,seems too easy to be true...:/</p>
  
  <p>Is this not secure? is a bad practice?</p>
  
  <p>Thanks a lot, (stackoverflow: very good web and very good users)</p>