0

I have a service service[dot]com. The service allows, for example, to create a landing page, which after creation is available at app.service[dot]com/<long_path_here_with_symbols>.

Our user needs the created page to open not at this long our address, but at his branded one, for example, landing.client[dot]com. There can be as many clients as you like: landing.client1[dot]com, landing.client2[dot]com, landing.client3[dot]com, and so on, so the solution must be scalable. It is important that after switching to landing.client[dot]com, there should not be a redirect to app.service[dot]com/<long_path_here_with_symbols>, and landing.client[dot]com should remain in the browser address bar, but the app.service[dot]com/<long_path_here_with_symbols> page should open.

As far as I was able to find out, this is done somehow through aliases, not redirects. The option of embedding an iframe to the client on the landing.client[dot]com page with our landing is not considered. I am sure that the problem can be somehow solved by editing the DNS on the client and with certain settings on the service[dot]com/app.service[dot]com side.

I studied many different sources, but I want to note one here - https://stackoverflow.com/a/17753713 - I registered CNAME cname.service[dot]com at landing.client[dot]com (now the call goes to the ip of our server when clicking on landing.client[dot]com, I also realized that I need a VPS, not a regular shared-hosting). I understand that editing the CNAME does not open another site, but simply gives the ip to access.

From various articles on the Internet, I realized that when landing.client[dot]com opens, then there is a call to the ip on which cname.service[dot]com lies, however, then the target server must understand what they want from it (namely, you need to open, for example, app.service[dot]com/<long_path_here_with_symbols>).

I saw that it seems that aliases are written in the Apache config, but even if so, I don’t understand how adding these aliases can be made dynamic.

The description of the question turned out to be chaotic, but I hope that this information is enough to understand what I'm trying to do.

Our service is written in PHP.

UPD 1: Following the advice of @arkascha I decided to simplify the task a little. So, to solve my problem I did 2 steps:

  1. I created test service subdomain cname.service.com, then I created landing.client.com and added CNAME cname.service.com. IN landing.client.com. Now if I go to landing.client.com I see that IP for landing.client.com is the same with cname.service.com in my browser console.

  2. In cname.service.com site root I created .htaccess file with these lines:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\..* [NC]
RewriteRule ^$ ./index.php?landing_id=%1 [L]

Now I expected, that if I go to landing.client.com, browser will open cname.service.com and I will get GET-parameter landing_id="landing.client.com", but it doesn't. I keep trying to solve the problem on shared-hosting, not vps.

UPD 2:

If I go to landing.client.com manually the browser’s network console shows:

Status: 200
IP: 89.255.251.130:80

URL in browser’s address bar doesn’t change. In this case access.log and error.log are empty on both sites (landing.client.com and cname.service.com)

If I go to cname.service.com manually the browser’s network console shows:

Status: 200
IP: 89.255.251.130:80

Of course, it adds new line in access.log on cname.service.com ("GET / HTTP/1.1" 200)

When I request landing.client.com, index.php script of cname.service.com doesn’t get called.

I keep trying to solve the problem on shared-hosting, not vps.

paperman
  • 1
  • 2
  • Two steps are required: 1. you need to take care that the DNS resolution for `landing.example.com` points to your service's http server. And 2. you need to implement a rewrite rule that extracts the requested host name from the requests and hands that one over to your application logic so that the branding can be adjusted accordingly. Note: such a rewrite rule implements an _internal_ rewrite, so the URL visible to the user stays the same. – arkascha Sep 19 '22 at 07:53
  • @arkascha 1. Do you mean CNAME for landing.example.com to service.com? 2. Can I add such rewrite rule in my .htaccess at service.com? – paperman Sep 19 '22 at 10:30
  • 1
    Doesn't matter if it is a CNAME or an A record. It has to point to your application service, obviously. And you can add such a rewrite rule to a distributed configuration file (".htaccess") of you do not have access to the actual server configuration (which you should prefer). If you use a distributed configuration file then it has to be located in the `DOCUMENT_ROOT` of the server's fallback host (so the first of the virtual hosts defined for that server). – arkascha Sep 19 '22 at 15:26
  • @arkascha I'm trying to do so for tests: 1. I created test service subdomain `cname.service.com`, then I created `landing.client.com` and added CNAME `cname.service.com. IN landing.client.com`. Now if I go to landing.client.com I see that IP for `landing.client.com` is the same with `cname.service.com` in my browser console. 2. In cname.service.com site root I created .htaccess file with these lines: `RewriteEngine On RewriteCond %{HTTP_HOST} !^www\..* [NC] RewriteRule ^$ ./index.php?landing_id=%1 [L]` but if I go to landing.client.com, it doesn't open cname.service.com. Is there a mistake? – paperman Sep 20 '22 at 08:19
  • Sounds fine so far. Do I have to ask what does "it doesn't open cname.service.com" actually mean? Please do not add such details in a comment here. I suggest you add an update at the bottom of the question itself. That is far better to read, you can make a summary of the current situation there. – arkascha Sep 20 '22 at 09:46
  • @arkascha I've done it. Now question has UPD section. Thank you for note. – paperman Sep 20 '22 at 10:42
  • Thanks. Could you please also elaborate on the "it doesn't open cname.service.com" question? – arkascha Sep 20 '22 at 12:46
  • @arkascha I expected, that if I go to landing.client.com, browser will open cname.service.com and I will get GET-parameter `landing_id="landing.client.com"`, but it doesn't. – paperman Sep 20 '22 at 13:17
  • Sorry, but what doesn't? The browser doesn't go there, what _exactly_ does that mean, or does the php script not receive the parameter? – arkascha Sep 20 '22 at 13:29
  • @arkascha I think my English is not good enough, sorry. I try to open cname.service.com by going landing.client.com to receive GET-parameter `landing_id="landing.client.com"` (based on rewrite rule). I need this parameter to show needed landing page on client url (landing.client.com) without redirect from landing.client.com to cname.service.com. – paperman Sep 20 '22 at 15:50
  • If you make a request to `https://landing.client.com` in a browser, what exactly happens? What does your browser's network console reveal what response it receives? Does that URL change or not? What does your http server's access and error log files show for that request and does your script `index.php` get called or not, if so with what parameters? – arkascha Sep 20 '22 at 17:34
  • @arkascha I added UPD 2 section to question. – paperman Sep 21 '22 at 05:43
  • It is impossible that the access file of the http server's are empty when you make a test request. So obviously the request does not get sent at all. Sounds like you are looking at client side cached results instead. Or _maybe_ a proxy inbetween. Always make test requests in a fresh anonymous browser window and use "deep reloads" in your browser to eliminate client side caching. – arkascha Sep 21 '22 at 06:58
  • @arkascha I always use anonymous browser window for tests. It seems to me that my task cannot be solved on shared-hosting. I'll try to do it on a VPS with a dedicated IP. Then I will share the results. – paperman Sep 21 '22 at 08:58
  • @arkascha it works on VPS, but now I see this output of `print_r($_GET)` in index.php: `Array ( [landing_id] => )` — there is no landing_id. – paperman Oct 06 '22 at 18:49
  • Remove `index.php` from the `DirectoryIndex` directive. – arkascha Oct 07 '22 at 13:32
  • @arkascha I found out that `RewriteRule ^$ ./index.php?landing_id=%{HTTP_HOST} [L]` works. Now I see `Array ( [landing_id] => landing.client.com)` – paperman Oct 07 '22 at 13:43
  • Oh sorry, sure, your original `RewriteCond` did not capture anything, so there is nothing contained in `%1` then. Did not check again with the question above today. – arkascha Oct 07 '22 at 13:57

0 Answers0