How do I host my primary domain from a sub-folder by using the .htaccess file?
Frequently Asked Questions • Tehnic | .htaccess | redirected | subfolder | public_html | domain | subdirectoryBy default, the primary domain will use the public_html directory for its files.
Additional domains (addon, subdomains) will use subdirectories inside the root directory.
However, it is possible to host the main domain from a subfolder within the public_html by configuring a redirection in the .htaccess file in the public_html folder, so that the server redirects all requests for the primary domain to that subfolder inside the public_html.
Site visitors won't know that the domain is loading from a sub-folder, which is not added to the URL name.
To perform this operation, the following lines must be added to the .htacces file in the public_html:
#Activate modul Rewrite
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]