Join us in Montréal on September 18-20 for Dot All 2019, the official Craft developer conference!

How to Access the Control Panel from a Subdomain

If you’d like to access Craft’s Control Panel from a subdomain, follow these steps:

1. Configure the subdomain on your server. #

Have your server route requests for <subdomain>.your-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://<subdomain>.your-domain.com/admin. (If you’ve given your site a custom CP trigger word, replace admin with that.)

2. Tell Craft to redirect Control Panel requests to your subdomain. #

If someone accesses the Control Panel from https://your-domain.com/admin, you can have Craft automatically redirect them over to your subdomain with the baseCpUrl config setting.

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

'production' => [
    'baseCpUrl' => 'https://<subdomain>.your-domain.com',
    // ...
],

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

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://<subdomain>.your-domain.com"
// -- config/general.php --
'*' => [
    'baseCpUrl' => getenv('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.