0
votes

I have a Joomla website on root-level, and wordpress blog on /blog .

Inside root-level .htaccess, I need to implement non-www to www redirect, such as:

RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L] 

However, this causes a problem when going to www.example.com/blog (withoug trailing "/" at the end). I get redirected to http://www.example.com/cgi-bin/php53.cgi/blog/index.php

The php53.cgi file is there to turn on PHP 5.3 version. This is the content of that file:

#!/bin/sh
export PHP_FCGI_CHILDREN=3
exec /hsphere/shared/php53/bin/php-cgi

This is the .htaccess inside /blog directory:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
# END WordPress
1

1 Answers

1
votes

You will need to redirect non-www to www on both .htaccess since the later .htaccess will overwrite your Joomla .htaccess rules.

RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

As for the blog not ending with / you could try this rule at your Joomla .htaccess:

# Redirect /blog to /blog/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+blog([^\s]+) [NC]
RewriteRule ^blog$ /blog/? [R=301,L]

NOTE: I am using %{THE_REQUEST} because since I don't know what rules you have on your Joomla .htaccess, the above will most likely work on all cases.

But you could also do it in a simpler way but that will not work in all cases depending on what other rules you have:

# Redirect /blog to /blog/
RewriteRule ^blog$ /blog/? [R=301,L]