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:
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:
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:
#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:
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:
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.
