Forum Moderators: phranque
I have a rewrite rule in the server root that "canonifies" my uris:
RewriteCond %{HTTP_HOST} !^www.dom.com [NC]
RewriteRule ^(.*) [dom.com...] [L,R=301,NC]
It works for all kinds of request, e.g.
dom.com
dom.com/
dom.com/page.htm
Now, I want to have different redirects in a subdirectory.
/subdir1/subdir2 and placed another .htaccess there:
RewriteCond %{HTTP_HOST} ^dom.com [NC]
RewriteRule ^(.*) [otherdom.com...] [L,R=301,NC]
What happens is this:
dom.com/subdir1/subdir2 -> www.otherdom.com//web/1/.../htdocs/subdir1/subdir2
i.e. the whole physical directory is appended. No idea, why.
dom.com/subdir1/subdir2/ -> www.otherdom.com/
dom.com/subdir1/subdir2/page.htm -> www.otherdom.com/page.htm
What I'd like to have is
dom.com/subdir1/subdir2/ -> www.otherdom/subdir1/subdir2
dom.com/subdir1/subdir2 -> www.otherdom/subdir1/subdir2
dom.com/subdir1/subdir2/page.htm -> www.otherdom/subdir1/subdir2/page.htm
I think, the ^ at the beginning of the rule might be wrong, and there probably should be a RewriteBase entry. But none worked for me so far.
Any idea?
First, I would not recommend this redirect in the specific directory, because you *should not* have access to the directory path to the current location on the left side of your rule.
IOW Your redirect should go to otherdom.com/page.html, not otherdom.com/subdir1/subdir2/page.html.
Why you are getting the extra information is something I am not sure about, but what I would suggest is moving your ruleset to the main .htaccess with a specific match:
RewriteRule ^subdir1/subdir2/(.*) http://www.otherdom.com/subdir1/subdir2/$1 [L,R=301,NC]
I am also unsure as to why you have the host condition present? Are you running the two sites out of the same physical directory on the same server, so you need to differentiate between the two?
[edited by: TheMadScientist at 4:04 pm (utc) on May 8, 2008]