Showing a subdomain for part of a Joomla! site

Discuss Search Engine Optimization in relation to Joomla!. This forum will also have discussions on SEF/SEO Joomla! extensions.

Moderator: General Support Moderators

Locked
Yorb
Joomla! Apprentice
Joomla! Apprentice
Posts: 22
Joined: Fri Jul 11, 2008 4:54 pm

Showing a subdomain for part of a Joomla! site

Post by Yorb » Mon Oct 11, 2010 4:58 pm

I've been trying to figure out the best way to do this, and would be interested to hear anyone's suggestions.

Situation: main site is http://www.example.com. Just moved our blog from a 3rd party blog provider, where it was located at blog.example.com, to our main site -- currently http://www.example.com/blog. Would really like to keep blog.example.com (or even blog.example.com/blog if necessary, as I suspect it might be) for branding reasons.

Currently all subdomains point to the main site. I use mod_rewrite to point the blog subdomain to http://www.example.com/blog, and 301 redirects to point the individual article pages to their new URLs (only about 50 or so articles). Code for that first part (super basic):

Code: Select all

RewriteCond %{HTTP_HOST} ^blog.example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/blog/$1 [L]
I can point blog.example.com to blog.example.com/blog using a similar method, the main difference being that I have to exclude the situation where index.php is being requested, because otherwise it will be an infinite loop. Here's the code for that, FYI:

Code: Select all

RewriteCond %{HTTP_HOST} ^blog\.example\.com [NC]
RewriteCond %{REQUEST_URI} !^/index\.php [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?Itemid=27 [NC,L]
But then if someone clicks back from the blog to another section of the site, the blog subdomain stays in the URL, which is not cool. :( So then I scrapped the previous attempts and tried to add the subdomain to the URL IF you're on one of the pages or components USED by the blog (slightly different logic):

Code: Select all

#RewriteCond %{HTTP_HOST} !^blog\.example\.com [NC]
#RewriteCond %{REQUEST_URI} ^/(blog|keyword|component\/blog_calendar) [NC]
#RewriteRule ^(.*)$ http://blog.example.com/$1 [NC,L]
That works, but then there's the same problem of needing to REMOVE the subdomain when someone LEAVES one of the blog sections. I thought I could just copy/paste the above block and switch the negating exclamation point from the first Cond to the second one, and change the Rule to go to www instead of blog. Unfortunately, that just dumps me at index.php whenever I try to go to a blog page. I dunno what's going on. Here's both blocks together, maybe someone can tell me what I'm doing wrong:

Code: Select all

RewriteCond %{HTTP_HOST} !^blog\.example\.com [NC]
RewriteCond %{REQUEST_URI} ^/(blog|keyword|component\/blog_calendar) [NC]
RewriteRule ^(.*)$ http://blog.example.com/$1 [NC,L]

RewriteCond %{HTTP_HOST} ^blog\.example\.com [NC]
RewriteCond %{REQUEST_URI} !/(blog|keyword|component\/blog_calendar) [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [NC,L]
The culprit is definitely the second Cond on the second block, it seems to be ignoring those, so dumping back to index whenever the subdomain is blog.

I tried this, since sometimes the request URI is in Joomla query string format (for reasons I can't figure out):

Code: Select all

RewriteCond %{HTTP_HOST} ^blog\.example\.com [NC]
RewriteCond %{REQUEST_URI} !Itemid=(27|158|159|179|184) [NC]
RewriteCond %{REQUEST_URI} !option=(com_blog_calendar|com_sectionex|com_tag) [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [NC,L]
Results in an infinite loop if both blocks are on, and results in always removing the blog subdomain if the first block is disabled. So again, the second and 3rd Conds are not working.

Any ideas as to what I'm doing wrong? I'm also open to completely other suggestions. Mod_rewrite is just how I'm accustomed to doing these sorts of things.

Thanks a bunch for reading, and for any help in advance. :)

Yorb
Joomla! Apprentice
Joomla! Apprentice
Posts: 22
Joined: Fri Jul 11, 2008 4:54 pm

Re: Showing a subdomain for part of a Joomla! site

Post by Yorb » Mon Oct 11, 2010 5:29 pm

Okay, it's working. Here are the 3 relevant blocks:

Code: Select all

RewriteCond %{HTTP_HOST} ^blog\.example\.com [NC]
RewriteCond %{REQUEST_URI} !^/index\.php [NC]
RewriteCond %{REQUEST_URI} ^/(blog|keyword|component\/blog_calendar) [NC,OR]
RewriteCond %{REQUEST_URI} ^/?$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?Itemid=27 [NC]

RewriteCond %{HTTP_HOST} !^blog\.example\.com [NC]
RewriteCond %{REQUEST_URI} ^/(blog|keyword|component\/blog_calendar) [NC]
RewriteRule ^(.*)$ http://blog.example.com/$1 [NC,L]

RewriteCond %{HTTP_HOST} ^blog\.example\.com [NC]
RewriteCond %{QUERY_STRING} !Itemid=(27|158|159|179|184) [NC]
RewriteCond %{QUERY_STRING} !option=(com_blog_calendar|com_sectionex|com_tag) [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [NC,L]
I feel like that's longer than it needs to be, so if you see room for pruning, PLEASE do. The only downsides right now are possible performance issues (redirects), possible SEO issues (if you know more about how this affects SEO, please do share, since that's the reason we are doing this in the first place), and the fact that all local (relative) links on a blog page will appear to go to blog.example.com/whatever, even if they aren't in the blog section. Once the link is clicked, the redirect swaps the blog for a www, but still. Not great. Ideas?

Yorb
Joomla! Apprentice
Joomla! Apprentice
Posts: 22
Joined: Fri Jul 11, 2008 4:54 pm

Re: Showing a subdomain for part of a Joomla! site

Post by Yorb » Fri Nov 05, 2010 1:46 pm

Bump.

What have other people done for this? This way is so roundabout, it seems like there must be an extension or something for this. I've run into other problems this way, such as, login information is not carried across subdomains, and clicking a Home link while in the blog section only takes you to the home of the blog, not the main home.

Ideas? Anyone? :(

User avatar
IberoMedia
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 126
Joined: Mon Apr 12, 2010 3:25 am
Contact:

Re: Showing a subdomain for part of a Joomla! site

Post by IberoMedia » Fri Nov 19, 2010 4:50 pm

I have no ideas, but I too, am looking for instructions on how to create subdomain while using the regular Joomla installation

djw2
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Tue Jan 29, 2008 9:18 pm

Re: Showing a subdomain for part of a Joomla! site

Post by djw2 » Sat Nov 27, 2010 12:25 am

I'm looking for some information on doing this as well. I'm looking to display a couple of components as subdomains, essentially just like Joomla does right here at joomla.org... notice the domain here in the forum, forum.joomla.org... or in the extension directory at extensins.joomla.org. In fact Joomla.org has a large number of subdomains in use.

So, how is it done here on Joomla.org?

Here are some of the components I'd like to do this with...

VirtueMart as shop.domain.com
Sobi2 as merchants.domain.com
EZ Realty as homes.domain.com
Kunena as forum.domain.com

I also have a couple of sections that I'd lie to do this to as well... it's a magazine format and there are a couple of 'supplemental' sections that I want to use a different template and different layout for... highschoolsports.domain.com.

Anybody know how this domain trick is accomplished, aside from addition installs in subdomains?

I am aware of the JMS Multisite components... is that it... is that the trick? I was under the impression that there was another way.

Thanks.

djw2
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Tue Jan 29, 2008 9:18 pm

Re: Showing a subdomain for part of a Joomla! site

Post by djw2 » Sat Nov 27, 2010 12:35 am

By the way... I'm going to be trying Virtual Domains Beta. It looks like it may work for what I trying to do.


Locked

Return to “Search Engine Optimization (Joomla! SEO) in Joomla! 1.5”