diff --git a/mobile_theme.module b/mobile_theme.module
index e94585a..e3daeca 100644
--- a/mobile_theme.module
+++ b/mobile_theme.module
@@ -45,19 +45,43 @@ function mobile_theme_help($path, $arg) {
 }
 
 /**
+ * Redirect users if PURL is enabled.
+ */
+function _mobile_theme_redirect() {
+  $mobile_device = _mobile_theme_is_mobile();
+
+  // The purl callback function is always called after hook_custom_theme
+  // so we define the session variable before the redirection
+  if ($mobile_device == TRUE && $_SESSION['is_mobile'] == FALSE) {
+    $_SESSION['is_mobile'] = TRUE;
+    
+    // Redirect mobile if they are not on the mobile path
+    purl_goto('<front>', array('purl' => array('provider' => 'mobile_theme', 'id' => 1)));
+  }
+  if ($mobile_device == FALSE && $_SESSION['is_mobile'] == TRUE) {
+    $_SESSION['is_mobile'] = FALSE;
+    // Redirect desktop if they are not on the desktop path
+    purl_goto('<front>', array('purl' => array('provider' => 'mobile_theme', 'id' => 0)));
+  }
+}
+
+/**
  * Implements hook_custom_theme().
  */
 function mobile_theme_custom_theme() {
-  // Retrieve the detection method.
-  $method = variable_get('mobile_theme_detection', 'mobile_theme_detect_php');
+  if (module_exists("purl")) {
+    session_start();
+    // Redirect the user if needed
+    _mobile_theme_redirect();
 
-  // If the detection method cannot be found, revert to default
-  if (!function_exists($method)) {
-    $method = "mobile_theme_detect_php";
+    // If PURL is available we use the session variable is_mobile to decide which theme to display
+    $mobile_device = $_SESSION['is_mobile'];
+  }
+  else {
+    // The theme switching is defined by the detection and not the path (incompatible with page caching)
+    $mobile_device = _mobile_theme_is_mobile();
   }
 
-  // Check if this is a mobile 
-  $mobile_device = $method();
   if ($mobile_device) {
     $theme = variable_get('mobile_theme_selection', 'default');
     if ($theme != 'default') {
@@ -67,6 +91,21 @@ function mobile_theme_custom_theme() {
 }
 
 /**
+ * Utility function to detect if the device is a mobile or not.
+ */
+function _mobile_theme_is_mobile() {
+  // Retrieve the detection method.
+  $method = variable_get('mobile_theme_detection', 'mobile_theme_detect_php');
+
+  // If the detection method cannot be found, revert to default
+  if (!function_exists($method)) {
+    $method = "mobile_theme_detect_php";
+  }
+
+  return $method();
+}
+
+/**
  * Implements hook_mobile_theme_detection().
  */
 function mobile_theme_mobile_theme_detection() {
@@ -215,3 +254,37 @@ function mobile_theme_settings_submit($form, $form_state) {
     variable_set('mobile_theme_detection', $form_state['values']['mobile_theme_detection']);
   }
 }
+
+/**
+ * Implements hook_purl_provider().
+ */
+function mobile_theme_purl_provider() {
+  return array(
+    'mobile_theme_provider' => array(
+      'name' => t('Mobile device'),
+      'description' => t('Provide mobile_theme which device type is beeing used.'),
+      'callback' => '_mobile_theme_purl_callback',
+    ),
+  );
+}
+
+/**
+ * Implements hook_purl_modifiers().
+ */
+function mobile_theme_purl_modifiers() {
+  return array(
+    'mobile_theme_provider' => array(
+      array('value' => 'desktop', 'id' => 0),
+      array('value' => 'mobile', 'id' => 1),
+    ),
+  );
+}
+
+/**
+ * PURL callback.
+ */
+function _mobile_theme_purl_callback($type) {
+  // The hook_custom_theme() is always called before this so we need
+  // to save the value in a $_SESSION variable
+  $_SESSION['is_mobile'] = ($type == 1);
+}
