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

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 :)

This Post Has 30 Comments

  1. Mathias

    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

    Wow! works like a charm. Many thanks for posting

  3. Christoff

    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?

    1. Magnus Palmér

      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.

  4. Mike

    Thanks!!! You are the man!

  5. tripmckay

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

  6. Yossarian

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

  7. Yossarian

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

  8. sigman

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

  9. Rik

    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

  10. Dave

    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!

  11. Vladimir

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

  12. Vladimir

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

  13. Theo

    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?

  14. Paul

    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?

  15. christoffer

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

  16. pawan

    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.

  17. Christina

    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.

  18. Duncan

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

    Cheers

  19. David

    does it work with Joomla! 1.6 ?

  20. Jack

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

  21. Kim

    Anybody tried this with Joomla 1.6 / 1.7?

  22. Endang Mulyanto

    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 …

  23. 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

  24. Maf

    Extraordinaire c’est un super tutorial. Thank you so much

  25. Pingback: itemprop="name">Robb

  26. Karin

    Your remark concerning commenting out Options+FollowSymLinks did help me to reanimate my Joomla 2.5 site hosted with One.com after I migrated the site from subdomain to domain.
    After renaming htaccess.txt into .htaccess and turning on use URL rewrite for SEO .. my site crashed. Nothing worked any longer. Neither the subdomain-sites until I did he solution I saw in your description.
    Thanks.

Leave a Reply