You can check this by running:
ping hello.domain.com
[root@grossiweb conf]# ping hello.domain.com
code>PING hello.domain.com (62.193.xxx.xxx) 56(84) bytes of data. 64 bytes from my.serverhostname.com (62.193.xxx.xxx): icmp_seq=0 ttl=64 time=0.058 ms 64 bytes from my.serverhostname.com (62.193.xxx.xxx): icmp_seq=1 ttl=64 time=0.040 ms 64 bytes from my.serverhostname.com (62.193.xxx.xxx): icmp_seq=2 ttl=64 time=0.071 ms 64 bytes from my.serverhostname.com (62.193.xxx.xxx): icmp_seq=3 ttl=64 time=0.028 ms
/var/www/vhosts//conf/vhost.conf
ServerAlias *.domain.com
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.* [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com
RewriteCond /var/www/vhosts/domain.com/httpdocs/%1 -d
RewriteRule ^(.*) /%1/$1 [L]
- The first line of mod_rewrite !^www.* only matches urls that don’t begin with www. You don’t want to redirect www.domain.com to www.domain.com/www/ do you? Note: you could add additional lines like these to prevent re-writing other subdomains like secure.domain.com if that should not be redirected to domain.com/secure/
- The second line ^([^\.]+)\.*$ captures into a backreference anything that doesn’t have a period e.g. the subdomain. The plus makes sure that there is at least one character that matches.
- The next condition checked is that the directory captured into the backreference does actually exist hence the -d.
- This last line ^(.*) /%1/$1 [L] takes the requested path and dumps it into a back reference and then rewrites it to point to the a directory (the subdomain backreference captured in the Rewrite conditions above) . In other words %1 is the subdomain backreference and $1 is the path backreference (that captured by .*). The important thing to rember is you can refer to backreferences in rewriteCond lines with % and backreferences in rewriteRules with $. Lastly the [L] (last) means doen’t further rewrite this URL. Note: You might want to leave this out if you are doing any subsequent rewrites, be sure to test what you have set-up thoroughly!!!
/usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=
service httpd restart