diff --git a/ecrire/inc/utils.php b/ecrire/inc/utils.php
index abac0184833e9aafd900dcc5d3205f363ccc5ea8..31fc63b170d9aa599f8e085b9a6c4ebcd054cd86 100644
--- a/ecrire/inc/utils.php
+++ b/ecrire/inc/utils.php
@@ -1540,13 +1540,20 @@ function url_de_base($profondeur=null) {
 		OR (isset($_SERVER['HTTPS']) AND
 		    test_valeur_serveur($_SERVER['HTTPS']))
 	) ? 'https' : 'http';
-	# note : HTTP_HOST contient le :port si necessaire
-	$host = $_SERVER['HTTP_HOST'];
-	if (isset($_SERVER['SERVER_PORT'])
-		AND $port=$_SERVER['SERVER_PORT']
-		AND strpos($host,":")==false){
-		if ($http=="http" AND $port!=80) $host.=":$port";
-		if ($http=="https" AND $port!=443) $host.=":$port";
+	if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])){
+		$host = strtr($_SERVER['HTTP_X_FORWARDED_HOST'], "<>?\"' \r\n", '________');
+	}
+	else {
+		# note : HTTP_HOST contient le :port si necessaire
+		$host = $_SERVER['HTTP_HOST'];
+		if (isset($_SERVER['SERVER_PORT'])
+			AND $port=$_SERVER['SERVER_PORT']
+			AND strpos($host,":")==false){
+			if (!defined('_PORT_HTTP_STANDARD')) define('_PORT_HTTP_STANDARD','80');
+			if (!defined('_PORT_HTTPS_STANDARD')) define('_PORT_HTTPS_STANDARD','443');
+			if ($http=="http" AND !in_array($port,explode(',',_PORT_HTTP_STANDARD))) $host.=":$port";
+			if ($http=="https" AND !in_array($port,explode(',',_PORT_HTTPS_STANDARD))) $host.=":$port";
+		}
 	}
 	if (!$GLOBALS['REQUEST_URI']){
 		if (isset($_SERVER['REQUEST_URI'])) {
diff --git a/ecrire/public/assembler.php b/ecrire/public/assembler.php
index 715df4a15498c6ccfd1bf17966bae0b10e63d060..730623077ffec6c48d92241ef3323c7835f4541a 100644
--- a/ecrire/public/assembler.php
+++ b/ecrire/public/assembler.php
@@ -194,6 +194,10 @@ function calculer_contexte_implicite(){
 		'notes' => $notes?$notes('','contexter_cache'):'',
 		'spip_version_code' => $GLOBALS['spip_version_code'],
 	);
+	if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])){
+		$contexte_implicite['host'] .= "|" . $_SERVER['HTTP_X_FORWARDED_HOST'];
+	}
+
 	return $contexte_implicite;
 }