gebeer Posted January 16, 2019 Share Posted January 16, 2019 Hello, I searched the forum but couldn't find posts about the exact same scenario that I am facing. Instead of serving the different languages through a language specific URL, Each language should have their own domain. Everything is served from one single PW installationh, no multisite setup. So instead of domain.com/ domain.com/de/ domain.com/pl/ etc. the language versions should be available under domain.com domain.de domain.pl etc. I found how to switch the language based on the http hostname. But there are a few more questions: How to properly implement the redirection in .htaccess How to configure PW so it doesn't append the language to the URL? (just leave the language names out on the home page settings tab?) I hope someone has had that scenario before and can help out with some hints. Thank you. 1 Link to comment Share on other sites More sharing options...
Autofahrn Posted January 16, 2019 Share Posted January 16, 2019 Clever idea. I've just test-implemented that on one of my multi-language sites with .de and .com domains and it works pretty smooth following these steps: all DNS entries point to the same PW instance root in site/config.php I've added all allowed domain names in _init.php I've quickly added this (only for com, should match a field in language setting): if(strpos($config->httpHost, ".com") > 0) { foreach($languages as $lang) { if($lang->name == 'en') { $user->language = $lang; break; } } } That's it, now all language fields follow the selected language. Switching between languages is now switching between domain names. Thanks for that hint! 6 Link to comment Share on other sites More sharing options...
Jan P. Posted January 16, 2019 Share Posted January 16, 2019 Hello, we found the following solution that is quite similar to the suggestion from Autofahrn. Our setup includes two languages - de (german) as default for *.de domain (default language) - en (english) for *.com domain In _init.php there is just: if (preg_match("/(:2284|\.com)/", $config->httpHost)) { $user->language = $languages->get('englisch'); } Your question no. 2: It is important that you configure the settings for your root page to "/" for each language. In that case PW doesn't prefix your URL paths for the children. Be careful! In case you use the front page editor - when a child page has the same path for every language, the front page editor is not able to save the page correctly. You have to use the backend. But if there are differences, for example *.com/imprint and *.de/impressum - the front page editor works fine. 6 Link to comment Share on other sites More sharing options...
wbmnfktr Posted January 16, 2019 Share Posted January 16, 2019 Be honest... you guys knew I would need this kind of language switcher very soon, too. ? Link to comment Share on other sites More sharing options...
gebeer Posted January 17, 2019 Author Share Posted January 17, 2019 @Autofahrn @Jan P. Thank you very much for your input. Besides the changes mentioned, did you need any additional rewrite rules in .htaccess? Link to comment Share on other sites More sharing options...
Jan P. Posted January 17, 2019 Share Posted January 17, 2019 Hello, no, there is no need to change the vendor .htaccess file to do this. At first sight I also thought it would be necessary but it is not. 2 Link to comment Share on other sites More sharing options...
Autofahrn Posted January 18, 2019 Share Posted January 18, 2019 Just verified that this can be made running in combination with @BitPoet's simple language switcher: I've basically added a text field url_domain to the language template and moved the default language detection from _init.php into the updatePath method (so my loop makes much more sense now): public function updatePath($path) { $httpHost = $this->wire('config')->httpHost; $languages = $this->wire('languages'); // Setup default language by domain root foreach($languages as $lang) { if(($lang->url_domain != "") && (strpos($httpHost, $lang->url_domain) > 0)) { $this->user->language = $lang; break; } } This change eliminates most of the other default processing, since the default already set based on the domain name. Throughout the site I'm using localUrl to generate internal link urls, that code was changed to get rid of the language segment in case it is the default for the current domain: public function hookPageLocalUrl(HookEvent $event) { $lang = $this->getLanguage($event->arguments(0)); $config = $this->wire('config'); if(($lang->url_domain != "") && (strpos($config->httpHost, $lang->url_domain) > 0)) // Default for this domain? $event->return = $config->urls->root . ltrim($event->object->path, "/"); else $event->return = $config->urls->root . ltrim($lang->name . $event->object->path, "/"); } The benefit of this is, that languages can be added to the site without the need having an associated domain for each. And it does not break old links on my site, which still have the language in the url. So www.domain.com/pagename and www.domain.de/en/pagename still retrieve the same content and another language may be reached through www.domain.de/fr/pagename or www.domain.com/fr/pagename for example. Edit: Just in case someone wants to see this in action: www.versus-x.com (english)www.versus-x.de (german)www.versus-x.com/de/ (also german)www.versus-x.com/fr/ (french, incomplete, for testing only)www.versus-x.de/fr/ (french, only parts as well) 3 Link to comment Share on other sites More sharing options...
dab Posted September 12, 2019 Share Posted September 12, 2019 On 1/16/2019 at 1:45 PM, Jan P. said: Hello, we found the following solution that is quite similar to the suggestion from Autofahrn. Our setup includes two languages - de (german) as default for *.de domain (default language) - en (english) for *.com domain In _init.php there is just: if (preg_match("/(:2284|\.com)/", $config->httpHost)) { $user->language = $languages->get('englisch'); } Your question no. 2: It is important that you configure the settings for your root page to "/" for each language. In that case PW doesn't prefix your URL paths for the children. Be careful! In case you use the front page editor - when a child page has the same path for every language, the front page editor is not able to save the page correctly. You have to use the backend. But if there are differences, for example *.com/imprint and *.de/impressum - the front page editor works fine. This works beautifully, thanks. & if any users need help on configuring their DNS (to point 2 domains to a single install of PW) on WHM use the >cPanel > Domains > Aliases function to add your extra domains (after enabling on > Server Configuration > Tweak Settings > Domains > "Allow users to park subdomains of the server’s hostname". Link to comment Share on other sites More sharing options...
uiui Posted April 26, 2020 Share Posted April 26, 2020 On 1/18/2019 at 1:36 AM, Autofahrn said: The benefit of this is, that languages can be added to the site without the need having an associated domain for each. And it does not break old links on my site, which still have the language in the url. So www.domain.com/pagename and www.domain.de/en/pagename still retrieve the same content and another language may be reached through www.domain.de/fr/pagename or www.domain.com/fr/pagename for example. Wouldn't you want to not have the same content available multiple times? Shouldn't you rather redirect the old URLs to the new domain? Link to comment Share on other sites More sharing options...
Autofahrn Posted April 26, 2020 Share Posted April 26, 2020 1 hour ago, uiui said: Wouldn't you want to not have the same content available multiple times? At least in my setups I prefer to see the same content, regardless if I come from the international domain (i.e. www.domain.com/pagename) or use the language sub-path (www.domain.de/en/pagename). 1 hour ago, uiui said: Shouldn't you rather redirect the old URLs to the new domain? Sure you could, with this setup its just not necessary. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now