0
votes

So I have this two sub sites that needs to be redirected into a different locale but has the same source, but only the first rewriterule takes effect for the both domain.

what should happen:

example-site1.com/register ----> https://register.index.com/en-us

example-site2.com/register ----> https://register.index.com/en-gb

what's happening for this code below:

example-site1.com ----> https://register.index.com/en-us

example-site2.com ----> https://register.index.com/en-us

###########################

RewriteCond %{HTTP_HOST} ^example-site1\.com [OR]
RewriteCond %{HTTP_HOST} ^www\.example-site1\.com
RewriteRule ^/(registration|registration/)$ https://register.index.com/en-us [L,R=301]
RewriteRule ^/(register|register/)$ https://register.index.com/en-us [L,R=301]

RewriteCond %{HTTP_HOST} ^example-site2\.com [OR]
RewriteCond %{HTTP_HOST} ^www\.example-site2\.com
RewriteRule ^/(registration|registration/)$ https://register.index.com/en-gb [L,R=301]
RewriteRule ^/(register|register/)$ https://register.index.com/en-gb [L,R=301]
1

1 Answers

0
votes

RewriteCond(s) only affect the immediately following RewriteRule, not multiple rules - so your second RewriteRule above is completely independent of your host name checks above. You need to either combine those two rules into one (should be no problem in this instance, because the target is always the same URL, and you simply have four [actually rather two, see below] different alternatives to match here) - or you would have to repeat the RewriteConds again before the second RewriteRule. And the same for the second block.


(registration|registration/) is kinda redundant anyway - you don’t require a back reference to what was matched for your rewrite, so you could just add the slash after the keyword, making it optional - registration/?. So if you combine both cases into one pattern, ^(registration|register)/?$ should do the trick. (I removed the leading slash, with that it should actually not have worked at all to begin with - if you configure rewriting in .htaccess, that leading slash has been stripped off at that point already.)