🍁 Autumn Sale — Up to 70% discount for hosting and domains
activate now
Frequently Asked Questions • Dev

How can I host my main domain from a sub-folder using the .htaccess file?

In this article, we will explain how to host the main domain in a sub-folder using the .htaccess file.

Views 1162Updated 7 aniPublished on 26/06/2019by Alexandru J.

By default, the main domain will use the public_html directory for its files.
Additional domains (addon, subdomains) will use subdirectories within the root directory.

However, it is possible to host the main domain from a subfolder within public_html by setting up a redirect in the .htaccess file in the public_html folder, so that the server redirects all requests for the main domain to the respective subfolder within public_html.

Website visitors will not know that the domain is loading from a subfolder, as this will not be added to the URL name.

To perform this operation, the following lines will need to be added in the file.htaccess, from public_html:

#Activate Rewrite mode
RewriteEngine on

#Replace "domeniu.ro" with the desired domain
RewriteCond %{HTTP_HOST} ^(www.)?domeniu.ro$

#Replace "subfolder" with the name of the subfolder used.
RewriteCond %{REQUEST_URI} !^/subfolder/

#Do not change these lines
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#Replace "subfolder" with the name of the subfolder used.
RewriteRule ^(.*)$ /subfolder/$1

#Replace "domeniu.ro" with the desired domain
RewriteCond %{HTTP_HOST} ^(www.)?domeniu.ro$

#Replace "subfolder" with the name of the subfolder used and index.html with the desired default page.
RewriteRule ^(/)?$ subfolder/index.html [L]

Similar Articles

Views 1,162
Updated 7 years ago

In this article, we will explain how to host the main domain in a sub-folder using the .htaccess file.

Views 1,836
Updated 2 years ago

The .htaccess file is an essential tool for configuring the Apache server, allowing for redirects, protecting directories, and managing access.

Views 1,152
Updated 5 years ago

Can't find the .htaccess file in FileZilla? Enabling the "Force Showing Hidden Files" option from the Servers menu will help you view hidden files.