Some services require you to place a file in the root of your domain to verify ownership (e.g., Google Analytics). How can this be done in B2C Commerce?
B2C Commerce doesn't provide a built-in feature for serving a static file in the domain root, but there are two workarounds. This article assumes the file should be accessible at https://www.example.com/foobar.txt
Method 1: Use the Static Mapping feature – will result in a 301 redirect
/cartridge/static/default/foobar.txtAdd this line to the Static Mappings at Merchant Tools > SEO > Static Mappings:/foobar.txt s,,,,,/foobar.txt
Requests to https://www.example.com/foobar.txt will redirect to https://www.example.com/on/demandware.static/Sites-YourSiteID-Site/-/-/foobar.txt
Method 2: Customize the RedirectURL-Start controller – no 301 redirect
If redirects aren't allowed, you can serve the file directly by customizing RedirectURL-Start.
For a custom cartridge layered on top of the SFRA base cartridge, consider using the following example for RedirectURL-Start:
'use strict';
const server = require('server');
server.extend(module.superModule);
server.prepend('Start', function (req, res, next) {
// Handle special cases
const URL_PATH = '/foobar.txt';
const FILE_PATH = '/foobar.txt';
const MIME_TYPE = 'text/plain;charset=UTF-8';
const URLRedirectMgr = require('dw/web/URLRedirectMgr');
const File = require('dw/io/File');
const FileReader = require('dw/io/FileReader');
const redirectOrigin = URLRedirectMgr.getRedirectOrigin();
if (redirectOrigin && redirectOrigin.indexOf(URL_PATH) === 0) {
const file = new File(File.STATIC + FILE_PATH);
if (file.exists()) {
const fileContent = new FileReader(file).readString();
res.base.writer.print(fileContent);
res.base.setContentType(MIME_TYPE);
const cacheExpiry = Date.now() + (1000 * 60 * 60 * 24); // 24 hours
res.base.setExpires(cacheExpiry);
return; // Do not continue the middleware chain
}
}
// Continue with the normal RedirectURL-Start behavior
next();
});
module.exports = server.exports();
The equivalent for SiteGenesis:
'use strict';
var app = require('*/cartridge/scripts/app');
var guard = require('*/cartridge/scripts/guard');
function start() {
var URLRedirectMgr = require('dw/web/URLRedirectMgr');
// Handle special cases
var URL_PATH = '/foobar.txt';
var FILE_PATH = '/foobar.txt';
var MIME_TYPE = 'text/plain;charset=UTF-8';
var File = require('dw/io/File');
var FileReader = require('dw/io/FileReader');
var redirectOrigin = URLRedirectMgr.getRedirectOrigin();
if (redirectOrigin && redirectOrigin.indexOf(URL_PATH) === 0) {
var file = new File(File.STATIC + FILE_PATH);
if (file.exists()) {
var fileContent = new FileReader(file).readString();
response.writer.print(fileContent);
response.setContentType(MIME_TYPE);
var cacheExpiry = Date.now() + (1000 * 60 * 60 * 24); // 24 hours
response.setExpires(cacheExpiry);
return;
}
}
// Standard redirect behavior from app_storefront_controllers RedirectURL.js
var redirect = URLRedirectMgr.getRedirect(),
location = redirect ? redirect.getLocation() : null;
if (!location) {
response.setStatus(410);
app.getView().render('util/redirecterrorutil/redirecterror');
} else {
app.getView({
Location: location
}).render('util/redirectpermanent');
}
}
exports.Start = guard.ensure([], start);
In this example, the content of foobar.txt will be returned at https://www.example.com/foobar.txt directly. The above code assumes that foobar.txt is uploaded to the Organization Static Content folder via WebDAV at /Sites/Static.
000391650

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.