How to get your Joomla! in a sub-directory to work at One.com

Magnus Palmér

I've spent quite some time getting my private Joomla! site to work the way I want with urls.
A short good step-by-step has for me proven very hard to find.
Several guides and post have been close, but still failed at the end for various reasons, so I'll explain briefly what I wanted to achieve and then exactly what does the trick.
I have my private domain, http://www.example.com hosted by One.com.
I'm using Joomla! for the main site, and then various other stuff in subdomains, like forum.example.com for my forum.
However I want to have my current active Joomla! installation in a subdirectory on the server but not show in the url of the browser.
I also like to have only one way of using the site, either with www or without.
So my setup expressed as example is this:

Domain: www.example.com
Webhost: One.com
File path on server: /joomla/

Default links like http://www.example.com/joomla/index.php?option=com_contact&view=contact&id=1&Itemid=13&lang=en it should show as http://example.com/en/contact instead.

I'll not go into reasoning why, this is the way I want to have it, and if this is how you want it too, please keep on reading, you are close...

These are the steps you need to do:

    1. Edit your webroot .htaccess
    2. Rename and then edit your default Joomla! htaccess.txt
    3. Configure Joomla! to use SEF and Apache mod_rewrite

Ok, now to the task of getting that htaccess correct, checking out the mod_rewrite documentation on the Apache site you get the following encouraging quotes to digest:

"The great thing about mod_rewrite is it gives you all the configurability and flexibility of Sendmail. The downside to mod_rewrite is that it gives you all the configurability and flexibility of Sendmail.''
-- Brian Behlendorf
Apache Group
"Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo.''
-- Brian Moore
bem@news.cmc.net

Instead of figuring out how to to this, I of course use my favorite search engine to get a post that has already done it, but no, I didn't find a single post that gave me the answer, some were close as I've already mentioned.
The thing is, it is depending upon your servers configuration, which can vary in so many ways, and by having your site on a cheap Webhost like I have, you have very scarce information. So, post that did the trick for some people, did not work for me on One.com.
So I ended up actually having to learn something about it...

Enough talking, now to business:

1. Edit your .htaccess in your webroot directory on the server. Note:www.example.com should be replaced by your domain and that /joomla with the directory you have your live joomla in.

# Make sure mod_rewrite is on, this is ok even if it is already on higher up in the hierarchy.
RewriteEngine On

#Match all www and do a permanent redirect from www.example.com to example.com
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]

#Ok, now get rid of that joomla directory in the resulting url.
RewriteCond %{REQUEST_URI} !^/joomla/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /joomla/$1 [L]
RewriteRule ^(/)?$ joomla/index.php [L]

2. Now edit your htaccess.txt in your root Joomla directory and when done, rename it to .htaccess

#Make sure this is commented and not active, otherwise nothing will work.
#Options +FollowSymLinks

#Uncomment all RewriteCond and RewriteRule in this section
########## Begin - Joomla! core SEF Section

########## End - Joomla! core SEF Section

#Uncomment all RewriteCond and RewriteRule in this section
########## Begin - Rewrite rules to block out some common exploits

########## End - Rewrite rules to block out some common exploits

3. Now, edit your configuration.php in your Joomla root directory.

$live_site ='http://example.com'
$sef = '1'
$sef_rewrite = '1'
$sef_suffix = '0'

Alternatively using the admin backend.
Site --> Global Configuration --> Site --> SEO Settings
joomla-seo-settings
Still, you have to edit manually the configuration.php for the live_site, this was added in Joomla! 1.5.2 to enable Joomla to reside in a subdirectory and generate urls with a different root.

Well, that's it, now it should work like a charm :)

Magnus Palmér
Consultant at Jayway

Tags: , , , , , ,

26 comments ↓

#1 Mathias on 02.04.09 at 21:54

Great tutorial! I followed it step by step but commented out the lines:
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]

…since I wanted http://www.mysite.com to work instead of redirecting to http://mysite.com

#2 Thure on 02.27.09 at 18:55

Wow! works like a charm. Many thanks for posting

#3 Christoff on 05.28.09 at 11:18

Nice solution, thanks for sharing it.

Just one thing though, it seems to throw the Search into a spin with 404 errors by adding an extra coded slash to the URL, ie. searching for ‘photo’ gives:
The requested URL /subdirectory/component/search/photo// was not found on this server
In the address bat the second slash at the end is coded as a %25

Any suggestions?

#4 Mike on 06.04.09 at 14:03

Thanks!!! You are the man!

#5 Magnus Palmér on 06.04.09 at 14:16

Hmm, search works fine on my site.
I guess you noticed that this was specific for One.com hosted Joomla sites.
Mail me the .htaccess and I can have a quick look at it.

#6 tripmckay on 08.16.09 at 19:52

Have the same issue with search, did any solutions on that come up?

#7 Widdy on 09.09.09 at 6:40

Awesome tip! Thanks! I am experiencing an issue when I’m in the admin console. It can’t find the DB when I’m saving configurations (both Joomla and Virtuemart). It’s trying to write back to http://www.example.com/administrator/... instead of http://www.example.com/joomla/administrator. Any advice or workaround?

#8 Yossarian on 09.27.09 at 14:01

For the search function I went into router.php in the search component and took out a slash.

#9 Yossarian on 09.27.09 at 14:09

No way, I cannot make this work… it simply does not.

#10 sigman on 11.08.09 at 18:54

You’re are awesome. I spent so many hours trying to get this working, and this post explains everything. Thanks.

#11 Rik on 01.07.10 at 16:30

Is there a solution already for the search? I’m using One.com, followed the procedure, but indeed have problems with the search.

Thanx,
Rik

#12 Dave on 01.15.10 at 22:54

Excellent article! I too searched for many hours on the web and did not find anything even close. After an afternoon+ of experimenting, I tried searching once again and found this article. Fantastic!

#13 Adrian Graham on 03.02.10 at 19:00

Hi, Grwat article but i cannot reach http://mydomain.com/administrator .. almost likes its looping?

Any help please?

#14 Vladimir on 03.04.10 at 22:41

Search works when $sef_suffix = ’1′ or change .

#15 Vladimir on 03.04.10 at 22:43

Alternatively to get search working you can set Add suffix to URLs to 1

#16 Theo on 03.29.10 at 20:13

I’ve seen a no. of threads about how to hiding or rewriting the file path, but I’m wondering what happens if you have the joomla install in a subdirectory and then want to link to other pages that aren’t in that subdirectory?

In my case, I still need to have header menus that link to the rest of the site that’s not Joomla. So far the only way I can do it is with absolute URLs in the links inside the Joomla subdir. I don’t have rewrite turned on, SEF is on. Is this just not possible or am I missing something really obvious?

#17 Paul on 04.14.10 at 10:39

I wanted to use a redirect for my subdomains. I tried putting my joomla folder in a subfolder called www. I followed the instructions above but now my menu points to pages like this mysite.com/www/contact.html. Also if i try mysite.com/contact.html i get a 404.

Any ideas?

#18 christoffer on 11.29.10 at 21:22

Thanks alot! I deployed a joomla-site on one.com today. Copy/pasted the .htaccess, worked like a charm.

#19 pawan on 01.25.11 at 8:51

a sub-domain is same as sub-directory. for example if we make a sub-domain joomla.example.com then there is still need to change the .htaccessfile or it will will work same only rename required. i think there is no need to change the .htaccess file for sub-domain condition.

#20 Christina on 01.25.11 at 15:20

You just have to change your /tmp directory

/customers/tricoz.com/tricoz.com/httpd.www/tmp

where for this client tricoz.com is both username and domain name. not sure which is which in this string.

Hey dont shoot the messenger. I have my own hosting server, but getting paid helps me work anywhere the client wants.

#21 Duncan on 03.12.11 at 17:46

Excellent tutorial….just what I was looking for and had my site up and running within a couple of minutes!!!

Cheers

#22 David on 05.29.11 at 1:03

does it work with Joomla! 1.6 ?

#23 Jack on 10.14.11 at 20:23

Simply: thanks!!! Great job, works perfect!

#24 Kim on 11.01.11 at 22:34

Anybody tried this with Joomla 1.6 / 1.7?

#25 Endang Mulyanto on 11.08.11 at 22:35

Terima kasih Mas, akhirnya masalah saya terselesaikan
dan sangat jelas panduannya :)
Thanks Sir, my problem was solved. Clear Explanation ..easy to be followed..one more thanks you very much …

#26 Cambridge Web design on 11.30.11 at 16:18

Well explained post. While you are in the .htaccess file why not a a quick bit of security for said file?

order allow,deny
deny from all

Stop those hackers who target Joomla sites!

Regards Ed

Leave a Comment