diff --git a/modules/piwik_reports/piwik_reports.pages.inc b/modules/piwik_reports/piwik_reports.pages.inc
--- a/modules/piwik_reports/piwik_reports.pages.inc
+++ b/modules/piwik_reports/piwik_reports.pages.inc
@@ -54,11 +54,50 @@ function piwik_reports_dateselect_form() {
   return $form;
 }
 
+/**
+ * Returns the Piwik base url
+ */
+function piwik_reports_piwik_url() {
+  // get http url
+  $piwik_url = variable_get('piwik_url_http', '');
+  if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
+    // get https url if the current page is SSL
+    $piwik_url = variable_get('piwik_url_https', $piwik_url);
+  }
+  return $piwik_url;
+}
+
+/**
+ * Url encodes a path with optional query for use as a parameter with Flash variables
+ */
+function piwik_reports_flashvars_urlencode($path, $query = NULL) {
+  $piwik_url = piwik_reports_piwik_url();
+  // Url encode path
+  $path = rawurlencode($path);
+  if (is_array($query)) {
+    // Encode query string
+    $query = drupal_query_string_encode($query);
+    // drupal_query_string_encode returns "&", "=", "["  and "]"
+    // so we have to encode these characters
+    $query = str_replace(array('&', '=', '[', ']'),
+                         array('%26', '%3D', '%5B', '%5D'),
+                         $query);
+  }
+  else {
+    $query = rawurlencode($query);
+  }
+  // Append the query.
+  if ($query) {
+    $path .= (strpos($path, '%3F') !== FALSE ? '%26' : '%3F') . $query;
+  }
+  return $path;
+}
+
 function piwik_reports_overview() {
   global $user;
 
   // Get basic configuration variables.
-  $piwik_url = variable_get('piwik_url_http', '');
+  $piwik_url = piwik_reports_piwik_url();
   $piwik_site_id = variable_get('piwik_site_id', '');
   $piwik_auth = $user->piwik['piwik_token_auth'];
   $period = $_SESSION['piwik_reports_period'];
@@ -102,9 +141,8 @@ function piwik_reports_overview() {
     $data1_params['token_auth'] = $piwik_auth;
   }
 
-  // Build the data URL with all params and urlencode it.
-  // Note: drupal_urlencode() doesn't work here!
-  $data1_url = rawurlencode($piwik_url . '/index.php?' . drupal_query_string_encode($data1_params));
+  // Build the data URL with all params for Flash.
+  $data1_url = piwik_reports_flashvars_urlencode($piwik_url . '/index.php', $data1_params);
 
   // Render HTML code.
   $output = theme('visitors_overview', $piwik_url, $data1_url, $period);
@@ -126,7 +164,7 @@ function piwik_reports_settings() {
   global $user;
 
   // Get basic configuration variables.
-  $piwik_url = variable_get('piwik_url_http', '');
+  $piwik_url = piwik_reports_piwik_url();
   $piwik_site_id = variable_get('piwik_site_id', '');
   $piwik_auth = $user->piwik['piwik_token_auth'];
   $period = $_SESSION['piwik_reports_period'];
@@ -209,12 +247,11 @@ function piwik_reports_settings() {
     $data4_params['token_auth'] = $piwik_auth;
   }
 
-  // Build the data URL with all params and urlencode it.
-  // Note: drupal_urlencode() doesn't work with Flash variables!
-  $data1_url = rawurlencode($piwik_url . '/index.php?' . drupal_query_string_encode($data1_params));
-  $data2_url = rawurlencode($piwik_url . '/index.php?' . drupal_query_string_encode($data2_params));
-  $data3_url = rawurlencode($piwik_url . '/index.php?' . drupal_query_string_encode($data3_params));
-  $data4_url = rawurlencode($piwik_url . '/index.php?' . drupal_query_string_encode($data4_params));
+  // Build the data URL with all params for Flash.
+  $data1_url = piwik_reports_flashvars_urlencode($piwik_url . '/index.php', $data1_params);
+  $data2_url = piwik_reports_flashvars_urlencode($piwik_url . '/index.php', $data2_params);
+  $data3_url = piwik_reports_flashvars_urlencode($piwik_url . '/index.php', $data3_params);
+  $data4_url = piwik_reports_flashvars_urlencode($piwik_url . '/index.php', $data4_params);
 
   // Render HTML code.
   $output = theme(
@@ -243,7 +280,7 @@ function piwik_reports_times() {
   global $user;
 
   // Get basic configuration variables.
-  $piwik_url = variable_get('piwik_url_http', '');
+  $piwik_url = piwik_reports_piwik_url();
   $piwik_site_id = variable_get('piwik_site_id', '');
   $piwik_auth = $user->piwik['piwik_token_auth'];
   $period = $_SESSION['piwik_reports_period'];
@@ -272,9 +309,8 @@ function piwik_reports_times() {
     $data1_params['token_auth'] = $piwik_auth;
   }
 
-  // Build the data URL with all params and urlencode it.
-  // Note: drupal_urlencode() doesn't work with Flash variables!
-  $data1_url = rawurlencode($piwik_url . '/index.php?' . drupal_query_string_encode($data1_params));
+  // Build the data URL with all params for Flash.
+  $data1_url = piwik_reports_flashvars_urlencode($piwik_url . '/index.php', $data1_params);
 
   $form = piwik_reports_dateselect_form();
   $output = theme('visitors_times', $piwik_url, $data1_url);
@@ -294,7 +330,7 @@ function piwik_reports_locations() {
   global $user;
 
   // Get basic configuration variables.
-  $piwik_url = variable_get('piwik_url_http', '');
+  $piwik_url = piwik_reports_piwik_url();
   $piwik_site_id = variable_get('piwik_site_id', '');
   $piwik_auth = $user->piwik['piwik_token_auth'];
   $period = $_SESSION['piwik_reports_period'];
@@ -325,9 +361,8 @@ function piwik_reports_locations() {
     $data1_params['token_auth'] = $piwik_auth;
   }
 
-  // Build the data URL with all params and urlencode it.
-  // Note: drupal_urlencode() doesn't work with Flash variables!
-  $data1_url = rawurlencode($piwik_url . '/index.php?' . drupal_query_string_encode($data1_params));
+  // Build the data URL with all params for Flash.
+  $data1_url = piwik_reports_flashvars_urlencode($piwik_url . '/index.php', $data1_params);
 
   $form = piwik_reports_dateselect_form();
   $output = theme('visitors_locations', $piwik_url, $data1_url);
@@ -348,7 +383,7 @@ function piwik_reports_pages() {
   drupal_add_js(drupal_get_path('module', 'piwik_reports') .'/piwik_reports.js');
 
   // Get basic configuration variables.
-  $piwik_url = variable_get('piwik_url_http', '');
+  $piwik_url = piwik_reports_piwik_url();
   $piwik_site_id = variable_get('piwik_site_id', '');
   $piwik_auth = $user->piwik['piwik_token_auth'];
   $period = $_SESSION['piwik_reports_period'];
@@ -405,7 +440,7 @@ function piwik_reports_outlinks() {
   drupal_add_js(drupal_get_path('module', 'piwik_reports') .'/piwik_reports.js');
 
   // Get basic configuration variables.
-  $piwik_url = variable_get('piwik_url_http', '');
+  $piwik_url = piwik_reports_piwik_url();
   $piwik_site_id = variable_get('piwik_site_id', '');
   $piwik_auth = $user->piwik['piwik_token_auth'];
   $period = $_SESSION['piwik_reports_period'];
@@ -462,7 +497,7 @@ function piwik_reports_downloads() {
   drupal_add_js(drupal_get_path('module', 'piwik_reports') .'/piwik_reports.js');
 
   // Get basic configuration variables.
-  $piwik_url = variable_get('piwik_url_http', '');
+  $piwik_url = piwik_reports_piwik_url();
   $piwik_site_id = variable_get('piwik_site_id', '');
   $piwik_auth = $user->piwik['piwik_token_auth'];
   $period = $_SESSION['piwik_reports_period'];
@@ -518,7 +553,7 @@ function piwik_reports_evolution() {
   global $user;
 
   // Get basic configuration variables.
-  $piwik_url = variable_get('piwik_url_http', '');
+  $piwik_url = piwik_reports_piwik_url();
   $piwik_site_id = variable_get('piwik_site_id', '');
   $piwik_auth = $user->piwik['piwik_token_auth'];
   $period = $_SESSION['piwik_reports_period'];
@@ -562,9 +597,8 @@ function piwik_reports_evolution() {
     $data1_params['token_auth'] = $piwik_auth;
   }
 
-  // Build the data URL with all params and urlencode it.
-  // Note: drupal_urlencode() doesn't work with Flash variables!
-  $data1_url = rawurlencode($piwik_url . '/index.php?' . drupal_query_string_encode($data1_params));
+  // Build the data URL with all params for Flash.
+  $data1_url = piwik_reports_flashvars_urlencode($piwik_url . '/index.php', $data1_params);
 
   $form = piwik_reports_dateselect_form();
   $output = theme('referers_evolution', $piwik_url, $data1_url);
@@ -585,7 +619,7 @@ function piwik_reports_search() {
   drupal_add_js(drupal_get_path('module', 'piwik_reports') .'/piwik_reports.js');
 
   // Get basic configuration variables.
-  $piwik_url = variable_get('piwik_url_http', '');
+  $piwik_url = piwik_reports_piwik_url();
   $piwik_site_id = variable_get('piwik_site_id', '');
   $piwik_auth = $user->piwik['piwik_token_auth'];
   $period = $_SESSION['piwik_reports_period'];
@@ -614,9 +648,8 @@ function piwik_reports_search() {
     $data1_params['token_auth'] = $piwik_auth;
   }
 
-  // Build the data URL with all params and urlencode it.
-  // Note: drupal_urlencode() doesn't work with Flash variables!
-  $data1_url = rawurlencode($piwik_url . '/index.php?' . drupal_query_string_encode($data1_params));
+  // Build the data URL with all params for Flash.
+  $data1_url = piwik_reports_flashvars_urlencode($piwik_url . '/index.php', $data1_params);
 
   // Create an array of data URL parameters for easier maintenance.
   $data2_params = array();
@@ -664,7 +697,7 @@ function piwik_reports_websites() {
   drupal_add_js(drupal_get_path('module', 'piwik_reports') .'/piwik_reports.js');
 
   // Get basic configuration variables.
-  $piwik_url = variable_get('piwik_url_http', '');
+  $piwik_url = piwik_reports_piwik_url();
   $piwik_site_id = variable_get('piwik_site_id', '');
   $piwik_auth = $user->piwik['piwik_token_auth'];
   $period = $_SESSION['piwik_reports_period'];
