Google Analytics などの一部のサービスでは、ドメインの所有権を証明するためにドメインのルートにファイルを配置する必要があります。この記事ではこれを実現する2つの方法を説明します。
B2C Commerce には、ドメインルートに静的ファイルを提供するための標準機能はありませんが、2つの回避策があります。この記事では例としてファイルに https://www.example.com/foobar.txt でアクセスできる方法を説明します。
方法1: 静的マッピング機能を使用する (301 リダイレクトが発生)
/cartridge/static/default/foobar.txt/foobar.txt s,,,,,/foobar.txt
この設定により、https://www.example.com/foobar.txt へのリクエストは https://www.example.com/on/demandware.static/Sites-YourSiteID-Site/-/-/foobar.txt へリダイレクトされます。
方法2: RedirectURL-Start コントローラーをカスタマイズする (301 リダイレクトは発生しない)
リダイレクトの発生が望ましくない場合は、RedirectURL-Start をカスタマイズすることでファイルを直接配信することができます。 SFRA のベースカートリッジを拡張したカスタムカートリッジの場合、 RedirectURL-Start として以下の例を使用することをご検討ください。
'use strict';
var server = require('server');
server.extend(module.superModule);
var URL_PATH = '/foobar.txt';
var FILE_PATH = '/foobar.txt';
server.prepend('Start', function (req, res, next) {
var URLRedirectMgr = require('dw/web/URLRedirectMgr');
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();
res.base.writer.print(fileContent);
var cacheExpiry = Date.now() + (1000 * 60 * 60 * 24); // 24 hours
res.base.setExpires(cacheExpiry);
return;
}
}
next();
});
module.exports = server.exports();
この例では foobar.txt の内容が https://www.example.com/foobar.txt で直接返されます。上記のコードは、foobar.txt が WebDAV 経由で /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.