Forum Moderators: phranque

Message Too Old, No Replies

different redirects in subdirs

         

the_nerd

8:57 am on Apr 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



pls. accept my apologies for asking this stupid question - but I tried to solve this for 3 hours ....

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?

TheMadScientist

4:04 pm on May 8, 2008 (gmt 0)

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



Interesting.

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]

jdMorgan

4:29 pm on May 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Look for a rule preceding this one --in this .htaccess file or in any 'above' this directory, that is missing an [L] flag.

Also, make sure that all external redirect rules are executed before any internal rewrite rules; Otherwise, your internal path will be 'exposed' by the redirects.

Jim