There is always some confusion between a sub-domain and sub-directory. They are very different from each other and works differently. In this article, we covered the basic differences between them and how you can implement them on a local server for testing purposes. This sub-directory or sub-domain concept on a local server or live site is termed as WordPress Multisite.
Before starting up the environment setup, let’s know a pinch about them, shall we?
What is Sub-Directory?
A sub-directory is a part of your website which shares a different database in your core WordPress directory. It’s a folder/directory in your WordPress Installation directory which have its own WordPress Installation or any other website. You can create as many sub-directories as you want.
The URL following for the Sub-Directory is as follows:
What is Sub-Domain?
A sub-domain is a little bit different from a sub-directory and a little bit tricky to setup. Nowadays, most of the domain providers allow you to create multiple but limited sub-domains of your website. It is a whole different website acquiring its own database and website design but as a child of your main site.
The URL following for the Sub-Domain is as follows:
You can choose between these two to expand your website according to your need. For example, if you want to open up a small blog then a sub-directory would be the best fit for you. But if you want to expand your business in different countries then a sub-domain will work great for those site management.
Local Server Setup
For local server environment setup with in-build WordPress Installation, we used Local by FlyWheel, you can choose any other local servers such as WAMP or XAMPP and install WordPress in them manually.
Local by FlyWheel allows you to create Multi-Site with just click of a button. And you will not have to worry about the database management for your WordPress website or Multisite.
Setting Up Sub-Directory on Local
For creating a sub-directory follow the given procedure:
- Create a new site and choose a name for your site.
- Now select your PHP version and MYSQL database version and your web-server, you can select between Apache and Nginx web-servers from the custom tab.
- Now choose your admin username and password.
[Most Importantly]: Choose advanced options and choose Multisite as Sub-Directory from the dropdown.
- Click on Add Site. This will create your Multisite with subdirectory along with WordPress Installed.
- Now Go to your Network Admin Dashboard.
- Hover Over ‘Sites’ and choose ‘Add New’.
We are almost done. Now you are ready to check your sub-directory website with your-site-URL/your-sub-directory-name.
But how you would access it from the front-end of your website? It’s pretty simple, you just have to add a new page from your main-site dashboard and change the permalink to your sub-directory link.
Setting Up Sub-Domain on Local
Environment setup of a sub-domain on any local server or even live server is a bit difficult in comparison to a sub-directory. For setting up the sub-domain in your Local follow the given steps:
- Create a New Site, same as the sub-directory steps but with WordPress Multisite as a Sub-Domain from the dropdown menu in Step 3.
- Go to your Network Admin Dashboard.
- Hover over ‘Sites’ and choose ‘Add New’
- Fill up the form and you are ready to go to your sub-domain of your main-site at your-sub-domain-name.your-main-site-name.com
For Accessing your sub-domain Landing Page from front-end.
Go to your main-site dashboard. Hover over ‘Pages’ and select ‘Add Page Link’.
Fill out the required information as you want. The newly created page will automatically be added to your menu at the front-end.
One More Important thing, After creating a sub-domain on your local server, you would have to sync or add you sub-domains in your host’s file. To do so, click on ‘Sync Multi-Site Domains to Hosts File’ option on Local otherwise, you will encounter an error “Site can’t be reached” while accessing your subdomain.
NOTE: If the sync button will not work, you would have to restart the ‘Local’ with Administrative Privileges. To do that,
Right-click on Local > Properties > Compatibility Tab.
Check on ‘Run this program as an administrator’.
Creating a sub-domain or a sub-directory is very useful for our online businesses in many ways. For example, if you have a ‘development-in-progress’ site which is not complete yet, you can create a sub-directory for it and have it stored on your server’s root installation and launch it whenever you want.
In conclusion, you can set up your own sub-domain or sub-directory websites on your local website also. If you are having any issues in implementing the above steps you are very welcome to ask them in the comment box below.