Domain mask for subfolders and different sites

Hi there,
I have a situation, where I have two sites (Drupal) hosted in Pantheon
dev-mysite1[dot]pantheonsite[dot]io
dev-mysite2[dot]pantheonsite[dot]io

Unfortunately they don’t support a multisite architecture where I can create two symlinks eu and us and this way serve the two different sites from the same domain.

Thus am looking to achieve this:

Use my domain mydomain[dot]com with two subfolders, so i.e. mydomain[dot]com/eu points to dev-mysite1[dot]pantheonsite[dot]io/ and mydomain[dot]com/us points to dev-mysite2[dot]pantheonsite[dot]io

I have read another thread about using Cloudflare workers but not sure if it’s the same scenario I am looking for.

Is this something I could achieve with any Cloudflare feature?

Many Thanks,
Juan

Hey @juan.colomer,
I will get straight to the point.
There are several ways to achieve that, and you will do that within your server set up.
CloudFlare will follow any redirects you will call to (within your server’s or app code)
That depends the server that you’re using (Apache, ISS, etc) and use the right redirects on your code.
You can follow the topic right over here, which more or less seems to be very similar to yours.

Cloudflare workers -> You can check the GeoIP redirection worker

However, (my personal opinion on this matter), I wouldn’t suggest an automated redirect users based on their location, unless of course this is something that has to do with the law.
In that case, you can use your main domain for the main language and redirect users to the other site with a simple button on the header that will tell the users “US site or anything else” and get them to the sub-folder-ed site.

Let us find more about what you want to achieve and we will be able to help more.

I want also here to add, that you could also use the sub-domain solution, which seems to me closer to the one that you want to achieve. All you need to do is again 2 sites on Pantheon, that you already have create a sub domain within your Domain provider, add this sub-domain to CloudFlare DNS, and redirect users choice. (for and example you could create a pop up and ask the user where they prefer to continue on the US site or another).

To create a subdomain in CloudFlare Dashboard, you just need to be logged in, then go to the DNS tab, scroll down to the Add a record section, add an A or CNAME record, and add the subdomain,

don’t forget after some minutes to go to the Caching tab, and Purge everything

Hey Stefano,
I really appreciate such a though response.
Please let me give you some more insight about the issue I’m trying to solve.

There are several ways to achieve that, and you will do that within your server set up .

Unfortunately Pantheon won’t allow me to make any modifications on nginx.conf

Pantheon does not support managing redirects in .htaccess files, since they are ignored by NGINX for reduced resource consumption and increased efficiency. This configuration is standard across all Pantheon sites, and modifications to the nginx.conf file are not supported.

That was actually the very first approach I tried to take but didn’t work because of not getting access to the nginx configuration.

In that case, you can use your main domain for the main language and redirect users to the other site with a simple button on the header that will tell the users “US site or anything else” and get them to the sub-folder-ed site.

That’s actually the current behaviour :smile: so hopefully I can manage to reproduce it on the new setup with Pantheon.

create a sub domain within your Domain provider, add this sub-domain to CloudFlare DNS, and redirect users choice. (for and example you could create a pop up and ask the user where they prefer to continue on the US site or another).

We have a pop up too so users can land into the default site (EU) and confirm wether they want to continue towards EU site or instead, visit the US version.

I think the key thing here is, even although I can create a subdomain on the AWS side, it will only allow me to create something like us.mydomain.com (subdomain) whereas, what I actually need is mydomain.com/us (subfolder).

On the previous architecture, creating the subfolder was straightforward with symlinks, since the setup was a multisite, this is, both sites on the same root folder like:

/
web

[us] -> siteus (symlink to us site)
[eu] -> / (symlink to default)

sites
default (siteeu)
siteus

With the new set up at Pantheon, the two sites are now totally independent. They have their own root so won’t be able to add symlinks anymore in order to create the actual subfolders /eu and /us

So basically the hassle here is how to manage to get those subfolders (hopefully generated with Cloudflare) so my new architecture maintains the current behaviour, this is:
mysiteDOTcom (by default to PantheonSiteEU site)
mysiteDOTcom/EU (serves PantheonSiteEU site)
mysiteDOTcom/US (serves PantheonSiteUS site)

Is there anyway to achieve this i.e. creating a subdomain like:
us.mydomain.com and convert this into mydomain.com/us, and at the same time, this serves PantheonSiteUS site?

I hope this gives more clarification one the actual issue.
Thank you very much once again @StefanoWP

UPDATE
I managed to create a subdomain on Route53 like eu.mywebsite.com CNAMEd to mywebsite.com/eu
The idea is now point that CNAME mywebsite.com/eu to [https://dev-mysite1.pantheonsite.io](https://dev-mysite1.pantheonsite.io/

Getting there! :sweat_smile:

1 Like

Hey @StefanoWP do you think I could apply what’s mentioned in this cloudflare’s post in regards the subfolders?


This is using the Worker approach which I had mentioned initially.

Hey @juan.colomer
Yes I have completely understand your set up.
However I am not feeling confident that will do the trick with the /subfolders in your case.

There is another scenario where you can use your settings.php (you’re using Drupal am I right?) and redirect from subdomain to subdirectory Path within your settings.php

// Redirect subdomain to a specific path.
// Check if Drupal or WordPress is running via command line
if (isset($_ENV['PANTHEON_ENVIRONMENT']) && ($_SERVER['HTTP_HOST'] == 'subdomain.example.com') && (php_sapi_name() != "cli")) {
  $newurl = 'https://www.example.com/subdirectory'. $_SERVER['REQUEST_URI'];
  header('HTTP/1.0 301 Moved Permanently');
  header("Location: $newurl");

  // Name transaction "redirect" in New Relic for improved reporting (optional).
  if (extension_loaded('newrelic')) {
    newrelic_name_transaction("redirect");
  }

  exit();
}

Here is a link with all the redirects you can use from Pantheon.

yep, that’s the right thing on workers side, however you need to check hands on, if that works, I can’t be sure that this will get all of your /subdirectory assets, maybe will need some further customization to apply in your case.

Thanks @StefanoWP,
Yep, my project is a Drupal 8 site so I’ll give a go to the settings.php amendments firstly and if that does’t do the trick, will probably need to try the Workers approach.