Forum Moderators: phranque

Message Too Old, No Replies

redirect www to non www in subfolder

         

joomir

10:15 am on Nov 6, 2014 (gmt 0)

10+ Year Member



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\.example\.com)?$
RewriteRule ^(.*)$ http://example.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?

[edited by: phranque at 11:10 am (utc) on Nov 6, 2014]
[edit reason] exemplified domain [/edit]

lucy24

6:39 pm on Nov 6, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Tangentially:
RewriteCond %{HTTP_HOST} ^(www\.example\.com)?$

This is backward. Express the condition as
!^(example\.com)?$
where the part inside parentheses is identical to the form you use in the target of your rule.

So you've got two separate joomla installations along the same physical path (one directory inside another)? Does the inner one say anything about
RewriteOptions inherit
? Or does the domain-name redirect rule appear twice? I assume you want the same form of the name throughout the site.


If-and-only if the problem is happening within Apache alone, rather than in joomla, here is the likeliest explanation:

Since the second htaccess file is in a subdirectory, any pattern in the form
^blahblah

means
www.example.com/subdir/blahblah

This applies to any RewriteRule located in a subdirectory: ^ (opening anchor, or earliest possible part of pattern) means the current directory. So if you want to capture and reuse from within this subdirectory, the target would have to say
www.example.com/subdir/$1