Welcome, Guest
Username: Password: Remember me
Got a Joomla problem? Post as much detail about it as you can here to see if you can get a solution.

Help others in the community - post your Joomla tips and how-tos here.

TOPIC: LiveSite, multiple folders and the Root domian.

LiveSite, multiple folders and the Root domian. 2 months 3 weeks ago #8534

  • Terry
  • Terry's Avatar
  • Offline
  • Junior Boarder
  • Posts: 24
  • Thank you received: 7
Hi,

my question; is there another way to handle having Joomla in a sub-directory that doesn't use Livesite= in the config for a site using the hosting accounts root domain?

This doesn't apply to Addon or subdomains, just the base domain that is defined when you set up the hosting account. My environment tends to be cPanel on Apache/Litespeed so not sure if this is an issue on other platforms.

Back when I first started playing with Joomla I didn't like the way the Self installers that come with the hosting account would put Joomla in the accounts public_html directory. I wanted to be able to put Joomla in its own directory, ie./public_html/site1, which was easy enough once I started downloading and installing Joomla for myself.

However having a site in its own directory left me with a URL with a directory name, www.mydomain.com.au/site1/home so I made some .htaccess to removed the directory name from URL.

RewriteCond %{HTTP_HOST} ^www\.mydomain\.com\.au$
RewriteCond $1 !^site2 <- Allows for testing, Site2 is not re-written
RewriteRule (.*) /site1/$1 [L]

And this works provided you use Livesite='www.mydomain.com.au'; in the Joomla configuration.php

This has served me well for over ten years and I haven't really thought about it since, but yesterday I found I had not updated a couple of livesite entries from http to https when I installed SSL certificates. And with Mr Taylor telling telling me I should not be using Livesite and he can fix it, which actually breaks it, I have started to question is it the best way.

Having recently come across a number of professionally built Joomla sites with the directory name in the URL I figured I would ask my question to see if there is a better way or at least share my method for others to use.

Terry
Been working with Joomla for Fun and Work for 10 years.
The administrator has disabled public write access.

LiveSite, multiple folders and the Root domian. 2 months 3 weeks ago #8536

  • sozzled
  • sozzled's Avatar
  • Offline
  • Moderator
  • I'm just a user, mate!
  • Posts: 137
  • Thank you received: 25
This is an excellent topic for discussion. We're having a similar discussion around a problem on the Joomla forum at forum.joomla.org/viewtopic.php?f=710&t=968911 which, I believe, is related to the way that people organise the files on their webservers and there are a few particular issues relating to how "best" to organise the files on shared webhosts.

Terry wrote:
Back when I first started playing with Joomla I didn't like the way the Self installers that come with the hosting account would put Joomla in the accounts public_html directory. I wanted to be able to put Joomla in its own directory, ie./public_html/site1, which was easy enough once I started downloading and installing Joomla for myself.

This is one of many reasons why people should avoid using "self installers" or "quickie" installs because, even though they take a few less mouse-clicks that using the standard approach which, by the way, takes less than 10 minutes, they generally cause more maintenance headaches in the long run.

Terry wrote:
Is there another way to handle having Joomla in a sub-directory that doesn't use Livesite= in the config for a site using the hosting accounts root domain?

As a general rule, a properly configured J! website should leave the configuration.php file with this entry:
public $live_site='';

So don't change it.

Terry wrote:
However having a site in its own directory left me with a URL with a directory name, www.mydomain.com.au/site1/home so I made some .htaccess to removed the directory name from URL.

This is the crifical question. For those [few] people who only want one website, it's a case of "who cares?" But who only wants one website? If you're running your website for business (and every website is a "business" of one kind or another even if it's not for profit or just as a hobby), you should have a test site on standby for experimentation.

When people obtain a shared hosting account, there's normally a domain associated with it. This is called the primary domain. URLs accessing the primary domain will look at the "root folder" (i.e. /public_html) and expect to find something there to execute. So, the idea is to "containerise" your websites to use separate sub-folders of the root. In other words, let's say the primary [domain] site is called www.site1.com.au and its files are placed in /public_html/site1. Following with me so far?

The trick is to redirect the URLs that—by default—expect to find the site in /public_html and point the HTTP requests relating to the real site at /public_html/site1 (i.e the sub-folder). The solution is to create a .htaccess file in the root folder with the following statements:
# .htaccess main domain to subdirectory redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.
# Do not change the line below.
RewriteEngine on
# Change site1.com.au to be your main domain.
# Change 'site1' to be the directory you will use for your main domain
RewriteCond %{REQUEST_URI} !^/site1/
# Don't change the next two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

That's it. That's all there is to it! B)
Read my blog and twitter
Last Edit: 2 months 3 weeks ago by sozzled.
The administrator has disabled public write access.

LiveSite, multiple folders and the Root domian. 2 months 3 weeks ago #8537

  • Terry
  • Terry's Avatar
  • Offline
  • Junior Boarder
  • Posts: 24
  • Thank you received: 7
Hi,

looking at your code example in the last box there seems to be something missing, the actual RewriteRule that makes a change, so I can't see what happens next, it looks like you haven't pasted the whole section. The RewriteCond statement is just a wasted line if there is no RewriteRule following it, like an IF statement with no THEN. :)
The trick is to redirect the URLs that—by default—expect to find the site in /public_html and point the HTTP requests relating to the real site at /public_html/site1 (i.e the sub-folder)
If you are a doing a 'redirect' and not a rewriterule, then you are doing multiple HTTP page requests so it is not very efficient
.
Regards,
Terry
Been working with Joomla for Fun and Work for 10 years.
The administrator has disabled public write access.

LiveSite, multiple folders and the Root domian. 2 months 3 weeks ago #8538

  • sozzled
  • sozzled's Avatar
  • Offline
  • Moderator
  • I'm just a user, mate!
  • Posts: 137
  • Thank you received: 25
Thanks, Terry, and you're quite right:

# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subdirectory/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /subdirectory/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ subdirectory/index.html [L]

Obviously there are parts of this example that people wouldn't use in a real-life situation (such as adding "index.html" to the end of the URL and using %{HTTP_HOST} is considered a no-no) but it gives you the general idea.

This might work: try it out

# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subdirectory/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /subdirectory/$1
Read my blog and twitter
Last Edit: 2 months 3 weeks ago by sozzled.
The administrator has disabled public write access.

LiveSite, multiple folders and the Root domian. 2 months 3 weeks ago #8539

  • Terry
  • Terry's Avatar
  • Offline
  • Junior Boarder
  • Posts: 24
  • Thank you received: 7
Hi,

the purpose of my original post is to find out how other people manage multiple copies of Joomla or Joomla in sub directories. I already have something that works, I want to know what other people do that is working for them.

Sozzle,

the key line, RewriteRule, in the second block of code you pasted is pretty much the same as what I currently use but I tested your version as it has an extra $ sign and as I suspected that method still requires Livesite= to be set to the domain name.

Terry
Been working with Joomla for Fun and Work for 10 years.
Last Edit: 2 months 3 weeks ago by Terry. Reason: correctedtypo in livesite
The administrator has disabled public write access.
Time to create page: 0.102 seconds
Powered by Kunena Forum