homepage Welcome to WebmasterWorld Guest from 54.166.100.8
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Redirecting multiple domains
on the target domain?
Patrick Taylor




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

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?

 

lucy24




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

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




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

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?

lucy24




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

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




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

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.

g1smd




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

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
www.example.com:80 with a port number, www.example.org for a different domain, www.example.com. with a trailing period (yeah that IS a valid request), example.com the bare non-www, or any combination of non-canonical items.
Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved