Domain
The Domain module suite lets you share users, content, and configuration across a group of domains from a single installation and database.
domain
Overview
The Domain module suite provides a comprehensive multi-domain management solution for Drupal. It allows administrators to register multiple domains within a single Drupal installation, share content and users across domains, and provide domain-specific configurations and access controls.
The module supports features such as domain-based content access, domain-specific configuration overrides, domain aliases with wildcard patterns, canonical URL management for SEO, and cross-domain login support. Domain records are stored as configuration entities, making them exportable as part of your site's configuration.
The suite includes several submodules: Domain (core functionality), Domain Access (content access control), Domain Alias (hostname mapping), Domain Config (per-domain configuration), Domain Config UI (admin interface for configuration), Domain Content (content overview by domain), and Domain Source (canonical URL management).
Features
- Register multiple domains within a single Drupal installation with unique hostnames and machine names
- Domain negotiation system that determines the active domain based on HTTP requests
- Support for http, https, or variable URL schemes per domain
- Cross-domain user login via shared cookie configuration
- Domain-based content access control with configurable permissions per content type
- Domain aliases with wildcard pattern support (e.g., *.example.com) and redirect options
- Per-domain configuration overrides for any Drupal configuration including site name and settings
- Language-aware domain configuration overrides
- Canonical URL management (Domain Source) for consistent link generation across domains
- Domain environment mapping for development workflow (local, development, staging, testing)
- Token support for domain-specific values
- Custom CSS classes per domain added to the body tag
- Views integration with domain-based access controls and filters
- Drush commands for domain management operations
- Block plugins for domain navigation, switching, and server information display
- Condition plugin for domain-based block visibility
Use Cases
Multi-brand Website
Manage multiple brand websites from a single Drupal installation. Each brand gets its own domain (brand1.com, brand2.com) with separate site names, themes (via Domain Theme Switch contrib module), and content visibility settings while sharing the same user base and administrative interface.
Multi-region Deployment
Run region-specific websites (us.example.com, eu.example.com) from one codebase. Use Domain Config to customize site name, contact information, and regional settings per domain. Use Domain Access to control which content appears on which regional site.
Development Workflow
Use Domain Alias to map development environments (example.local, example.dev.cloudhost.com, example.staging.cloudhost.com) to their production counterparts. Set environments so links are correctly rewritten for each stage of development without modifying domain records.
Microsites
Create microsites for campaigns, events, or product launches that share the main site's content management but appear as separate domains. Use Domain Access to assign specific content to microsites while keeping everything manageable from a central admin.
Intranet and Public Site
Run both a public website and a private intranet from the same installation. Use Domain Access permissions to control which content types and nodes appear on each domain, with separate user roles and permissions per domain.
SEO and Canonical URLs
Use Domain Source to ensure content that appears on multiple domains always has consistent canonical URLs. This prevents duplicate content issues and consolidates search engine rankings to your preferred domain.
Franchise or Dealer Networks
Manage a network of franchise or dealer websites where each location has its own domain. Share common content (product catalog, policies) across all sites while allowing location-specific customization and content.
Tips
- Domain records are configuration entities, so they are exported with your site configuration and can be managed in version control.
- Always add url.site to required_cache_contexts when using Domain Config to ensure proper cache segmentation.
- Use environment-based aliases for development workflows to avoid modifying production domain records during development.
- The domain switcher block is useful during development but should be restricted in production to admin users only.
- When deleting domains, you'll be prompted to reassign content - plan your content migration strategy before deletion.
- Use drush domain:generate for quickly setting up test domains during development.
- Domain Source rewrites links but does not issue redirects. If you need redirects, configure them in Domain Alias or use a separate redirect module.
- For large multi-domain sites, consider using per-bundle node access grants (experimental feature in Domain Access) for better performance.
- Token support in CSS classes allows dynamic classes like domain-[domain:machine-name] for domain-specific theming hooks.
Technical Details
Admin Pages 11
/admin/config/domain
View and manage all registered domain records. Lists domains with their hostname, name, scheme, status, and default flag. Provides inline actions to enable, disable, or set default domains. The currently active domain is shown in boldface.
/admin/config/domain/add
Create a new domain record with hostname, name, URL scheme, and status settings.
/admin/config/domain/settings
Configure global settings for the Domain module including character support, www prefix handling, CSS classes, and accessible paths for inactive domains.
/admin/config/domain/domain_access
Configure how Domain Access fields are displayed and control node access behavior.
/admin/config/domain/alias/{domain}
Manage aliases for a specific domain. Aliases define unique domains or patterns that map to existing domain records, with support for wildcards and redirect options.
/admin/config/domain/alias/{domain}/add
Create a new alias for a domain with pattern, redirect, and environment settings.
/admin/config/domain/config-ui
Configure which configuration forms can have domain-specific overrides and which should be excluded.
/admin/config/domain/config-ui/list
View all saved domain-specific configuration overrides with options to inspect, enable/disable, or delete them.
/admin/config/domain/domain_source
Configure which routes and paths should be excluded from Domain Source link rewrites.
/admin/content/domain-content
Review content by assigned domain. Provides Views-based content overview pages filtered by domain assignment.
/admin/content/domain-editors
Review users by assigned domain. Provides Views-based user overview pages filtered by domain editor assignments.
Permissions 31
Hooks 4
hook_domain_request_alter
Allows modules to modify the active domain during request negotiation.
hook_domain_validate_alter
Allows modules to modify or add validation errors for domain hostnames.
hook_domain_references_alter
Allows modules to modify the domain reference options available in entity reference fields.
hook_domain_source_exclude_routes_options_alter
Allows modules to modify the list of routes that can be excluded from Domain Source link rewrites.
Drush Commands 17
drush domain:list
List active domains for the site.
drush domain:add
Add a new domain to the site.
drush domain:delete
Delete a domain from the site.
drush domain:default
Sets the default domain.
drush domain:disable
Deactivates a domain.
drush domain:enable
Activates a domain.
drush domain:name
Changes a domain's label.
drush domain:scheme
Changes a domain's URL scheme.
drush domain:test
Tests domains for proper HTTP response.
drush domain:info
List general information about the domains on the site.
drush domain:replace
Replace strings in domain hostnames.
drush domain:generate
Generate domains for testing.
drush domain-alias:list
List all domain aliases.
drush domain-alias:add
Add a new domain alias.
drush domain-alias:delete
Delete a domain alias.
drush domain-alias:delete-bulk
Delete multiple aliases.
drush domain-alias:update
Update a domain alias.
Troubleshooting 8
Set the cookie_domain value in sites/default/services.yml to match the root hostname of your sites (e.g., cookie_domain: '.example.com'). This requires all domains to share a common parent domain.
Add url.site to required_cache_contexts in services.yml. Clear caches after making the change. Ensure any config overrides follow the correct naming pattern: domain.config.DOMAIN_ID.config_name
Enable CORS in services.yml by setting cors.config.enabled to true. Configure allowedOrigins to include your domains or use ['*'] for all origins.
Ensure all domains and aliases are added to trusted_host_patterns in settings.php. Domain will refuse to redirect to hosts not in the trusted list.
Check the Domain Access field values on the content. If using Domain Access, rebuild node access permissions at /admin/reports/status/rebuild after configuration changes.
Ensure the Test server response checkbox is unchecked if the domain DNS is not yet configured. Alternatively, ensure your server can reach the domain hostname via HTTP.
Check the sort order of aliases. More specific patterns should have lower weights. Wildcard matching follows a specific precedence order documented in the Domain Alias README.
Ensure the correct Views access handler is configured (domain, domain_access_content, or domain_access_editor). Add appropriate contextual filters or arguments for domain fields.
Security Notes 7
- All permissions marked 'restrict access' are considered sensitive and should only be granted to trusted roles.
- Enabling CORS for cross-domain AJAX has security implications - review the documentation before enabling.
- The 'access inactive domains' permission allows bypassing domain visibility restrictions - grant only to administrators.
- Domain configuration overrides can change security-sensitive settings - restrict 'use domain config ui' permission appropriately.
- Cross-domain login shares session cookies across domains - ensure all domains are under your control before enabling.
- Always configure trusted_host_patterns in settings.php to prevent redirect attacks to malicious domains.
- The 'administer domains' permission grants full control over all domain functionality - equivalent to site administrator access for domain operations.