I still haven't tested your modification sorry, but the code is
very similar to the one I use. Just to say that HTTP_HOST does
not always exist in some rare cases, with some exotic clients
(generally bad robots). Maybe a try/except would help, but what
to use instead?  Christoph Zwerschke a écrit : sophana wrote:
Yes I have a rewrite rule, but the rule does not apply in this
case. This may explain that I don't get the expected result.
What I don't understand is that, even if the url was rewritten,
the result is simply wrong... The apache name must not be used.
It does not matter whether your URL is rewritten or not. If (and
only  if) the engine is on, then Apache (mod_rewrite) sets
SCRIPT_URI, which  includes the canonical name (the one that you
don't want), and this is  returned by serverURL().  This does
the same as serverURL() except for checking SCRIPT_URI, right? I
wouldn't have written that if the result was the same... ;-)  I
only wanted to make sure that the only reason why the result is
not  the sam