Joomla

Organize your public_html directory

Dumping your Joomla files in the root of your public_html directory is so confusing. It creates a big mess of files. There has to be some way to sort things into folders to make it neater. Let me show you how.

Prerequisites

This is an advanced article. You will need a server running mod_rewrite and you must have at least a basic understanding of .htaccess files. I’d also advise you to test this out in a dev environment not a live site. It took me a while to get it right myself, so there is definitely a learning curve. Alright, let’s get down to it.

STOP THE INSANITY!

Set it up

Open up your web servers public_html directory via SFTP. (or ftp if you are old school)  This article is written with the assumption that this is a new account with no files in public_html.

Make a folder called /v1/. Don’t worry, we will hide the directory from showing in your url later in this article using mod_rewrite. Create a .htaccess file in the public_html root as well. For now you can leave it blank.
Now dump your Joomla files from Joomla.org into the /v1/ directory and create your database users via cpanel or phpmyadmin or how you normally do it.

the .htaccess file

Now we need to put some code in your .htaccess file. Our goal is to have our physical files for Joomla in /v1/, however we do not want to see the /v1/ in the url of our site. This is easy with some mod_rewrite magic.

RewriteEngine on

RewriteRule ^$ /v1/ [QSA,L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule !^(forum|blog|wordpress|activecollabs|affiliates)(/.*)?$ /v1%{REQUEST_URI} [QSA,L]

Voila! Now when you go to yourwebsite.com you will actually be accessing the /v1/ directory. Install your Joomla site as you normally would, and not using the /v1/ in the url.

Changing to a new site, or a new version

The best part of this method is now you can have a directory at /v2/ that you can use for creating a new version of your site. When the site is ready to go, you just open up your .htaccess file and change the 2 instances of /v1 to /v2 and now your new site is live and your old site is not.

Mind your configuration.php file

Everything should work fine the way it sits, but don’t forget to change your log_path and tmp_path in your Joomla configuration.php file. They should be the actual path , not the fake path we are creating with .htaccess.
For example:

var $log_path = '/home/website/public_html/v1/logs';
var $tmp_path = '/home/website/public_html/v1/tmp';

Dev site, test site, new versions, anything is possible

By setting your public_html directory up like this, you are creating all sorts of space and room for freedom. You can make a directory at /dev/ and then duplicate your main site into it. Now you have a place to test new plugins or upgrades without tinkering with your live site.

public_html_done_right

Security and Googlebot

Naturally search engine spiders will want to look over your new directories. Chances are you don’t want Google to be sniffing into your dev or future site builds, so it’s best to block then from snooping around. You can create a file called robots.txt and put this into it.

User-agent: *
Disallow: /dev/
Disallow: /v2/
Disallow: /freakydeekystuff/
Disallow: /cgi-bin/

Ultimately however, if you really don’t want anybody goofing around in those directories you need to just disable the site in configuration.php or create a .htaccess password using cpanel. Much like the lines on the road, robots.txt is just a guideline for search engines.

How do you do it?

This is how I organize my web server directories, how do you do it? Do you have a better method?

11

Merav

Merav Knafo is the founder and CEO of iJoomla, Inc. She loves writing about Joomla, usability and Social Networking.

Leave a comment

  • Avatar

    ErnestMarcinko

    |

    Now this is a useful article! I never knew how to organise my public_html directory, It is always a mess 😀
    http://offlajn.com

    Reply

  • Avatar

    MaryHolickStremmel

    |

    the only issue I have with this tutorial is that the live sites I have residing in sub-folders do not rank as well in Google no matter what else I do.  The seo will always improve after pulling them out of a sub-folder and putting them in their own cPanel.  I am moving to a reseller account where I can have unlimited cPanels.

    Reply

    • Avatar

      columbusgeek

      |

       @MaryHolickStremmel HI Mary
      With this method your sites are sorted into subfolders, but the mod_rewrite displays them without said folder.   This is transparent to Google and will have zero effect on SEO.

      Reply

      • Avatar

        MaryHolickStremmel

        |

         @columbusgeek  ok I will give that a try too and see what happens especially for some of my clients that have more than one site… thanks for the reply.

        Reply

  • Avatar

    MaryHolickStremmel

    |

    I do like the robots.txt part of the tutorial though.  With this I can keep the robots out of the sites under development.  (I was doing it correctly before)

    Reply

  • Avatar

    MaryHolickStremmel

    |

    is this necessary and what does is mean?
     
    RewriteRule !^(forum|blog|wordpress|activecollabs|affiliates)

    Reply

    • Avatar

      columbusgeek

      |

       @MaryHolickStremmel It’s directories that will be ignored by the mod_rewrite rule.

      Reply

  • Avatar

    EPrabidhiKathmandu

    |

    Thank you for the marvellous article. Now, it has become easy to organize my files in good order.

    Reply

  • Avatar

    ALnews

    |

    it is a bit difficult to understand first but if you follow the steps described here at the end you will have a better organized directory
    http://www.lajm-shqip.com
     

    Reply

  • Avatar

    MaryHolickStremmel

    |

    well, can’t make it work get 500 server error, found other tutorials but they all show the sub folder 🙁

    Reply

  • Avatar

    uglyeoin

    |

    Not entirely something I’d find a use for.  Ages ago I set up a completely different testbed domain because I wanted to avoid any issues of accidentally messing up a live site.  However, I’m sure many would find this useful (probably more careful than me), and cheaper.  I do have one question though, is it more secure not to have your site in the public_html folder?

    Reply