diff --git a/core/SettingsPiwik.php b/core/SettingsPiwik.php
index af1ea261739c98b65703e63eea06fd2a094bffe1..a1082eb4a00446605b55235106553a5658660bf3 100644
--- a/core/SettingsPiwik.php
+++ b/core/SettingsPiwik.php
@@ -179,6 +179,9 @@ class SettingsPiwik
 
         $currentUrl = Common::sanitizeInputValue(Url::getCurrentUrlWithoutFileName());
 
+        // when script is called from /misc/cron/archive.php, Piwik URL is /index.php
+        $currentUrl = str_replace("/misc/cron/", "", $currentUrl);
+
         if (empty($url)
             // if URL changes, always update the cache
             || $currentUrl != $url
diff --git a/tests/PHPUnit/System/ArchiveWebTest.php b/tests/PHPUnit/System/ArchiveWebTest.php
index 527f5c647700fb3559c65b286629db42419634ba..745b12e0ec76e9d4870e52a9c4be76f72cbf1ecf 100644
--- a/tests/PHPUnit/System/ArchiveWebTest.php
+++ b/tests/PHPUnit/System/ArchiveWebTest.php
@@ -74,7 +74,7 @@ class ArchiveWebTest extends SystemTestCase
         $this->assertNotContains('WARNING', $output);
 
         // Check there are enough lines in output
-        $minimumLinesInOutput = 60;
+        $minimumLinesInOutput = 30;
         $linesInOutput = count( explode(PHP_EOL, $output) );
         $this->assertGreaterThan($minimumLinesInOutput, $linesInOutput);
     }