So, when I want to link my users to a specific page I always use (in PHP):
"http://" . $_SERVER["HTTP_HOST"] . "/page.php"
to be sure that the link points to the page they're currently surfing (and not one of the server aliases).
But with IDN names, HTTP_HOST
is set to xn--hemmabst-5za.net
(for example) - which of course works but doesn't look very nice. Is there a way to have HTTP_HOST
set to the correct IDN name in these cases (in this case - hemmabäst.net
)?
I rather do it in Apache before it comes to PHP because otherwise I'd have to replace all my usage of $_SERVER["HTTP_HOST"]
.
Any ideas?
Since the allowed set of characters in a DNS name is so narrow, the actual domain name is the name with the hyphens in it. So what you see in HTTP_HOST is, in fact, the correct name. The translation to unicode is a bit of sugar-coating applied for display only when the name gets to the browser (and not even by all browsers). Any work you want to do with the URL should be done with the original ASCII ("punycode") version, not the Unicode version, or things may not work the way you expected.
That said, if you want to translate the punycode version of the domain name into Unicode for display purposes within your web page (presumably using PHP), then use the PHP IDN functions.
Don't quote me on it, but I don't think so.
I believe it's the client software that converts the domain name from the IDN format keyed by the user into the ASCII format to query the DNS servers with, so when it gets sent across the wire to your Apache server, it's already been converted into so-called "punycode."
I suppose you might be able to put something at the head of your scripts (or even in a prepended header file - see
php.ini
) that convertsxn--hemmabst-5za.net
into the original format (hemmabäst.net
) that your scripts can use (perhaps writing it back into$_SERVER['HTTP_HOST']
or into a global variable.There may even be something out there already capable of doing this for you.