By default, when you setup a Sitecore SXA site by first creating a Tenant and then the Site itself, your site will be operating under the settings where it accepts calls from any host bound to that particular site.
For the majority of clients, this will be perfectly fine, but what if you have a client that would like a separate URL, say a preview site, which points to the master
database, instead of the web
database.
Now in a typical Sitecore site, setting up a separate site definition in a patch file would be all you need to do. It's quick, it's easy. That doesn't work for an SXA site.
Site Grouping
Let's navigate down to the Site Grouping
folder located within our Settings folder: /sitecore/content/<Tenant>/<Site>/Settings/Site Grouping
Open it up and you'll see a site node with the same name as your site.
On this item, you'll find everything that you'd typically find in the standard site definition. But how do we make one for say a preview site with a url https://preview.companyname.com
.
First step, let's duplicate that item.
Once duplicated, let's go in and update the hostname and target hostname with the new URL. For our requirement, we'll also change the database to master
.
We can then go back to the original site definition item and update the hostname there, or leave it as is (I'll show you why shortly).
SXA Site Manager
With those in place, let's open up the SXA Site Manager.
Once it loads, you'll see that our preview site is in the list, but it's currently showing as being in conflict. That's because it's below the site that accepts all hosts.
Let's resolve that by selecting the Demo Preview
site in the list, and in the top bar click the Move Up
button. Once that's done, you'll now see the site is green.
We're able to leave the host as a * for the original site as a catch all, hence the reason we don't need to update it with the original hostname. You may, depending on your environment, need to do this. It all depends on your needs.
Be sure, once your change is done, click the Publish
button in the top bar to finalize the change.