diff --git a/ecrire/inc/flock.php b/ecrire/inc/flock.php
index a4640271df2264a9b186e9ba624f1b8e00ea18ba..c45578e1f1c58883a02e254c90ba158d03191d80 100644
--- a/ecrire/inc/flock.php
+++ b/ecrire/inc/flock.php
@@ -141,18 +141,24 @@ function supprimer_fichier($fichier) {
 
 //
 // Retourne $base/${subdir}/ si le sous-repertoire peut etre cree,
-// $base/${subdir}_ sinon ; le flag $nobase signale qu'on ne veut pas de $base/
+// $base/${subdir}_ sinon ; $nobase signale qu'on ne veut pas de $base/
+// On peut aussi ne donner qu'un seul argument, 
+// subdir valant alors ce qui suit le dernier / dans $base
 //
 // http://doc.spip.org/@sous_repertoire
-function sous_repertoire($base, $subdir, $nobase = false) {
-	if (!preg_match(',[/_]$,', $base)) $base .= '/';
+function sous_repertoire($base, $subdir='', $nobase = false) {
 	$base = str_replace("//", "/", $base);
+	if (preg_match(',[/_]$,', $base)) $base = substr($base,0,-1);
+	if (!strlen($subdir)) {
+		$n = strrpos($base, "/");
+		if ($n === false) return $nobase ? '' : ($base .'/');
+		$subdir = substr($base, $n+1);
+		$base = substr($base, 0, $n+1);
+	} else {
+		$base .= '/';
+		$subdir = str_replace("/", "", "$subdir");
+	}
 	$baseaff = $nobase ? '' : $base;
-	# $base = 'IMG/distant/' ou 'IMG/distant_'
-
-	if (!strlen($subdir)) return $baseaff;
-
-	$subdir = str_replace("/", "", "$subdir");
 
 	if (@file_exists("$base${subdir}.plat"))
 		return "$baseaff${subdir}_";; 
diff --git a/ecrire/inc/utils.php b/ecrire/inc/utils.php
index 8b3a6ad0305233630bee4ed228e85d53e4b0688f..e124ddb1e73ed29c03def8aa00aff6d686c1d535 100644
--- a/ecrire/inc/utils.php
+++ b/ecrire/inc/utils.php
@@ -935,7 +935,7 @@ function spip_initialisation($pi=NULL, $pa=NULL, $ti=NULL, $ta=NULL) {
 	define('_DIR_SESSIONS', $ti . "sessions/");
 	define('_DIR_TRANSFERT', $ti . "upload/");
 	define('_DIR_CACHE', $ti . "CACHE/");
-	define('_DIR_DTD', $ti . "CACHE/dtd");
+	define('_DIR_DTD', $ti . "CACHE/dtd/");
 	define('_DIR_SKELS', $ti . "CACHE/skel/");
 	define('_DIR_TMP', $ti);
 
@@ -991,8 +991,8 @@ function spip_initialisation($pi=NULL, $pa=NULL, $ti=NULL, $ta=NULL) {
 
 	define('_DOCTYPE_ECRIRE', 
 		// "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>\n");
-		// "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
-	            "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>\n");
+		"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
+	       //     "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>\n");
 
 	define('_DOCTYPE_AIDE', 
 	       "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>");
diff --git a/ecrire/inc/valider_xml.php b/ecrire/inc/valider_xml.php
index 6bcb1645b770d0d8bb5c27bde78be7e40374422b..542e2d5b456200a79a3c41c169842831652bd937 100644
--- a/ecrire/inc/valider_xml.php
+++ b/ecrire/inc/valider_xml.php
@@ -67,7 +67,8 @@ function analyser_dtd($grammaire, $avail, &$dtc)
 	if ($avail == 'SYSTEM')
 	  $file = $grammaire;
 	else
-	  $file = _DIR_CACHE . preg_replace('/[^\w.]/','_', $grammaire);
+	  $file = sous_repertoire(_DIR_DTD);
+	  $file .= preg_replace('/[^\w.]/','_', $grammaire);
 
 	if (@is_readable($file)) {
 		lire_fichier($file, $dtd);
diff --git a/ecrire/public/compiler.php b/ecrire/public/compiler.php
index a0e41605b88b23e7b2fe740d299733923dac1818..529e735cc07f756273cd0ce57654e5aab80ed663 100644
--- a/ecrire/public/compiler.php
+++ b/ecrire/public/compiler.php
@@ -772,7 +772,7 @@ function public_compiler_dist($squelette, $nom, $gram, $sourcefile) {
 	$secondes = spip_timer('calcul_skel');
 	spip_log("COMPIL ($secondes) ["
 		.preg_replace(',\.html$,', '', $sourcefile)
-		."] ".sous_repertoire(_DIR_CACHE, 'skel', true)."$nom.php");
+		."] $nom.php");
 
 	$code = "<"."?php
 /*
diff --git a/ecrire/public/composer.php b/ecrire/public/composer.php
index 63e92aa45cdfb625047a9b9aeb80bb1424144d95..edbe947b6c8bba4137d02762d762100a0218ad28 100644
--- a/ecrire/public/composer.php
+++ b/ecrire/public/composer.php
@@ -39,7 +39,7 @@ function public_composer_dist($squelette, $mime_type, $gram, $sourcefile) {
 	if (function_exists($nom))
 		return $nom;
 
-	$phpfile = sous_repertoire(_DIR_CACHE, 'skel') . $nom . '.php';
+	$phpfile = sous_repertoire(_DIR_SKELS) . $nom . '.php';
 
 	// si squelette est deja compile et perenne, le charger
 	if (!squelette_obsolete($phpfile, $sourcefile)