Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Redirecting multiple domains

on the target domain?


Patrick Taylor

7:09 am on Oct 24, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

A friend is insisting on this .htaccess (fragment) to redirect multiple domains to one:

# Canonical url fix
RewriteCond %{HTTP_HOST} ^(www\.)?example\.(com|net|info|co\.uk) [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.example\.org [NC]
RewriteRule ^(.*)$ http://example.org/$1 [R=301,L]

The .htaccess file is located only on example.org - so how does the redirect work on (eg) example.com unless the user is actually on example.com?


8:37 am on Oct 24, 2011 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

It depends what happens in all the other domains' servers. They might be set up to point to the example.org server without a concurrent redirect (change in url). But you need to find out exactly what the configuration is before you do anything with the htaccess.

So if your friend is insisting, you may have to insist louder ;)

Patrick Taylor

4:29 pm on Oct 24, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Thanks. What you say seems to confirm the following line is useless:

RewriteCond %{HTTP_HOST} ^(www\.)?example\.(com|net|info|co\.uk) [NC,OR]

... because the .htaccess file that contains it is only on example.org and if the user has arrived there it is superfluous. That's as I understand it at least.

I might have misunderstood the whole thing but (com|net|info|co\.uk) is always going to be useless do you think?


2:26 am on Oct 25, 2011 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Unless you've got more than one of them living in the same place, you wouldn't expect it to do any good.

By weird coincidence, I've just met a domain that comes with four different extensions, very similar to your example. And a choice of two names. And with-and-without www variants. It appears to be distributed among at least three different servers,* which explains why some names are accepted as-is (possibly rewritten, or possibly just all routed via the same jsp code) while a few are redirected.**

In your case, is the site under construction or is it already up and running? What happens if you type in a name other than .org?

* Apache-Coyote/1.1, with Apache/1.3.34 (Unix) PHP/4.4.2 lurking in the background, and a couple more that seem to belong to g###.

** I was never very good at the abacus method for counting on your fingers-- the one that lets you go up to 99-- but I make that sixteen possible names. Both versions of name1.net redirect (302) to www.name1.org, as do both versions of, let's say, name1.uk. And both versions of name2.uk-- but not name2.net-- redirect (302) to name1.com. Without www. With .com instead of .org. All of this should be enough to make g1smd's hair stand on end ;)

Patrick Taylor

6:37 am on Oct 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

The example.org site is live (I built the site).

example.com, example.net, example.info, and example.co.uk all resolve to .org even when I delete the above line (comment #:4378731) from .htaccess. My friend bought the other domains and has done something at his end to redirect them, but he is also asking for the additional line (above - the one I am challenging). I have told him it does nothing.

The reason I'm asking the question is that if you search for "redirect multiple domains" or similar you will find examples where redirecting these extra domains is advised in the .htaccess on the target domain. I don't understand how that can work.


7:06 am on Oct 25, 2011 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

If the "something at the other end" sees any URL (i.e. deep page) requested on those other domains redirected to the root of the new site, then you should fix that code to redirect to the right page each time.

Do check that non-canonical requests are redirected once; make sure there is no redirection chain generated for any request. Use the Live HTTP Headers extension for Firefox to check things out.

If the other person is paying for additional hosting merely to place a redirect in that other hosting, change the DNS around to point all of the domains to the server where the site actually resides and cancel the other hosting. In the config of the site where the content actually resides set it to redirect requests for the wrong domains to the right domain, preserving the requested path in that redirect.

I would use this on the actual site:
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

This ensures that any non-canonical hostname is redirected. It caters for
with a port number,
for a different domain,
with a trailing period (yeah that IS a valid request),
the bare non-www, or any combination of non-canonical items.

Featured Threads

Hot Threads This Week

Hot Threads This Month