cPanel – How to put all Domains in the same Folder

cpanelIf you’ve ever used cPanel you probably know that each account is tied to a default domain for that account.. you can add more domains to each account but these will be seen as additional domains..
This idealogy has always annoyed me.. because it also means that your default domain is bound to the public_html folder and all other domains can have either that folder or any sub folder as it’s homedir.. but I want all my domains in the same folder, not one “default” domain as the main folder and put all other domains in a subfolder of that domain.. where’s the logic in that?

So I used htaccess to have mod_rewrite redirect the main domain to the “domains” folder… which is the same folder all my other domains use, this way I can have things the way I like.

Here’s the code that you put right inside your public_html folder;

<IfModule mod_rewrite.c>
RewriteEngine On
ReWriteCond %{HTTP_HOST} naatan.com
ReWriteCond %{DOCUMENT_ROOT} !domains/
ReWriteCond %{DOCUMENT_ROOT} !subdomains/
ReWriteRule ^(.*)$ domains/naatan.com/$1 [L]
</IfModule>

Of course you’re gonna want to replace naatan.com with your domain..

Note that I am placing an ignore on the domains and subdomains folder, seeing as it would keep redirecting indefinitely if I didn’t put that on the domains folder, and I want to have my subdomains in their own folder as well.

Now you can still use htaccess in the main domains folder, but as it’s home directory  is different from the directory the files are actually in (thanks to mod_rewrite) you need to base the path on the homedirectory.. so my .htaccess file for my default domain looks like this;

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /domains/naatan.com/index.php [L]
</IfModule>

And voila, I got all my domains in one folder..

I am still hoping for cPanel to allow you to customize this some day.. but it doesn’t seem like this limitation bothers the developers behind cPanel much.

On a small side note, I’ve had a bit of trouble with wordpress admin redirecting after a login using the method described above.. but by simply logging in and then manually entering the wp-admin url it all works fine. Even so, if anyone knows a better way of going about this, I’d love to hear it.

4 Responses to “cPanel – How to put all Domains in the same Folder”

  1. David says:

    I keep getting a 500 internal server error when I try this. When I make the [L] into [L,R] (for a redirect), it gets stuck in an eternal loop.

    I’m on a lunarpages server, and want to organize all my domain names… Any tips??

    Thanks!

  2. David says:

    In addition, it says it can’t find the file when I try this:

    http://forums.powweb.com/showthread.php?t=40454

  3. David says:

    FYI, I found the problem. Here’s the code that works for me:

    RewriteEngine On
    Options +FollowSymlinks
    RewriteBase /

    RewriteCond %{HTTP_HOST} youdomain.com
    RewriteCond %{REQUEST_URI} !domains/
    RewriteRule domains/$1 [L]

    Notice the difference in the last line:

    ReWriteRule ^(.*)$ domains/naatan.com/$1 [L]

    and

    RewriteRule domains/$1 [L]

    I had to remove the ^(.*)$ at the beginning, since that was adding a / to the beginning of the path, making the server look in /domains/yourdomain instead of the public_html/domains/yourdomain

    Thanks for the tips though!

  4. David says:

    ok what the heck. now it randomly stopped working. sorry for the bad advice – I guess I’ll stop running a commentary on here

Leave a Reply

:) ;) :D :| :( :O :P