简体   繁体   中英

Show different content based on country code top-level domain

I have a website which can be accessed in one of two ways: www.foo.com and www.foo.de. Presumably the www.foo.de visitors are from Germany, and there are about a half dozen pages on the site that will soon have German-language equivalents - eg the homepage (index.php), the management page (management.php), the careers page (careers.php) and so on.

What we'd like to do is serve the new German-language alternate pages if the user is visiting the site via www.foo.de. This is a static site, nothing dynamic.

I thought maybe the way to do it (though clunky) is to

  1. figure out if they're a ".de" or a ".com" visitor
  2. Set a URL parameter, such as ?lang=de, if they're a ".de" visitor
  3. Put a little bit of code in the header of the few relevant pages that redirect the user to the other version of the page if the parameter is "lang=de", or, I suppose, if it exists at all.

Am I making this too complicated? To be honest, I don't care if it's an enterprise-level solution that is future proof and easily expandable. If it's sloppy and somewhat manual, that's fine with me.

I've tried using RewriteEngine/RewriteRule in the htaccess file, but I may be over my head here. I can't seem to get anything to detect just the top-level domain.

Help! And thanks!

<?php
$domain = $_SERVER["SERVER_NAME"];

if (strtolower(substr($domain, -3, 3)) == ".de")
    die(header("Location:http://example.com"));
?>

You could use javascript as well.

document.URL

Parse the url for the country top level domain and redirect to the ?lang=de link.

您也可以将url的映射映射到不同的IP /服务器。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM