Redirect www to non www in subfolder by htaccess

I have joomla installed on root folder and another joomla installed on subfolder. I want to redirect www to non in subfolder by this code in blog htaccess:

RewriteCond %{HTTP_HOST} ^(www\.mydomain\.com)?$
RewriteRule ^(.*)$ http://mydomain.com/blog/$2 [R=301,L]

it worked for root redirect but when i want browse internal page it redirect the page to home page. What is problem?

Hi sitedar!

First question/comment: You really need to display the .htaccess in the DocumentRoot AND the subdirectory. Lacking that, I’ll bet that the DocumentRoot (whose .htaccess is executed first) redirects to the www’d domain so that the .htaccess in the blog subdirectory isn’t given a chance.

Workarounds:

  1. Exclude blog from redirects to www in the DocumentRoot’s .htaccess

  2. Make blog the DocumentRoot for the blog.domain.com subdomain (because that will then bypass the domain’s DocumentRoot).

Second question: Why do you find it necessary to group the {HTTP_HOST}? All you need to be testing is the www. What you’ve done is make the {HTTP_HOST} OPTIONAL, i.e., www.mydomain.com OR null (an impossibility on a typical production website).

You might benefit from reading the mod_rewrite tutorial at http://dk.co.nz/seo as it contains explanations and sample code. It’s helped may members and should help you, too.

Regards,

DK

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.