1

I have a main domain, www.mycompany.com, which has several groups of sites, which are available in several languages:

www.mycompany.com/international

www.mycompany.com/sales/en
www.mycompany.com/sales/fr

www.mycompany.com/customers/en
www.mycompany.com/customers/fr

etc.

Once visitor access to www.mycompany.com, he will be auto-redirected to a Site version depending on his IP (probably using a third-party plugin like Country Redirect, once available for Craft 3).

The problem is that when I set up the Sites, Craft force to set a primary Site. So I choose the www.mycompany.com/international version.

But when Site is saved, the Base URL is displayed as www.mycompany.com instead of www.mycompany.com/international, and all URLs in this one are now like www.mycompany.com/my-slug instead of www.mycompany.com/international/my-slug.

This probably can be solved by pre-checking all links, adding the slug inside the URL if current Site id is the www.mycompany.com/international version, then adding a routing rule for all /international/* requests.

But it sounds a bit tricky in the some cases, so I wondered if there was a cleaner way to achieve this?

  • 1
    Did you set siteUrl in config/general.php for your sites? – carlcs Jan 25 '18 at 14:06
  • Whoops... siteUrl was set to ((isset($_SERVER['HTTPS'])) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'] instead of an array of site handle => site base URL. Thank you! – Romain Poirier Jan 25 '18 at 14:53
  • Would you mind sharing your solution as an official answer @RomainPoirier? Might end up helping someone in the future. – Brad Bell Jan 25 '18 at 16:57
  • Of course, thank you for asking this. carlcs has posted his answer, I'm just waiting for further help, because I'm still facing errors with template / routing after setting the siteUrl. I didn't find out how to fix this without having to write weird routing rules. – Romain Poirier Jan 26 '18 at 8:53
1

It looks like you forgot to setup siteUrl in config/general.php for your sites.

'siteUrl' => [
    'landing' => 'https://www.mycompany.com/international',
    'sales-en' => 'https://www.mycompany.com/sales/en',
    'sales-fr' => 'https://www.mycompany.com/sales/fr',
    ...
],
|improve this answer|||||
  • Thank you, now international links look like www.mycompany.com/international/my-slug. But I'm facing another issue: each of these URLs (including international homepage) returns a 404 Template not found error. It looks like it try ot load templates of an international/ subfolder that doesn't exists. Do you know how can I fix this without using Routing? – Romain Poirier Jan 25 '18 at 16:20
  • No, templates/international/index.html should not be required as it falls back to templates/index.html if you rely on template path routing. If you do set an entry template in the section settings, you can point to whatever template you want for each site individually. – carlcs Jan 26 '18 at 9:47
  • It makes sense... On the Single > Homepage, Site Settings URI is set to blank (Leave blank if this is the homepage) and template is set to same file for each Site. Homepage template is found for each Site, except for /international which is set as Primary and that Craft can't find (404 error). Its sounds like a bug that I should report, no? – Romain Poirier Jan 26 '18 at 11:16
  • Sorry but I can’t say that. 404 can be a lot, server configs etc.?! – carlcs Jan 26 '18 at 18:13
  • 2
    This was a CRAFT_SITE issue. CRAFT_SITE wasn't set there: htdocs/index.php & htdocs/international/index.php. I thought it was set automatically because this Site was set as Primary. Thank you Brad for pointing it out! – Romain Poirier Jan 30 '18 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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