Let’s say, you have a website, that is opened by URL: http://ladby.ru. And you want to be able to open it by http://www.ladby.ru also. What should you do? I will describe it now.
In this case www is a subdomain for your website. It is useful usually if you want to have also ftp.ladby.ru for instance. Also it can be useful to redirect from www.ladby.ru so that some users that type your website URL with www will not have any problems accessing it. Here is more information on what is the purpose of the www subdomain.
To achieve this, you should create a CNAME record in your DNS Zone file. Basicly, CNAME record tells where one should be redirected.
I have a record:
1 |
@ IN A 78.47.91.3 |
Here @ sign means basic address: ladby.ru in this case. So when somebody wants to open ladby.ru, he is redirected to the 78.47.91.3 IP address. A-record returns a 32-bit IPv4 address, most commonly used to map hostnames to an IP address of the host.
Also I have added an important record, which is the core of the trick:
1 |
www IN CNAME @ |
So, when somebody wants to open www subdomain, he is redirected to basic address or ladby.ru.
In my case the final result looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
$TTL 86400 @ IN SOA ns1.first-ns.de. postmaster.robot.first-ns.de. ( 2014062605 ; serial 14400 ; refresh 1800 ; retry 604800 ; expire 86400 ) ; minimum @ IN NS robotns3.second-ns.com. @ IN NS robotns2.second-ns.de. @ IN NS ns1.first-ns.de. @ IN A 78.47.91.3 localhost IN A 127.0.0.1 mail IN A 78.47.91.3 ftp IN CNAME www imap IN CNAME www loopback IN CNAME localhost pop IN CNAME www relay IN CNAME www smtp IN CNAME www www IN CNAME @ @ IN MX 10 mail |
Also, you should edit your Apache configuration file this way:
1 2 3 4 |
# cd /etc/apache2/sites-available # vim ladby.conf ServerName www.ladby.ru |
It should not be like this:
1 |
ServerName ladby.ru |