views:

20

answers:

1

Hi,

I have two domains pointing to the same host, say example1.com and example2.com.

I already have a redirect:

RewriteRule ^([A-Za-z0-9-]+)/$ page.php?q=$1 [L]

to catch things like example1.com/hello-world/ => example.com/page.php?q=hello-world

Now I need 3 specific conditions to be met:

1) example1.com/special/ => example2.com/special/ [ONLY for "special"]
2) example2.com/ => example2.com/special/
3) example2.com/anything-not-special/ => example1.com/anything-not-special/

I can get this to happen, except that I want exactly what's in the right-hand column here to be displayed in the URL bar. Instead, I'm getting: example2.com/special/ => example1.com/page.php?q=special

which is not ideal for me.

Any help appreciated, thanks!

+1  A: 

See if this does what you want:

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/page\.php
RewriteCond %{HTTP_HOST}%{REQUEST_URI} =example1.com/special/ [OR]
RewriteCond %{HTTP_HOST}%{REQUEST_URI} =example2.com/
RewriteRule ^.*$ http://example2.com/special/ [R=301,L]

RewriteCond %{REQUEST_URI} !^/page\.php
RewriteCond %{HTTP_HOST}    =example2.com
RewriteCond %{REQUEST_URI} !=/special/
RewriteRule ^.*$ http://example1.com%{REQUEST_URI} [R=301,L]

RewriteRule ^([A-Za-z0-9-]+)/$ page.php?q=$1
Tim Stone
Thanks for the answer, however it did not work. It seems to be that the second RewriteCond in the second block is not correctly catching /special/.Also it still resolved the URL in the URL bar to http://example1.com/page.php?q=special
Tom
Yeah, sorry. Minor oversight on my part. See if the edited version works any better.
Tim Stone
example2.com/special/ is still resolving to example1.com/page.php?q=special which is strange. It doesn't make sense to me - your code is sound and almost identical to what I already had fumbled my way to.
Tom
So when you go to `example2.com/special/` it changes the URL in the browser to `example1.com/page.php?q=special` still? Hmm..it doesn't do that on my test server. Is there any other other rule for any other module that you know of? I'm trying to think what else might be forcing an external redirect..
Tim Stone
I think the problem might lie with how the REQUEST_URI field is being filled on my server...I shall investigate.
Tom
I didn't really figure out what was causing the inconsistency, but using `RewriteCond %{SCRIPT_FILENAME} !-f` ended up providing a solution for now.
Tom
Hmm, interesting. I messed around with a bit and couldn't figure out why that might happen..Probably something I'm just overlooking though. At least you were able to get it work for now; if I figure out what the root of the issue might be I'll let you know.
Tim Stone