diff --git a/library/ZendAfi/Controller/Dispatcher/Standard.php b/library/ZendAfi/Controller/Dispatcher/Standard.php
new file mode 100644
index 0000000000000000000000000000000000000000..992d95a138cbf21c002b2fb4678ac2cf4b4e261b
--- /dev/null
+++ b/library/ZendAfi/Controller/Dispatcher/Standard.php
@@ -0,0 +1,45 @@
+<?php
+/**
+ * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
+ * the Free Software Foundation.
+ *
+ * There are special exceptions to the terms and conditions of the AGPL as it
+ * is applied to this software (see README file).
+ *
+ * AFI-OPAC 2.0 is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * along with AFI-OPAC 2.0; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+class ZendAfi_Controller_Dispatcher_Standard extends Zend_Controller_Dispatcher_Standard {
+	public function dispatch(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response) {
+		try {
+			return parent::dispatch($request, $response);
+		}
+		catch (Zend_Controller_Dispatcher_Exception $e) {
+			$parent_rewrite_url = $request->getControllerName();
+
+			if (!$profil = Class_Profil::findFirstBy(['rewrite_url' => $parent_rewrite_url])) {
+				throw $e;
+			}
+
+			$profil->beCurrentProfil();
+			$page_rewrite_url = $request->getActionName();
+			if ($page = Class_Profil::findFirstBy(['rewrite_url' => $page_rewrite_url,
+																						 'parent_id' => $profil->getId()]))
+				$page->beCurrentProfil();
+
+			$request->setControllerName('index');
+			$request->setActionName('index');
+			return parent::dispatch($request,$response);
+		}
+	}
+}
+?>
\ No newline at end of file
diff --git a/library/startup.php b/library/startup.php
index a6e06c8c6fabfb32825a54fe37a9d3433c598e14..8052f31855822ded874dd4eaef06c5240b00c38d 100644
--- a/library/startup.php
+++ b/library/startup.php
@@ -262,12 +262,11 @@ function setupMail($cfg) {
 }
 
 
-function setupFrontController($cfg) {
-	$front_controller = Zend_Controller_Front::getInstance()
+function newFrontController() {
+	return Zend_Controller_Front::getInstance()
+		->setDispatcher(new ZendAfi_Controller_Dispatcher_Standard())
 		->addModuleDirectory(MODULEDIRECTORY)
-		->addControllerDirectory(ROOT_PATH.'afi/application/modules/opacpriv/controllers','opacpriv')
 		->setDefaultModule('opac')
-		->setBaseUrl(BASE_URL)
 		->registerPlugin(new ZendAfi_Controller_Plugin_AdminAuth())
 		->registerPlugin(new ZendAfi_Controller_Plugin_SetupLocale())
 		->registerPlugin(new ZendAfi_Controller_Plugin_DefineURLs())
@@ -277,9 +276,15 @@ function setupFrontController($cfg) {
 		->registerPlugin(new ZendAfi_Controller_Plugin_Popup())
 		->registerPlugin(new ZendAfi_Controller_Plugin_TogetherJS())
 		->registerPlugin(new ZendAfi_Controller_Plugin_CustomFields())
-		->setParam('useDefaultControllerAlways', true);
+		->setParam('useDefaultControllerAlways', false);
+}
 
 
+function setupFrontController($cfg) {
+	$front_controller = newFrontController()
+		->addControllerDirectory(ROOT_PATH.'afi/application/modules/opacpriv/controllers','opacpriv')
+		->setBaseUrl(BASE_URL);
+
 	setupRoutes($front_controller, $cfg);
 
 	if (!Class_Users::isCurrentUserSuperAdmin())
diff --git a/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php b/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php
index 8c2898b00926e4f0735c6adbbe27512f189e8497..35931b506cfecdf6e0e60f7266a9f47e37ba95a0 100644
--- a/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php
+++ b/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php
@@ -30,7 +30,6 @@ abstract class ProfilOptionsControllerWithProfilAdulteTestCase extends AbstractC
 		Class_Systeme_ModulesMenu::reset();
 		$this->admin_var=$this->fixture('Class_AdminVar',['id' => 'FORMATIONS',
 																											'valeur' => 1]);
-//		$this->admin_var->beModuleEnabled('FORMATIONS');
 		$this->admin_var->save();
 		Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice')
 			->whenCalled('countBySQLSelect')
@@ -908,6 +907,45 @@ abstract class ProfilOptionsControllerProfilJeunesseWithPagesJeuxMusiqueTestCase
 
 
 
+
+class ProfilOptionsControllerUrlRewritingTest extends ProfilOptionsControllerProfilJeunesseWithPagesJeuxMusiqueTestCase {
+	public function setUp() {
+		parent::setUp();
+		$this->profil_jeunesse->setRewriteUrl('jeunesse')->assertSave();
+		$this->page_jeux->setRewriteUrl('jeux')->assertSave();
+	}
+
+
+	/** @test */
+	public function dispatchUrlWithJeunesseShouldAccessJeunesseProfil() {
+		$this->dispatch('/jeunesse', true);
+		$this->assertXPathContentContains('//title', 'Jeunesse');
+	}
+
+
+
+	/** @test */
+	public function dispatchUrlWithJeunesseJeuxShouldAccessJeuxProfil() {
+		$this->dispatch('/jeunesse/jeux', true);
+		$this->assertXPathContentContains('//title', 'Jeux');
+	}
+
+
+	/** @test */
+	public function glubShouldRaiseError404() {
+		try {
+			$this->dispatch('/glub', true);
+		} catch(Zend_Controller_Dispatcher_Exception $e) {
+			$this->assertEquals(404, $e->getCode());
+			return;
+		}
+		$this->fail('should have 404 error');
+	}
+}
+
+
+
+
 class ProfilOptionsControllerPopupLoginProfilAdulteTest extends ProfilOptionsControllerProfilJeunesseWithPagesJeuxMusiqueTestCase {
 	protected
 		$_json,
diff --git a/tests/bootstrap_frontcontroller.php b/tests/bootstrap_frontcontroller.php
index d4eb60250a4f6427dc8f022767ac7f391c1c8357..86b9ef7d34f2bc2458797ededaebbf02a10886e0 100644
--- a/tests/bootstrap_frontcontroller.php
+++ b/tests/bootstrap_frontcontroller.php
@@ -16,7 +16,7 @@
  *
  * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
  * along with AFI-OPAC 2.0; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 /* Regénère un nouveau front controller pour chaque test,
@@ -26,26 +26,15 @@ $_SERVER['HTTP_HOST'] = 'localhost';
 
 Zend_Registry::get('session')->id_profil = 2;
 
-$controller = Zend_Controller_Front::getInstance()
-	->throwExceptions(true)
-	->addModuleDirectory('application/modules')
-	->setDefaultModule('opac')
-	->registerPlugin(new ZendAfi_Controller_Plugin_AdminAuth())
-	->registerPlugin(new ZendAfi_Controller_Plugin_SetupLocale())
-	->registerPlugin(new ZendAfi_Controller_Plugin_DefineURLs())
-	->registerPlugin(new ZendAfi_Controller_Plugin_InitModule())
-	->registerPlugin(new ZendAfi_Controller_Plugin_SelectionBib())
-	->registerPlugin(new ZendAfi_Controller_Plugin_System())
-	->registerPlugin(new ZendAfi_Controller_Plugin_TogetherJS())
-	->registerPlugin(new ZendAfi_Controller_Plugin_CustomFields());
+$controller = newFrontController()
+	->throwExceptions(true);
 
-$_SESSION["selection_bib"]=array("message" => 'selection bib sucks',
-																 "nb_notices" => 12345,
-																 "html" => "<madmode>yes, really</madmode>",
-																 "id_bibs" => '');
+/* $_SESSION["selection_bib"]=array("message" => 'selection bib sucks', */
+/* 																 "nb_notices" => 12345, */
+/* 																 "html" => "<madmode>yes, really</madmode>", */
+/* 																 "id_bibs" => ''); */
 
-$viewRenderer = new ZendAfi_Controller_Action_Helper_ViewRenderer();
-Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
+Zend_Controller_Action_HelperBroker::addHelper(new ZendAfi_Controller_Action_Helper_ViewRenderer());
 
 setupRoutes($controller, new Zend_Config([]));
 ?>
\ No newline at end of file