Jump to content
#StayAtHome ×
TheWebExpert

Need help with redirect.

Recommended Posts

Ok, so let's say my website is bob.com - fine. Well, I want to have sam.com also, but can't afford to pay for Deluxe hosting. So I get the domain, but I forward sam's DNS servers to point at Bob, with masking on.

What I'm looking to do is to identify what the person typed in - i.e., the original, unmodified URL. Here's what I have currently:

function get_redirect_target($url)
{
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_NOBODY, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $headers = curl_exec($ch);
    curl_close($ch);
    // Check if there's a Location: header (redirect)
    if (preg_match('/^Location: (.+)$/im', $headers, $matches))
        return trim($matches[1]);
    // If not, there was no redirect so return the original URL
    // (Alternatively change this to return false)
    return $url;
}

$path = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo get_redirect_target($path);

The main problem here is that it's VERY slow. I'm also often getting a 500 error. Anyone have any ideas?

Share this post


Link to post
Share on other sites

Why is there a redirect? If you want both sites on the same server that's totally fine, but why would there be any redirections for it?

Share this post


Link to post
Share on other sites

I can't afford the deluxe hosting.  With the deluxe hosting, I can have an infinite number of websites under one hosting plan.  With the basic hosting, I can only have one site hosted.  So, what I have is the DNS pointing the second domain to the first; if the user types "www.sam.com," they still go to "www.bob.com," but they see the content for "www.sam.com" instead, just as if it was its own site.

Share this post


Link to post
Share on other sites

If you told your DNS provider that it should redirect from one to the other, that's wrong. If you told them to alias, that's potentially okay, depending on how they do the aliasing.

Can you post the actual domain name? The second "sam.com" one.

Share this post


Link to post
Share on other sites

What they did was host mullins-storage.com on their servers, and the webpage they present uses an iframe to load br-storage.com. That's not good. It also doesn't support what you want to do.

You need to point both domains to the same server, then make sure your web server tries to serve both sites... however they need to be served. I don't know what "deluxe hosting" is but you're probably getting close to it.

Share this post


Link to post
Share on other sites

It's on the right server but it's redirecting to br-storage.com now.

The web server needs to handle both domains going to the same site.

Share this post


Link to post
Share on other sites

I thought that redirecting (or alias, or whatever) was the right way.

 

If it's not an alias or redirecting, there won't be anywhere for it to go.

The br-storage site goes to the br-storage site; the mullins-storage ALSO goes to the br-storage site.  Isn't that what you said?  That both domains should go to the same site?  I'm confused.  Can you explain exactly what you mean?

Share this post


Link to post
Share on other sites

In my very first post here I questioned why you were even having it redirect at all. I haven't changed my mind since then.

You know how br-storage goes to your server? The server that has the website and all that? mullins-storage needs to do exactly the same thing. No redirects.

Share this post


Link to post
Share on other sites

How is that possible?  Each server can only serve ONE website.  Mullins is on the same server, but can't have its own website.  Therefore, there HAS to be some sort of redirect or alias or whatever, so that, with the proper code, I can detect what people were searching for - and thus make it LOOK like there are two separate websites, when, in fact there's only one.

Share this post


Link to post
Share on other sites
8 minutes ago, TheWebExpert said:

Each server can only serve ONE website.

Yeah no. One server can handle multiple websites. It's how a lot of the web works.

Share this post


Link to post
Share on other sites

Uh.  AFAIK, I need a separate hosting for multiple sites.  Basic can only do one; I have multiple domains, but only one hosting... and therefore one website.  If you can clue me into how I'd do multiple websites, I'd appreciate it.

Share this post


Link to post
Share on other sites

Is it just me or have you basically just stated that what you've been trying to do in this thread is impossible?

Share this post


Link to post
Share on other sites

My host offers mutliple domains for no extra cost.  I pay a domain registration fee each year to have another name and I then assign that as a sub-domain under my original hosted domain.  POC!

Share this post


Link to post
Share on other sites

AFAIK, what I'm trying to do IS possible - I'm just not sure what's wrong.

My company has multiple hosting plans.  The basic plan is one website.  I can have multiple domains, but only one hosted site.  I can do DNS forwarding on the 2nd domain, or an alias on the 2nd domain.  If I pay extra, I can get the deluxe hosting - which can have as many websites hosted on the server as I care to dream up.  What I wanted to have happen was to have my singleton website try to determine what it was the person had typed.  If they typed www.mullins-storage.com, then - instead of bringing up the index.php for www.br-storage.com, it would bring up a slightly different index.php geared toward www.mullins-storage.com instead.

 

If you're telling me that this isn't possible, then I'll have to bite the bullet and pay for the deluxe hosting, and have two individual websites.

Share this post


Link to post
Share on other sites

1. The DNS for both domains needs to be the same IP address to the server - no aliases, no redirects, just a basic DNS setup
2. The web server needs to be configured so that both domains go to the same "site"

The second part you may or may not be able to do, depending what you have access to. It's quite possible they may have locked this part of the process down enough so that clever people wouldn't be able to get around their paywall. Or maybe they didn't.

Share this post


Link to post
Share on other sites

Who are you using as a hoster?  The ones that I reviewed prior to making my selection many years ago all offered sub-domains which is pretty much what you can do I believe.  I have two function domains that may call each other but I never do it.  They are distinct things and don't need to share anything.

Share this post


Link to post
Share on other sites

Well, it seemed as if that was done - but it just wasn't working.  It's too big of a headache.  I'm just going to set up two independent websites, and be done with it.

Share this post


Link to post
Share on other sites

You should be able to do that with your current hosting plan if one is made a sub-domain of the primary.  That's what I am doing.  Works great.  If they support sub-domains.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.