I would like to provide a more complete overview and solution to this topic. I know little about the Apache Web Server .htaccess commands. Like many other Joomla enthusiasts I use the .htacess code by recommendation and trail and error.
Recognize that installing Joomla in a subdirectory is advantageous from a file management persepctive for certain users. I have several (minor) websites, document directories, and other functions as subdirectories of my root directory. It would be quite a mess if all of these were in the root, and not organized into subdirectories.
The redirect command can be used in the .htaccess file so that your yoursite.com/subdir can be accessed directly with redirect command in the .htacess file.
Definitions www.yoursite.com -- your website domain name
subdir - the subdirectory in which Joomla is installedCode:
##The following line is to redirect http://www.yoursite.com/index.htm
#to http://www.yoursite.com/subdir/index.htm
Redirect 301 /index.htm http://www.yoursite.com/subdir
.
.
# change RewriteBase / (root) to the subdir in which Joomla is installed.
RewriteBase /subdir
A drawback of Joomla in a subdirectory is that the website shows as:
http://www.yoursite.com/subdirA couple of the previous posts addressed ways to circumvent this limitation. Instead of the redirect command, DipDog3 and YoungMonkey built on an alternative approach.
I have this alternative functioning on three websites, one of which is fairly complex all based on Joomla 1.5.9. The websites use SEF URLS, Mod Rewrite, and they have Community Builder (CB) installed. I mention these options and extensions because there were problems with them. Also I should mention that our websites are all on GoDaddy Shared Hosting Accounts.
The .htaccess code I used was a hybrid between the code suggested by DipDog3, YoungMonkey, and other code I have found posted on this forum.
Here is the code with comments annotations and revisions. In total you are adding eight NEW lines of code as shown below. My comments are preceded with ##. Original are preceded by #.
Code:
# The following line can be commented out if causes errors.
##I did not find this to matter so I left it uncommented
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
## The configuration in the three lines above and two lines of code that follow are from the DipDog3 reference.
## The following section must come next immediately after the Rewrite Base command!
###BEGINNING OF SECTION###
#This masks the Joomla Subdir name in the URL and allows access to other subdirectories in the root
# Add trailing slash if path does not contain a period or end with a slash
##(after $1 in second line - you may need to test the need for this by trial and error).
RewriteCond %{REQUEST_URI} !(\.|/$)
RewriteRule (.*) http://www.yoursite.com/$1/ [R=301,L]
##I don't remember who I copied the following from but use it and not the code from
##the previous source because it didn't rewrite for http://yoursite.com. Use the following.
#When somebody links to your website,
#sometimes they don't always link to you in the way that you want them to.
# If somebody links to www.yoursite.com and somebody else links to yoursite.com,
#Google will assign a separate pagerank for each of those. Yes, it is stupid but it is true,
#by inserting the below example into your .htaccess file,
#it will solve the problem by redirecting anything linking to yoursite.com to www.yoursite.com,
#also redirecting the pagerank.
#
rewritecond %{http_host} ^yoursite\.com [NC]
rewriteRule ^(.*) http://www.yoursite.com/$1 [R=301,L,NC]
## The following four lines of code are from YoungMonkey's reply,
##and they are substitute code for the last two lines of code referred by DipDog3.
##Rewrites http://www.yoursite.com/subdir to http://www.yoursite.com/
##and it allows selected subdirectories to be also be accessed.
##For example, if you have document downloads in a subdir2 that are to be accessed directly
##or through a call from your Joomla code,
##you need to specify them in the second RewriteRule that follows.
##I suggest that at minimum you specify your Joomla subsirectory [i]subdir[i].
##Also do not terminate the list with |.
RewriteRule ^$ /subdir/ [QSA,L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule !^(subdir|subdir1|subdir2|...|...|subdirN)(/.*)?$ /subdir%{REQUEST_URI} [QSA,L]
###END OF SECTION###
This code seems to work except for the following problem I encountered, which I hope someone may be able to explain.
With the SEF URLs AND Mod_Rewrite ON in the Joomla Globals, I could not get the CB Login to go to the destination page. I received an error saying cookies were not enabled even though they are enabled in the browser (by the way I only tested this with IE7 -- I always suggest testing with FireFox too as I have suggested in these forums. (Do as I say, not as I do)).
However everythings works with SEF URLs ON and Mod_Rewrite OFF in the Joomla Globals.
Since the .htaccess code above includes
RewriteEngine On
does make any difference?
Also, does anyone know if there are advantages from a SEO perspective to the above approach giving
http://www.yoursite.cominstead of
http://www.yoursite.com/subdir?
If anyone finds typos in the above code or my comments in the code, please zing me an email/contract privately and I will correct them.