Automatic subdomain for every directory (mod_rewrite)

Discussion in 'Installation/Configuration' started by xsoft, Aug 16, 2013.

  1. xsoft

    xsoft New Member

    Simple question and nowhere is an answer.

    I want to have automatic subdomain creation (ISPadmin 3.0.3).
    I mean whenever I create a directory, a subdomain will be created.

    Example:

    Code:
    test1.domain1.com -> /var/www/domain1.com/web/test1
    test2.domain1.com -> /var/www/domain1.com/web/test2
    test3.domain1.com -> /var/www/domain1.com/web/test3
    
    domain1.com -> /srv/web/domain1.com/www
    www.domain1.com -> /srv/web/domain1.com/www
    I dont want to use ISPadmin > Sites > Sudomain for website. Im migrating 9 domain and one have like 200 subdomains. Also create subdomain ad a directory is much faster for me and it works well on previous hosting (no, I dont have configuration fro there).

    ISPadmin > Sites > Website > Auto-Subdomain (none, www, *.) doesnt helped.

    Im looking for something like mod%rewrite solution since no ISPadmin option is avaliable.
    Like:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^sub.domain.tld [NC]
    RewriteRule ^/(.*)$ /sub/$1 [L]

    but for * (not static domain) and domain1.com > www redirection.

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www
    RewriteRule (.*) http://www.%{HTTP_HOST}$1 [L,R]

    Web root:
    /var/www/domain1.com/web/
    here usually index.htm is.

    ->

    /www (new rood folder for domain1.com and www.domain1.com)
    /<any_folder> (for <any_folder>.domain1.com)

    Simple enough?
    Any help of how to do this? Thanks you.

    PS: I have DNS setup (*,A,CNAME. Every *.domain1.com ends on my server)
     
    Last edited: Aug 16, 2013
  2. xsoft

    xsoft New Member

    Hmm hmm hmm ... done.

    Code:
    # iidx.cz presmeruj na www.iidx.cz
    RewriteRule !^/www - [C]
    RewriteCond %{HTTP_HOST} ^(www\.)?iidx\.cz
    RewriteRule ^/(.*) /www/$1 [L]
    
    # vsechy xxx.iidx.cz hod do adresare /xxx
    #RewriteCond %{HTTP_HOST} !^www.* [NC]
    RewriteCond %{HTTP_HOST} ^([^\.]+)\.iidx\.cz
    RewriteCond /srv/www/iidx.cz/web/%1 -d
    RewriteRule ^(.*) /%1/$1 [L]
     

Share This Page