TheWebExpert Posted December 19, 2019 Share Posted December 19, 2019 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? Quote Link to comment https://forums.phpfreaks.com/topic/309718-need-help-with-redirect/ Share on other sites More sharing options...
requinix Posted December 20, 2019 Share Posted December 20, 2019 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? Quote Link to comment https://forums.phpfreaks.com/topic/309718-need-help-with-redirect/#findComment-1572695 Share on other sites More sharing options...
TheWebExpert Posted December 21, 2019 Author Share Posted December 21, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/309718-need-help-with-redirect/#findComment-1572746 Share on other sites More sharing options...
requinix Posted December 21, 2019 Share Posted December 21, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/309718-need-help-with-redirect/#findComment-1572750 Share on other sites More sharing options...
TheWebExpert Posted December 23, 2019 Author Share Posted December 23, 2019 I am forwarding the DNS of www.mullins-storage.com to www.br-storage.com. Quote Link to comment https://forums.phpfreaks.com/topic/309718-need-help-with-redirect/#findComment-1572847 Share on other sites More sharing options...
requinix Posted December 23, 2019 Share Posted December 23, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/309718-need-help-with-redirect/#findComment-1572854 Share on other sites More sharing options...
TheWebExpert Posted December 28, 2019 Author Share Posted December 28, 2019 All right, they changed it to an alias. However, the code simply times out. Quote Link to comment https://forums.phpfreaks.com/topic/309718-need-help-with-redirect/#findComment-1572941 Share on other sites More sharing options...
requinix Posted December 28, 2019 Share Posted December 28, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/309718-need-help-with-redirect/#findComment-1572952 Share on other sites More sharing options...
TheWebExpert Posted December 29, 2019 Author Share Posted December 29, 2019 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? Quote Link to comment https://forums.phpfreaks.com/topic/309718-need-help-with-redirect/#findComment-1572963 Share on other sites More sharing options...
requinix Posted December 29, 2019 Share Posted December 29, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/309718-need-help-with-redirect/#findComment-1572967 Share on other sites More sharing options...
TheWebExpert Posted December 30, 2019 Author Share Posted December 30, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/309718-need-help-with-redirect/#findComment-1572969 Share on other sites More sharing options...
requinix Posted December 30, 2019 Share Posted December 30, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/309718-need-help-with-redirect/#findComment-1572970 Share on other sites More sharing options...
TheWebExpert Posted December 31, 2019 Author Share Posted December 31, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/309718-need-help-with-redirect/#findComment-1572984 Share on other sites More sharing options...
requinix Posted December 31, 2019 Share Posted December 31, 2019 Is it just me or have you basically just stated that what you've been trying to do in this thread is impossible? Quote Link to comment https://forums.phpfreaks.com/topic/309718-need-help-with-redirect/#findComment-1572986 Share on other sites More sharing options...
ginerjm Posted December 31, 2019 Share Posted December 31, 2019 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! Quote Link to comment https://forums.phpfreaks.com/topic/309718-need-help-with-redirect/#findComment-1572987 Share on other sites More sharing options...
TheWebExpert Posted December 31, 2019 Author Share Posted December 31, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/309718-need-help-with-redirect/#findComment-1573020 Share on other sites More sharing options...
requinix Posted December 31, 2019 Share Posted December 31, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/309718-need-help-with-redirect/#findComment-1573022 Share on other sites More sharing options...
ginerjm Posted January 1, 2020 Share Posted January 1, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/309718-need-help-with-redirect/#findComment-1573035 Share on other sites More sharing options...
TheWebExpert Posted January 2, 2020 Author Share Posted January 2, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/309718-need-help-with-redirect/#findComment-1573071 Share on other sites More sharing options...
ginerjm Posted January 2, 2020 Share Posted January 2, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/309718-need-help-with-redirect/#findComment-1573072 Share on other sites More sharing options...
isabelwilliams Posted January 7, 2020 Share Posted January 7, 2020 There are several hosting that cost $2 per month where you can host multiple sites, just google it. Quote Link to comment https://forums.phpfreaks.com/topic/309718-need-help-with-redirect/#findComment-1573158 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.