How to Create Home Page for a Subdomain?
It is common practice among webmasters to host media content separately in a subdomain to increase the parallel HTTP requests in order to improve the site speed. In such scenario the main domain will have WordPress installation with all required root directories but the subdomain on which the media files are stored will not have a landing page and hence show 403 access forbidden message when someone tries to access it directly.
In this article we will discuss how to create a landing page for a subdomain without installing any additional software. The basic assumption here is that your hosting server is PHP enabled like the one needed for WordPress.
Let us take an example of this very own site; we have moved all media files to a separate subdomain. Below is an image of the subdomain home page which is stored in a subdomain and can be directly accessible using the URL https://img.webnots.com/2015/06/Subdomain-Home-Page.png.
What if someone try to view the subdomain https://img.webnots.com? Ideally it will show access forbidden error since it has no individual home page. This may not look professional and the minimum need is to inform the visitor to check the main domain for more details.
How to Create a Landing Page for WordPress Subdomain?
The landing page or home page can easily be created by adding an index.php file inside the subdomain folder (inside img directory in our case). You can add any customized HTML code inside this index.php file to show the desired message to those who views the subdomain URL.
Step1 – Creating index.php File
In order to create a new file inside subdomain folder you need to have an access to your cPanel hosting account or FTP access to your hosting server. Access the subdomain folder and create a new file named “index.php” inside the folder.
Index.php is the file informing any PHP enabled web server to run the PHP scripts before sending the HTML response to the browser’s HTTP request. Now that you have added a PHP file the next step is to inform server what to do when someone request the subdomain URL.
Step2 – Adding HTML Inside index.php
This is a custom step and you can add any type of content inside index.php file which you want to show on the subdomain’s home page. Here we want to show some simple message and a search box as you can see in the home page of our subdomain. Add the below code inside index.php file and replace the highlighted parameters like title, URLs, etc. with your own.