How to Access the Control Panel from an Alternate Domain

If you’d like to access Craft’s control panel from an alternate domain or subdomain—meaning one that differs from the public site—you’ll need to configure your web server and tell Craft how to handle URLs.

In the example below, we’re pretending your-domain.com is the public-facing site, and cp-domain.com is used for accessing the control panel. (The configuration would be the same if you were using a subdomain as your alternate, like cp.your-domain.com.)

1. Configure the alternate domain on your server. #

Have your server route requests for cp-domain.com to the same web root (e.g. your web/ folder) as your main site.

Once that’s configured correctly, you should be able to access your control panel from https://cp-domain.com/admin. (If you’ve given your site a custom CP trigger word, replace admin with that.)

2. Tell Craft to use your alternate domain for control panel URLs. #

Open up config/general.php and add the baseCpUrl config setting to your production environment’s config:

'production' => [
    'baseCpUrl' => 'https://cp-domain.com',
    // ...
],

The base CP URL should not include the CP trigger word (e.g. /admin).

If the alternate domain is only used for the Craft control panel, you can set cpTrigger to null to keep control panel URLs short and avoid displaying the site’s front end at your control panel domain:

'production' => [
    'baseCpUrl' => 'https://cp-domain.com',
    'cpTrigger' => null,
    // ...
],

If you’d prefer to define the base CP URL using an environment variable, you can add the baseCpUrl to the default environment config instead:

# -- .env --
BASE_CP_URL="https://cp-domain.com"
// -- config/general.php --
'*' => [
    'baseCpUrl' => craft\helpers\App::env('BASE_CP_URL') ?: null,
    // ...
],

With that in place, any time Craft needs to generate a URL to the control panel (such as when redirecting users to the Login screen), it will take your baseCpUrl into account rather than building the URL based on the requested URL.

Applies to Craft CMS 3.