Create a Subdomain and Point it to a Folder in cPanel
This tutorial explains the subdomains function in cPanel, which lets you create a subdomain — a domain with an extra prefix that operates separately from the original domain. You could make a blog for your site (example.com) with an address of “blog.example.com” — or a landing page, forum, app page or any number of other variants. Read below for instructions on how to make a subdomain in cPanel and your domain provider.
Add domain in cPanel
Log in to cPanel and search for the Domains section. Within this section click on the Subdomains.
If you don’t have any current sub domains active, you will be prompted to create a new one. Enter a subdomain name of your choice (blog, forum, app, info, etc.) and select the main domain from the drop down list. Then click Create.
Congrats! Your first subdomain is now created! 😎
How/Where to add subdomain files?
Older versions of cPanel required a subdomain’s files to be stored in the parent domain’s directory. This is no longer the case. The latest security and privacy practices recommend that you do not place a domain or subdomain inside of another domain’s directory. cPanel, by default, will create a new, separate directory for your subdomains in your home folder.
From cPanel navigate to File Manager and look for a folder with your subdomain URL in its name.
This is where you can drop your website files and they should now reflect on your subdomain site.
Tip 1. Redirect your newly created subdomain to HTTPS
By default the newly created subdomain’s folder in cPanel is empty, which means it has no .htaccess file. If you already have installed SSL certificate on your main domain, you would probably want to have your subdomain to open with https as well. For this you need another .htaccess file in that folder.
You can copy this file from your public_html folder. For this, also make sure you have all the hidden files visible.
Once you have .htaccess in your subdomain folder, edit it and add the following code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
You can erase all the existent code from the copied file and replace with the one above. This should redirect your subdomain to https.
Tip 2. Add a subdomain to your DNS records
If for some reason, after adding a new subdomain to cPanel you still cannot access your content by its path, you should consider adding a new A record to your domain’s DNS settings.
To do so, login to your domain provider website, for example GoDaddy and search for domain’s DNS records. Add a new A record with the name of your subdomain (same as in cPanel), point it to your hosting IP address (same as @ name), set the TTL and click save.
Please, be aware that it may take from 8 to 24 hours for the DNS to propagate across all the server nodes in the world.
If you encountered any issues down the path or you need help with your website, don’t hesitate to contact Raptor Media team. Our web experts will answer your questions or concerns and will provide the best solution possible to achieve the desired result.