7

Upon request I have reformulated my question for clarity so others might benefit better from the answers.

I have 3 domains for the company I work for:

bizwizprint.com (the main website that is hosted on a shared server)

bizwizsigns.com (secondary domain with no hosting attached)

boatwiz.com (tertiary domain with no hosting attached)

The goal is to get my second and third domains to redirect to the first domain onto their own respective landing pages.

First Step: At the domain registrar, change the DNS "A Records" of the second and third domains to resolve to the same IP address that the main website is hosted on.

Second Step: Create a "Site Alias" on the main website server for the second and third domains, they will point to the root directory where the main website files reside.

Third Step: Create or edit an .htaccess file that will redirect the requests for the second and third domains and point them to the landing pages that I have created for them.

The question: What rules do I add to htaccess?

Essentially, I would like to have a user type in "boatwiz.com" in the address bar and the browser will literally GO TO "bizwizprint.com/boatwiz.html".

Please note: I do not want any rewrite rules that will change the actual URL to boatwiz.

The reason for this is that it is a temporary thing. Eventually there will be an actual "boatwiz" website and "bizwizsigns" website and they will most likely be very different in structure. I don't want it to appear that I have three domains with all the same content, or have people make any bookmarks that I will need to redirect yet again in the future.

4
  • 1
    OK I see your update. 1) I don't understand what you mean by "Please note: I do not want any rewrite rules that will change the actual URL to boatwiz." Please be more specific. 2) you write "I would like to have a user type boatwiz.com and the browser will literally GO TO ..." - this means that the URL in the location bar will change? But then you wrote " I don't want it to appear that I have three domains with all the same content" which is apparent contradiction! It doesn't make sense - if you do the redirection in the Location bar, then users will notice!
    – Tomas
    Commented Jan 3, 2014 at 20:17
  • True, it does seem like a contradiction I see what you mean. I DO want "boatwiz.com" to CHANGE to "bizwizprint.com/boatwiz.html" when they actually arrive there. I want the change to be very apparent (for now). I DON'T want to add a rewrite rule to htaccess that will make people think that they are actually at a "boatwiz.com" when they are not (not really). The goal of the landing page (which is on me) will be to assure the user that they have arrived at the right place, despite the fact that a redirection has occured.
    – Grapho
    Commented Jan 3, 2014 at 20:29
  • The bottom line is: I have a domain that goes nowhere right now. you can type it in and nothing happens. Users will have no preconception of where it is "supposed" to go. If I am printing out a business card with that address, I want it to go somewhere, and for now that has to be a sub page on a different address, until I get the time and resources to host a proper site for it.
    – Grapho
    Commented Jan 3, 2014 at 21:05
  • @GraphicO: What you're intending to do is only possible if you have mod_proxy enabled on Apache server of boatwiz.com. Is it possible?
    – anubhava
    Commented Jan 5, 2014 at 5:23

2 Answers 2

5
+25

"How do I redirect an external domain (boatwiz.com) to land in a specific page of a new domain (bizwizprint.com/boatwiz.html) without any rewriting?"

So you probably mean that you want an "internal redirect", not the "external redirect", right? I.e. you want e.g. the bizwizsigns.com to stay displayed in the browser Location bar, but show the contents of bizwizprint.com/signs, right?

1. htaccess only - impossible

Well, using only .htaccess, this is impossible, because the different domain will force the external redirect. Citing the docs:

Absolute URL

If an absolute URL is specified, mod_rewrite checks to see whether the hostname matches the current host. If it does, the scheme and hostname are stripped out and the resulting path is treated as a URL-path. Otherwise, an external redirect is performed for the given URL. To force an external redirect back to the current host, see the [R] flag below.

2. Iframe trick

What you could do is to use iframe. Put this code at bizwizsigns.com/index.html:

<iframe src="http://bizwizprint.com/signs" width="100%" height="100%" 
        style="border: 0 none;" frameborder="0">

But there are many downsides of this solution:

  • the URL will not change in the browser's location bar, even if user clicks within the iframe
  • browser bookmarks and history will not work as expected.

3. Clever hosting setup (domain aliases into the same dir)

Are you in a hosting environment, or do you have your own server? Sometimes the hosting allows you to make aliases of several domains that are handled by the same local directory tree. In that case, you won - you can write .htaccess so that it handles the requests as internal redirects:

RewriteCond %{HTTP_HOST} bizwizsigns\.com$ [NC]
RewriteRule ^$ /signs [L]

RewriteCond %{HTTP_HOST} boatwiz\.com$ [NC]
RewriteRule ^$ /boats [L]

which will (internally) redirect bizwizsigns.com to /signs (= your content of bizwizprint.com/signs, because you have one hosting server directory for all 3 domains). But if you e.g. want all queries like bizwizsigns.com/<foo> to be redirected to bizwizprint.com/signs/<foo>, you have to be more careful - see the added condition on REQUEST_URI to prevent endless loop:

RewriteCond %{HTTP_HOST} bizwizsigns\.com$ [NC]
RewriteCond %{REQUEST_URI}  !^/signs/ [NC]
RewriteRule ^.*$ /signs/$1 [L]
4
  • Thank you for all this detail. I actually already have the aliases set up on my shared hosting plan, so by default, all my domains just point to my document root. The thing is I don't want any rewriting going on. I do not want to give the illusion that I have 3 domains that all have the same content. I would just like someone to type in boatwiz.com to the url and just land on the bizwizprint.com/boat page and have the main site just take over from there. I imagine this would be very similar to a 301 redirect. Is this the thing that the apache docs say is impossible?
    – Grapho
    Commented Jan 3, 2014 at 18:01
  • @GraphicO now I am totally confused. I thought you don't want to change the URL in the location bar, and now it seems it's the contrary... also your term "land on" is not very clear. Please describe what exactly should happen, what happens in the browser's location bar as well as in the page content. The best way is not the comments but to clean up and update your question. There will be a solution but first it must be absolutely clear what you want.
    – Tomas
    Commented Jan 3, 2014 at 18:07
  • so sorry for the confusion. "boatwiz.com" and "bizwizsigns.com" are just empty domain addresses, there are no actual pages that I need to redirect or rewrite to. "bizwizprint.com" is the main website that has all the pages I need for now. If a user types in "boatwiz.com" to the browser, I want the end result to literally be "bizwizprint.com/boatwiz.html" just as if they had clicked an actual link to get there. I appended my original question when I realized that a URL rewrite was a little overboard for what I really need. I hope that is more clear. Thanks!
    – Grapho
    Commented Jan 3, 2014 at 18:23
  • I reformed my question. Take another look when you get a chance. Thanks!
    – Grapho
    Commented Jan 3, 2014 at 20:11
3

Assuming that you have all 3 domains pointing to the same document root, you just need this in its htaccess file:

RewriteCond %{HTTP_HOST} bizwizsigns\.com$ [NC]
RewriteRule ^$ http://bizwizprint.com/signs [L,R=301]

RewriteCond %{HTTP_HOST} boatwiz\.com$ [NC]
RewriteRule ^$ http://bizwizprint.com/boats [L,R=301]

RewriteCond %{HTTP_HOST} (bizwizsigns|boatwiz)\.com$ [NC]
RewriteRule ^(.+)$ http://bizwizprint.com/$1 [L,R=301]

So if it's just http://bizwizsigns.com/ or http://boatwiz.com/, then you get redirected to http://bizwizprint.com/signs or http://bizwizprint.com/boats. But if you have anything after the last /, like http://bizwizsigns.com/foo/bar.html then you'll get redirected to http://bizwizprint.com/foo/bar.html.

5
  • +1 cool. can I assume that this will work in conjunction with some other rules I make? for instance when WordPress does rewrites for custom permalinks?
    – Grapho
    Commented Dec 30, 2013 at 23:51
  • @GraphicO as long as it's before any rules that route requests (external redirects usually need to happen first)
    – Jon Lin
    Commented Dec 30, 2013 at 23:52
  • lol. sorry. I need to wait for DNS changes to take before I see the results, but it seems like it will work.
    – Grapho
    Commented Jan 2, 2014 at 17:08
  • Sorry again. I need to update my question. I think all I need is a redirect and not a url overwrite.
    – Grapho
    Commented Jan 2, 2014 at 17:40
  • Note that Wordpress does not know how to create relative links. That may cause problems... Commented Jan 9, 2014 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.