View Single Post
Old 28th April 2007, 12:32
radim_h radim_h is offline
Senior Member
Join Date: Jan 2007
Location: Prague, Czech
Posts: 426
Thanks: 34
Thanked 26 Times in 21 Posts
Send a message via ICQ to radim_h
Default user names as subdomains - HOWTO

I think this can interrest someone:

It used to drive me crazy have user names in format
wanted them as http://user.domain.tld (third level domain)

so here is how to do it

1. in Ispconfig go to Management->System Config->Settings->ISP manager
change User Prefix to [DOMAIN]_
then user dirs will lok like http://www.domain.tld/users/domain.tld_user

2. Create file /etc/httpd/user_rewrite.conf which includes

RewriteCond %{SERVER_NAME} !^www\.
RewriteCond %{SERVER_NAME} !^mail\. ( not neccessary see bellow)
RewriteCond %{SERVER_NAME} ^([^.]*)\.(.*\..*)$
RewriteRule ^/(.*)$ /var/www/www.%2/user/%2_%1/web/$1 [L]

You can create as many lines like "RewriteCond %{SERVER_NAME} !^www\." as you want
^www\. here means that www.domain.tld will not rewrite (will not be looking for directory http://www.domain.tld/users/domain.tld_www, but show www.domain.tld) In my case i'm using also rewrite to show webmail as mail.domain.tld for each domain so i also have
RewriteCond %{SERVER_NAME} !^mail\.

3. In ISP manager->sites click on your site, then go to "Co-domains" and add
yourIP * domain.tld

6 In ISPmanger->sites-> www.domain.tld ->Basic put "Include user_rewrite.conf" into Apache Directives (Optional):

If you have more domains and don't want to forget do this for each domain, change:
Management->Form Designer->Edit Form->isp - ISP Web:->edit->web_httpd_include->Edit and put Include user_rewrite.conf into Default: window

5. In DNS manager ->domain.tld-> records you must create
CNAME * domain.tld

6. probably not necessary, but you can restart apache "apachectl restart"

and you are done

If you want to have mail.domain.tld for each domain showing your default webmail
must have in DNS for your site
CNAME mail yourwebmail.yourdomain.tld
and your /etc/httpd/user_rewrite.conf should look like this

RewriteEngine on
RewriteCond %{SERVER_NAME} ^mail.*.*$
RewriteRule .* /var/www/path_to_your_webmail_site/web$0 [L]
RewriteCond %{SERVER_NAME} !^www\.
RewriteCond %{SERVER_NAME} !^www2\.
RewriteCond %{SERVER_NAME} !^mysql2\.
RewriteCond %{SERVER_NAME} ^([^.]*)\.(.*\..*)$
RewriteRule ^/(.*)$ /var/www/www.%2/user/%2_%1/web/$1 [L]

It works for me, i have configured webmail outside ISPconfig apache, if you use some webmail inside ispconfig in /home/admispconfig/ispconfig/web/yourwebmail it may not work (haven't tried)

Just have 2 questions for Falco or some other developer here .)

1. is there more ellegant way how to include user_rewrite.conf for all domains?
It didnt work for me to include in httpd.conf for all domains at once, its working just when included for each Virtual Host separatelly

2. Can i change default DNS entry for domains without editing code?
In my case i like to have DNS for all domains by default like this:

A Record
empty (domain.tld is already included in zone file but not showed in DNS manager)

Hostname Target
* mydomain.tld
mail mail.myhosting.tld

Mailserver Hostname

(by default it shows MX admin.myhosting.tld which is wrong for me i have admin on different ip adress then users webs)

Last edited by radim_h; 16th May 2007 at 19:46.
Reply With Quote
Sponsored Links