I'm getting an issue creating a sub directory behave as the general public_html for my primary domain, and becoming an answer that actually works with this domain names sub sites too.

Background

My hosting enables me to host multiple sites, that are all working great. I've setup a subfolder under my ~/public_html/ directory known as /domain names/, where I produce a folder for every separate website. The folder structure on my small server looks something similar to this:

  • public_html
    • domain names
      • websiteone
      • websitetwo
      • websitethree
      • ...

This prevents my sites nice tidy. The only real problem was getting my "primary domain" to suit into this technique. It appears my primary domain, is in some way associated with my account (in order to Apache, or something like that), and so i can't alter the "document root" of the domain. I'm able to define the document roots for just about any other domain names ("Addon Domain names") which i include cPanel not a problem. However the primary domain differs.

The issue

I had been told to edit the .htaccess file, to redirect the primary domain to some subdirectory. This appeared to operate great, and my website works fine on it's home/index page.

The issue I am getting is when I attempt to navigate my browser to express the pictures folder (just for instance) of my primary site, such as this:

world wide web.yourmaindomain.com/images/

it appears to disregard the redirect and shows the whole server directory within the url, such as this:

world wide web.yourmaindomain.com/domain names/yourmaindomain/images/

Still it really shows the right "Index of /images" page, and shows their email list of my images. It is simply the "pretty" URL this is the problem.

Illustration of my .htaccess

RewriteEngine on

RewriteCond % ^(world wide web.)?yourmaindomain.com$

RewriteCond % !^/domain names/yourmaindomain/

RewriteCond % !-f

RewriteCond % !-d

RewriteRule ^(.*)$ /domain names/yourmaindomain/$1

RewriteCond % ^(world wide web.)?yourmaindomain.com$

RewriteRule ^(/)?$ domain names/yourmaindomain/index.html [L]

Performs this htaccess file look correct? I simply need to allow it to be so my primary domain reacts as an addon domain, and it is subdirectories follow the redirect rules.

Avoid using mod_rewrite for your, use virtual hosts for your. I will not explain that here at length, you will find all of the information you need in the above link. (Hint: You will need the title-based ones most likely.)

You most likely wish to move your stuff from ~/public_html/ to more generic place like /var/world wide web/ or /srv/world wide web.

On top of that: Avoid using .htaccess files on production.