Hide your website subdirectory in your URL

If you have a website in a sub directory and want to point your main URL to it, here's a trick that worked for us.

We had a Joomla site installed in a sub-directory called "home".  This was sitting next to another directory called "dev".  The idea was to have 2 copies of the same website sitting next to each other:  a "development" site for testing, and a "live" production site.

Scanning the web, we found many people offered the following solution, which involves creating a file called ".htaccess" with the following code:

RewriteBase /

# Add trailing slash if path does not contain a period or end with a slash
RewriteCond %{REQUEST_URI} !(\.|/$)
RewriteRule (.*) http://www.yoursite.com/$1/ [R=301,L]

#Change http://yoursite.com to http://www.yoursite.com (Optional)
RewriteCond %{HTTP_HOST} ^yoursite.com$
RewriteRule ^/?(.*)$ http://www.yoursite.com/$1 [R=301,L]
#Rewrites http://www.yoursite.com/subdir to http://www.yoursite.com/
RewriteCond %{REQUEST_URI} !^/subdir
RewriteRule ^(.*)$ subdir/$1 [L]


For the above code, replace yoursite.com with the name of your website & subdir with the sub-directory (e.g. where Joomla was installed).

Then you upload the .htaccess file into your website's home directory (note that there is a dot "." at the beggining of the filename — this is normally required, so if your computer doesn't support this type of file name, name it "htaccess" without the dot, and then use your FTP program or webhost's control panel and you should be able to change the name there).

Nearly every place we found these instructions left our a few extra steps which are important to do:

  1. Make sure your .htaccess file is set as executable (assuming you are running this on a shared UNIX/Linux host).  Most FTP programs support changing the file attributes.  Good rule is to make it user and group executable first, and if that doesn't work, make it world executable.
  2. Most important, make sure your Joomla configuration.php file has the following set:
    var $live_site = '';
    var $live_site = 'http://www.yoursite.com/';
    (Replace yoursite with the name of your website)

For us, it was the 2nd step that made the code work for us!!!

One last point, if you also use Joomla's built-in search engine frienly URL setting using Joomla's .htaccess file (in your Joomla subdirectory), the code in that should work fine with the other .htacess file you put in your host's root directory.  For your Joomla's .htaccess, make sure to us:  RewriteBase /


  • Twitter
  • LinkedIn
  • Facebook
  • StumbleUpon
  • del.icio.us
  • Google Bookmarks
  • MySpace
  • Digg
  • Live
  • Slashdot
  • RSS
  • email
  • Technorati