cPanel
Domain
Manager
Upgrades
Postini
Dedicated
IP
SSL
Certificates
Profile/
Billing
Checkout
HELP



Knowledgebase

How to host the Primary Domain from a subfolder (.htaccess)


Problem:

How do I make a sub directory (or sub folder) act as the public_html for your main domain?

Solution:

The main domain on the hosting account uses the public_html directory for all of its Web site files. Addon domains use sub directories inside the public_html directory. In order to also set up your main domain to use a subdirectory on your hosting account you will need to set up a redirect in the .htaccess file in the public_html folder so that the server knows that any request for your main domain will be redirected to a subdirectory on public_html.

To setup the rewrite/redirect, edit the ~/public_html/.htaccess file. Insert the following code block and make modifications as noted in the (#) comments.


  # Fastdomain.com
  # .htaccess main domain to subdirectory redirect
  # Copy and paste the following code into the .htaccess file
  # in the public_html folder of your hosting account
  # make the changes to the file according to the instructions.
  # Do not change this line.
  RewriteEngine on

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

  # Change 'subdirectory' to be the directory you will use for your main domain.
  RewriteCond %{REQUEST_URI} !^/subdirectory/

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

  # Change 'subdirectory' to be the directory you will use for your main domain.
  RewriteRule ^(.*)$ /subdirectory/$1

  # Change yourdomain.com to be your main domain again.
  # Change 'subdirectory' to be the directory 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 ^(/)?$ subdirectory/index.php [L]

Visitors to your Web site will not be able to tell your main domain is using a subdirectory. They will still see the Web site address as http://www.yourdomain.com/page.html.
Keywords:.htaccess redirect subfolder sub-folder root

Home  |  Awards  |  Hosting Features  |  Help Center  |  Contact Us  |  About Us  |  Domain Check  |  Affiliates | Terms
© 2006-2010 FastDomain.com. All Rights Reserved