How to Change Your Website Root Directory with .htaccess file

Home / Website Design and Management / htaccess file / How to Change Your Website Root Directory with .htaccess file

IF your website is using cpanel system, your website root directory should be /home/yourusername/public-html directory. When anyone want to visit your website, the apache server will direct it to the index file in your /home/yourusername/public_html folder.

But you can change it to  different directory by .htaccess file. Just place following codes into your .htaccess file:


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

In the above lines you should replace the following 2 strings:

domain-name.com – Type your own domain name
folder – custome the folder which hold your website

Leave a Reply

Your email address will not be published.