23
Jan
2009
Hide Joomla Subdirectory (Subfolder)

Instead of installing Joomla in the web root (public_html), some like to put
the Joomla files in a subfolder for better housekeeping.

It's cleaner to see folders when you list publc_html and not all
the Joomla files, especially if you have other server applications
installed such as blogs, forums, etc, or have created folders for
add-on or sub domains.

When Joomla is installed in a subdirectory the appearance of the
subfolder in urls may be undesireable.

mod_rewrite can remove the subfolder from the url.

http://domain.com/joomla/index.php
will become
http://domain.com/index.php

Below are two different examples. If one does not work try the other. Using bits of each might work too.

 

Example1:

1. edit the file joomla/configuration.php

In Joomla 1.5 var live_site is empty by default

Change
var live_site = '';
To
var live_site = 'http://www.domain.com';

(In Joomla 1.0 you would be looking in the same file for $mosConfig_live_site =)

 

2. Edit or create the file named .htaccess (invisible files begin with a period) in

your webroot (not the one in the joomla subdirectory) and change its content to: 

 

Options +FollowSymlinks
RewriteEngine on

RewriteBase /
 
# Add trailing slash if path does not contain a period or end with a slash
RewriteCond %{REQUEST_URI} !(\.|/$)
RewriteRule (.*) http://www.domain.ca/$1/ [R=301,L]
 
# Change http://yoursite.com to http://www.yoursite.com
RewriteCond %{HTTP_HOST} ^domain.ca$
RewriteRule ^/?(.*)$ http://www.domain.ca/$1 [R=301,L]
 
# Exclude any subdirectories in the site root that should NOT be affected.
# include the Joomla subdir
# best not to use directories in your site root that also exist in joomla e.g. images
RewriteCond %{REQUEST_URI} !^/subdir
#or separate multiple directories with |
#RewriteCond %{REQUEST_URI} !^/(dir1|dir2|dir3)


#if you have other domains (add-on domains) they should be added here to not affect
RewriteCond %{HTTP_HOST} !^otherdomain.ca$


#Rewrites http://www.domain.ca/ to http://www.domain.ca/subdir
RewriteRule ^(.*)$ subdir/$1 [L]

 

#Replace domain.ca with your domain and subdir with the name of the subdirectory in which you have installed Joomla.

-------------------------------------------------------------------------------------------------

Example 2:

The example below does not require listing of folders to be omitted and only affects specified domain, but did not work for me in IE8.

 

1. edit the file joomla/configuration.php

In Joomla 1.5 var live_site is empty by default

Change
var live_site = '';
To
var live_site = 'http://domain.com';
 

2. Edit or create the file named .htaccess (invisible files begin with a period) in

your webroot (not the one in the joomla subdirectory) and change its content to: 

Options +FollowSymlinks
RewriteEngine on

# remove "www"
RewriteCond %{HTTP_HOST} ^www.domain.ca$ [NC]
RewriteRule ^(.*)$ http://domain.ca/$1 [R=301,L]

# Redirect to the Joomla root folder
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.ca$ [NC]
RewriteRule ^(index\.html)?$ http://domain.ca/subdir/ [R=301]

# Only apply to URLs on this domain
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.ca$

# Only apply to URLs that aren't already under folder
RewriteCond %{REQUEST_URI} !^/subdir/

# Don't apply to URLs that go to existing files or folders
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all those to insert /subdir
RewriteRule ^(.*)$ /subdir/$1 [L]

#Replace domain.ca with your domain and subdir with the name of the subdirectory in which you have installed Joomla.

 

Joomla Announcements

  • Joomla Community Magazine | October 2011
  • Joomla Community Magazine | September 2011
  • Joomla! Explained - Second Joomla Press Book Released
Joomla Web Hosting Canada RSS Feed