diff --git a/module/VuFind/src/VuFind/Sitemap/Generator.php b/module/VuFind/src/VuFind/Sitemap/Generator.php
index a04068cdd9536140a5a2a80ff08f43d5e56b8d31..2d2a2bd464c8a3847cc4d1a9f5299e4e791e49f0 100644
--- a/module/VuFind/src/VuFind/Sitemap/Generator.php
+++ b/module/VuFind/src/VuFind/Sitemap/Generator.php
@@ -58,6 +58,13 @@ class Generator
      */
     protected $baseUrl;
 
+    /**
+     * Base URL for sitemap
+     *
+     * @var string
+     */
+    protected $baseSitemapUrl;
+
     /**
      * Settings specifying which backends to index.
      *
@@ -134,6 +141,8 @@ class Generator
         $this->backendManager = $bm;
         $this->baseUrl = $baseUrl;
         $this->config = $config;
+        $this->baseSitemapUrl = empty($this->config->SitemapIndex->baseSitemapUrl)
+            ? $this->baseUrl : $this->config->SitemapIndex->baseSitemapUrl;
 
         // Process backend configuration:
         $backendConfig = isset($this->config->Sitemap->index)
@@ -175,6 +184,36 @@ class Generator
         return $this->verbose;
     }
 
+    /**
+     * Get/set base url
+     *
+     * @param string $newUrl New base url
+     *
+     * @return string Current or new base url
+     */
+    public function setBaseUrl($newUrl = null)
+    {
+        if (null !== $newUrl) {
+            $this->baseUrl = $newUrl;
+        }
+        return $this->baseUrl;
+    }
+
+    /**
+     * Get/set base sitemap url
+     *
+     * @param string $newUrl New base sitemap url
+     *
+     * @return string Current or new base sitemap url
+     */
+    public function setBaseSitemapUrl($newUrl = null)
+    {
+        if (null !== $newUrl) {
+            $this->baseSitemapUrl = $newUrl;
+        }
+        return $this->baseSitemapUrl;
+    }
+
     /**
      * Get the current microtime, formatted to a number.
      *
@@ -443,7 +482,6 @@ class Generator
     protected function getBaseSitemapIndexUrl()
     {
         // Pick the appropriate base URL based on the configuration files:
-        return empty($this->config->SitemapIndex->baseSitemapUrl)
-            ? $this->baseUrl : $this->config->SitemapIndex->baseSitemapUrl;
+        return $this->baseSitemapUrl;
     }
 }
diff --git a/module/VuFindConsole/config/module.config.php b/module/VuFindConsole/config/module.config.php
index 227a6fa0466d73087b6baf87d7342fe7d0844c14..4bce81fec51c0ec1452787f79282d9d609e70875 100644
--- a/module/VuFindConsole/config/module.config.php
+++ b/module/VuFindConsole/config/module.config.php
@@ -79,7 +79,7 @@ $routes = [
     'util/index_reserves' => 'util index_reserves [--help|-h] [-d=s] [-t=s] [-f=s]',
     'util/lint_marc' => 'util lint_marc [<filename>]',
     'util/optimize' => 'util optimize [<core>]',
-    'util/sitemap' => 'util sitemap [--verbose]',
+    'util/sitemap' => 'util sitemap [--help|-h] [--verbose] [--baseurl=s] [--basesitemapurl=s]',
     'util/suppressed' => 'util suppressed [--help|-h] [--authorities] [--outfile=s]',
     'util/switch_db_hash' => 'util switch_db_hash [<newhash>] [<newkey>]',
 ];
diff --git a/module/VuFindConsole/src/VuFindConsole/Controller/UtilController.php b/module/VuFindConsole/src/VuFindConsole/Controller/UtilController.php
index fe13dab6142343a4c9b0d4285b2189ad36db76c7..2514ec0d605d175f3551d8fd0eae7ba390fd856a 100644
--- a/module/VuFindConsole/src/VuFindConsole/Controller/UtilController.php
+++ b/module/VuFindConsole/src/VuFindConsole/Controller/UtilController.php
@@ -277,6 +277,29 @@ class UtilController extends AbstractBase
      */
     public function sitemapAction()
     {
+        $request = $this->getRequest();
+        if ($request->getParam('help') || $request->getParam('h')) {
+            Console::writeLine('Generate sitemap files.');
+            Console::writeLine('');
+            Console::writeLine(
+                'Optional parameters: [--verbose] [--baseurl=url]'
+                . ' [--basesitemapurl=url]'
+            );
+            Console::writeLine('');
+            Console::writeLine('  verbose: turn on detailed feedback');
+            Console::writeLine(
+                '  baseurl: define the base url (overrides the url setting in'
+                . ' Site section of config.ini)'
+            );
+            Console::writeLine(
+                '  basesitemapurl: define the base sitemap url (overrides the url'
+                . ' setting in Site section of config.ini, or baseSitemapUrl in'
+                . ' sitemap.ini)'
+            );
+            Console::writeLine('');
+            return $this->getFailureResponse();
+        }
+
         // Build sitemap and display appropriate warnings if needed:
         $configLoader = $this->serviceLocator
             ->get(\VuFind\Config\PluginManager::class);
@@ -284,8 +307,13 @@ class UtilController extends AbstractBase
             $this->serviceLocator->get(\VuFind\Search\BackendManager::class),
             $configLoader->get('config')->Site->url, $configLoader->get('sitemap')
         );
-        $request = $this->getRequest();
         $generator->setVerbose($request->getParam('verbose', false));
+        if ($url = $request->getParam('baseurl', false)) {
+            $generator->setBaseUrl($url);
+        }
+        if ($sitemapUrl = $request->getParam('basesitemapurl', false)) {
+            $generator->setBaseSitemapUrl($sitemapUrl);
+        }
         $generator->generate();
         foreach ($generator->getWarnings() as $warning) {
             Console::writeLine("$warning");