How to use Wild Card Domain
I need a subdomain resolution to a wildcard setting for a project. By this when a visitor put any subdomain he will be directed to the main domain. Every vistior who try to get an subdomain will get my main domain on his browser. I need to know the steps to enable and to setup a wildcard subdomain on a cpanel server. How to configure it and setup an new wildcard domain.
Re: How to use Wild Card Domain
It is not quiet easy to setup a wild card domain. To setup a wild card domain on your Cpanel server you will need to do this. Do the following steps :
First thing you must have a access to the Edit DNS Zone on your server. Whether it si WHM or Cpanel. You will get this option under DNS functions. Click on Edit DNS Zone. Select the domain of your choice to use. Do not edit any of the server in the list. Just the only you need to. Go down and look for Add New Entries Below this Line. Put * in the first box, followed by your server IP address in the place of 65.66.67.68.
The second part is to connect to your sever through SSH. You can use a simple tool call Putty to access it. If you have any other tool you can use that also. The idea is that you must have a program that is capable of accessing a server through SSH. Now launch the Putty tool. In the Putty configuration window enter your server's IP address. The port should be 22, unless you've configured your SSH access to another port. Click on Open. Now type the following text into Putty window :
* login as: username
* password: password
* enter: cd /etc/httpd/conf/
* enter: pico httpd.conf
* press: ctrl w
* enter: youdomain.com
Now edit the line : ServerAlias yourdomain.com to: ServerAlias: *.yourdomain.com yourdomain.com. Now click ctrl x to exit. Save your work. Now you are done with configureing your server to use a wildcard dns for your subdomain.
At last you to get your wildcard subdomain name with PHP
PHP Code:
$serverhost = explode('.',$_SERVER["HTTP_HOST"]);
$sub = $serverhost[0];
if ($sub = "www") {
$sub = "";
}
Insert the above php code in your main php file. By the above code use appropriate setting for your sub domains.
Re: How to use Wild Card Domain
To setup you Wildcard Subdomain do this :
- Login in your CPanel
- Search for DNS Zone > Edit DNS Zone
- Select a Domain > Add New Entries Below this Line.
- Now you will need to put a * in the first box and choose A from the list.
- Add your server IP address in the next field.
- Go to Cpanel and select Subdomains menu use * in place of the subdomain prefix/name. Select to Add Subdomain.
Configure your subdomains.
Re: How to use Wild Card Domain
I am giving you a very simple steps to setup your own wildcard domain. Just after configuring the below setting you will be able to use your own wildcard domain.
Go to DNS control > A Record > Enter your IP Domian Address.
Then Select Admin Level > Custom Httpd configurations > domain.com
In the top text area, add this *one* line: ServerAlias *.|DOMAIN| then click “Save”.
Then wait for a while.
The wildcard subdomains will point to your main public_html directory for the domain.