Your Gateway To Digital Success
Wesbytes Blue Logo

Wesbytes Knowledge Base

Search our articles or browse by category below

How to Change the Root Directory of Primary Domain with .htaccess

Last modified: June 17, 2022
You are here:
Estimated reading time: 1 min
Linux VPS Server

If you have a website installed for the primary domain of your hosting account. By default your website is loaded from the public_html folder. Public_html is the root folder for the primary domain. Besides that, we also call it web root folder or document root directory.

If your website is located in a sub-folder of the document root and you want to display it when typing your domain name, here is what you should do. Firstly, you need to edit the .htaccess file in your public_html folder. If you cannot find the .htaccess, it is possible that the file is hidden. Then you can create one.

Adding rules

In the .htaccess file, you need to add the following rules to redirect the root folder:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^$ [NC,OR]
RewriteCond %{HTTP_HOST} ^$
RewriteCond %{REQUEST_URI} !folder/
RewriteRule (.*) /folder/$1 [L]

Replacing the lines

You should replace the following 2 strings in the lines above: – Type the domain name in question.
folder – Type the name of the sub-folder which the website is located in.

After you have added the code and saved the .htaccess file, open your domain name in a browser and you should see the website which is in the sub-folder.

Was this article helpful?
Dislike 0
Views: 19