Knowledgebase

Working with Subdomains for Applications Print

  • developersgitdeployment, developers, subdomain, domain, ssl, cpanel, staging, guide
  • 0

Separating parts of a project.

COMMON USES

api.yourdomain.com for an API app.yourdomain.com for an application, with the main domain as a marketing site staging.yourdomain.com for testing docs.yourdomain.com for documentation

CREATING ONE

cPanel > Domains > Create A New Domain. Enter the subdomain and set its document root.

Run AutoSSL afterwards, or the subdomain has no certificate.

COOKIES AND SESSIONS

Cookies set on the main domain are not automatically available on a subdomain unless the cookie domain is set to permit it.

This causes login state to be lost when moving between them. Set the cookie domain deliberately if sessions must be shared.

CROSS-ORIGIN REQUESTS

A browser treats a subdomain as a different origin. An application at app.yourdomain.com calling api.yourdomain.com requires CORS headers on the API.

Configure them narrowly, permitting only the origins that need access. A wildcard is rarely appropriate.

SUBDOMAIN OR SUBDIRECTORY

Subdirectories share cookies, sessions and search authority. Subdomains separate them cleanly.

For an application distinct from the main site, a subdomain is usually right.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot