Forum Moderators: phranque

Message Too Old, No Replies

301 multi sites one httaccess

301 multi domains

         

Mr_Smith

1:00 pm on Aug 8, 2012 (gmt 0)

10+ Year Member



Hi,
Hope you can help, I have two domains hosted on the same server sharing the same htaccess file. One is a US site and one a UK site.

I want to do some 301 redirects but the 2 sites share the same site structure i.e.

www.widgets.uk/big-widgets/red
www.widgets.usa/big-widgets/red

I want to redirect /big-widgets/red to /big-widgets/red-2 on both sites.

But I’m sure you can see it will create a bit of a problem, is there a way I can include the domain name in the first part of the redirect?

Thanks

g1smd

6:25 pm on Aug 8, 2012 (gmt 0)

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



You could use the {HTTP_HOST} variable in the target but you then lose www/non-www canonicalisation and create a double redirect for some requests.

You're better off using two rules. Use a RewriteCond to detect the requested host name in each and match
^(www\.)?example\.co\.uk
in one and
^(www\.)?example\.us
in the other.

Hard code the respective target hostname in each of the two rules.

lucy24

10:17 pm on Aug 8, 2012 (gmt 0)

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



Can you express it as a Condition that will always succeed, just to have something to capture from? Either

RewriteCond %{HTTP_HOST} ^(?:www\.)?(example\.co\.uk|example\.com)
RewriteRule {blahblah} http://www.%1/{blahblah}

or

RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.(co\.uk|com)
RewriteRule {blahblah} http://www.example.%1/{blahblah}

depending on whether the domains have the same name in the middle. Output will either have or not have the "www." piece depending on personal preference. And then you do something analogous for the generic www. rule at the end.

g1smd

10:42 pm on Aug 8, 2012 (gmt 0)

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



You could, but I am always wary of using
%n
references anywhere within the hostname part of the target.

A small coding slip resulting in
%n
being blank or having a value other than 'uk' or 'us' and the vistor is being redirected off-site and crucially those errors don't show up in your server logs.