How To Host The Main Domain Pointing To Subfolder?

Main Domain Pointing To Subfolder

Table of Contents

It’s been awkward to keep all the main domain files maintaining under public_html directory. So here is a solution to organize your main/primary domain pointing to a subfolder.

Simply Follow These Steps To Host Primary Domain Point To Subfolder:

Step 1: Log into your web host service provider and go to “FILES” section.

Files Manager
Files Manager

Step 2: Create a subfolder for your ‘primary domain’ under public_html directory. For Example: ‘first’, this could be your main/primary domain name of the website.

File Manager htaccess
File Manager htaccess

Step 3:Now Edit your .htaccess file under the public_html directory from the web host File Manager Directory Section. This file will be stored as hidden, so you need to select the option ‘Show Hidden Files’ from the File Manager.

File Manager Directory Selection
File Manager Directory Selection

Step 4: Right click the .htaccess file and choose as “Code Editor”

Step 5: Add the following code to your .htaccess file in the public_html folder of your hosting account.

Please note: You will need to insert the following code and make modifications as noted in the (#) comments.

[php]

# .htaccess main domain to subdirectory redirect

# Do not change this line.
RewriteEngine on

# Change yourdomain.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$

# Change ‘subfolder’ to be the folder you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subfolder/

# Don’t change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Change ‘subfolder’ to be the folder you will use for your main/primary domain.
RewriteRule ^(.*)$ /subfolder/$1

# Change yourdomain.com to be your main domain again.
# Change ‘subfolder’ to be the folder you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.

RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$
RewriteRule ^(/)?$ subfolder/index.php [L]

[/php]

Now visitors to your Website will not be able to tell that your main/primary domain is using a subdirectory in your web hosting.

Share it...

WhatsApp
Facebook
X
LinkedIn
Picture of WPChats
WPChats

We focus on in-depth, practical reviews of WordPress themes, plugins, and tools, testing them from a real-world perspective—performance, scalability, developer experience, and long-term usability.

Search

Visual Page Builder

Recent Updates

Also, Check our Recommendation

10 Effective Web Design Tips for Building Exceptional Websites

There was a time when building a website was a very challenging as well as expensive task. But the situation is no longer the same; ...
Customer Relationship Management

4 Reasons To Invest in a CRM System To Grow Your Business

When you hear the word CRM (Customer Relationship Management), a number of things must come to your mind. First of all, we all know that ...

7 Best Practices for a Memorable Ad Design

It is not that simple to market a product and create an image in the mind of the buyer. You need to think out of ...

How to Create a Unique Brand Identity in 2020?

Right now, age, consumers are gaining more force than any other time in recent memory inside the business scene. Because of the high immersion of ...

5 Tips for Successful Integration of Your eCommerce With an ERP Solution

ERP software and eCommerce are a match made in heaven! How so? There are many reasons why, but the following four examples is enough to ...

7 Best Slogan Generators for Your WordPress Website

Nike’s “Just Do It”, McDonald’s “I’m Lovin’ It” or Apple’s “Think Different” are slogans we can all quote without hesitation. When we hear those words, ...

4 Common SEO Mistakes to Avoid

By now, you know that SEO – search engine optimization is an extremely effective way to generate traffic to your website. However, if you aren’t ...
Holiday E-commerce Strategy on Social Media

How to Create a Perfect Holiday E-commerce Strategy on Social Media?

Do you have started working on your holiday eCommerce strategy? If not, it is high time to pull up your socks as the holiday season ...