diff --git a/.htaccess b/.htaccess
index 8438c0731489f4381b289322d88ffc10a026bafd..9566a09bf0cf5828f69c3acb53abef3dfc051a6c 100644
--- a/.htaccess
+++ b/.htaccess
@@ -7,6 +7,9 @@ RewriteCond %{HTTP_HOST}   ^ventitre\.noblogs\.org [NC]
 RewriteRule ^/?(.*)         http://www.ventitre.org/$1 [L,R=301,NE]
 ####
 
+#avoid inspection of queries log
+RewriteRule ^/noblogs_queries.*	/ancheno [L,R=404]
+
 # uploaded files
 RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]
 RewriteRule ^gallery/([0-9]+)/(previews|previews-med)/(.*)$ oldgal/$1/$2/$3 [L]
@@ -17,7 +20,8 @@ RewriteRule ^resource/[^/]+/download/(.*)$ wp-includes/ms-files.php?file=2010/08
 # BEGIN WPSuperCache
 <IfModule mod_rewrite.c>
 AddDefaultCharset UTF-8
-RewriteCond %{REQUEST_URI} !^.*[^/]$
+# Commented in order to cache more
+# RewriteCond %{REQUEST_URI} !^.*[^/]$
 RewriteCond %{REQUEST_URI} !^.*//.*$
 RewriteCond %{REQUEST_METHOD} !POST
 RewriteCond %{QUERY_STRING} !.*=.*
@@ -31,7 +35,8 @@ RewriteCond %{HTTP:Accept-Encoding} gzip
 RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/%{HTTP:X-Forwarded-Proto}/$1/index.html.gz -f
 RewriteRule ^(.*) "/wp-content/cache/supercache/%{HTTP_HOST}/%{HTTP:X-Forwarded-Proto}/$1/index.html.gz" [L]
 
-RewriteCond %{REQUEST_URI} !^.*[^/]$
+#Commented in order to cache more
+#RewriteCond %{REQUEST_URI} !^.*[^/]$
 RewriteCond %{REQUEST_URI} !^.*//.*$
 RewriteCond %{REQUEST_METHOD} !POST
 RewriteCond %{QUERY_STRING} !.*=.*
diff --git a/db-config.php b/db-config.php
index 3b0e0246e074078c340bbc467e22b80b4cc53f50..88f67a32284dea7459d4ea504cf9176efda3e442 100644
--- a/db-config.php
+++ b/db-config.php
@@ -1,8 +1,7 @@
 <?php
 
 // Common settings
-$wpdb->save_queries = false;
-$wpdb->persistent = false;
+$wpdb->persistent = true;
 $wpdb->max_connections = 30;
 
 define("NOBLOGS_BACKEND_CONFIG", "/etc/noblogs/backends");
@@ -22,4 +21,3 @@ $wpdb->add_database(array(
     ));
 
 $wpdb_reverse_backend_map = noblogs_load_backends(NOBLOGS_BACKEND_CONFIG, $wpdb->hash_map);
-
diff --git a/wp-content/db.php b/wp-content/db.php
index 18d53a1bf996fe4f1d65a1ab9836406aacac751b..99ff86ed1e577118d7de3c9c046a93c5b89216f2 100644
--- a/wp-content/db.php
+++ b/wp-content/db.php
@@ -1,4 +1,6 @@
 <?php
+//AI patch: set to true if you want to activate query profiling
+define('AI_DB_PROFILER', false);
 
 /*
 Plugin Name: HyperDB
@@ -1441,6 +1443,23 @@ class hyperdb extends wpdb {
 
 } // class hyperdb
 
-$wpdb = new hyperdb();
+/**
+ * AI custom: Logs all queries for debugging purposes
+ */
+function ai_log_db_queries($query, $time, $backtrace=null, hyperdb $obj ) {
+    $fh = fopen( ABSPATH . '/profiling/noblogs_queries_'. date('Ymd') . '.log', 'a');
+    if (!$fh) {
+        return array($query, $time, $backtrace);
+    }
+    fwrite($fh, sprintf("##\n#Date: %s\n#Query time: %s\n%s\n", date('r'), $time, $query));
+    fclose($fh);
+    return array($query, $time, $backtrace);
+}
 
+
+$wpdb = new hyperdb();
+if ( AI_DB_PROFILER === true ) {
+    $wpdb->save_queries = true;
+    $wpdb->save_query_callback = 'ai_log_db_queries';
+}
 require( DB_CONFIG_FILE );