login Sign In

Domain & Hosting

Host sites on platform subdomains or connect custom domains with automatic SSL.

schedule 10 min read

Overview

SiteBuilder supports two hosting modes for client sites:

ModeURL ExampleSetup RequiredPlan
Platform Subdomain mysite.yourdomain.com None (automatic) All plans (Free)
Custom Domain www.clientsite.com DNS configuration + verification Starter+
info
How it works

The subdomain-router.php file handles all routing. When a request comes in, it checks the hostname — if it's a subdomain of your platform domain, it serves the matching site. If it's an external domain, it looks up which site has that domain verified.

Prerequisites (One-Time Server Setup)

Before domain routing works, complete these steps on your production server:

1. Set Environment Variables

Add these to your .env file:

# Your platform's main domain (without www)
PLATFORM_DOMAIN=dedicinfotech.com

# Your server's public IP address (for A record DNS verification)
SERVER_IP=185.199.108.153

2. Run Database Migration

Import config/domain-migration.sql in phpMyAdmin (SQL tab → paste & execute). This adds:

  • subdomain column to sites table
  • domain_verified, domain_verified_at columns
  • ssl_status, ssl_issued_at, ssl_expires_at columns
  • domain_verifications table (verification log)
  • platform_settings table
check_circle
Safe to run multiple times

The migration uses IF NOT EXISTS and INSERT IGNORE patterns — running it again won't break anything.

3. Set Up Wildcard DNS

At your domain registrar, add a wildcard A record:

TypeNamePoints ToTTL
A*Your server IP14400

This routes all subdomains (e.g. anything.yourdomain.com) to your server.

4. Enable the Router in .htaccess

Uncomment the subdomain router block (see section below).

Subdomain Hosting (Automatic)

Once prerequisites are done, every site is automatically available at:

https://{site-slug}.yourdomain.com

How the routing works:

  1. Wildcard DNS (*.yourdomain.com) routes all subdomains to your server
  2. Apache hits .htaccess → matches the subdomain pattern → routes to subdomain-router.php
  3. Router extracts the subdomain from the HTTP hostname
  4. Looks up the site by slug in the sites table
  5. Serves static files from /sites/{slug}/ directory
info
No per-site action needed

Once wildcard DNS + .htaccess are configured, every new site you create is instantly live on its subdomain. The subdomain matches the site slug.

Reserved subdomains (these always serve the main platform):

  • www, admin, api, mail, ftp, cpanel, webmail, ns1, ns2

.htaccess Configuration

In your root .htaccess, find and uncomment this block for production:

# ── Subdomain / custom-domain router ─────────────────────────────
# Subdomain routing: slug.yourdomain.com → subdomain-router.php
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^localhost [NC]
RewriteCond %{HTTP_HOST} !^127\.0\.0\.1 [NC]
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+\.[^.]+$ [NC]
RewriteRule ^ subdomain-router.php [L]

# Custom domain catch-all (domains NOT matching platform domain):
RewriteCond %{HTTP_HOST} !yourdomain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^localhost [NC]
RewriteRule ^ subdomain-router.php [L]
warning
Important

Replace yourdomain\.com with your actual platform domain (dots escaped with backslash). For example: dedicinfotech\.com

Also update RewriteBase for production:

# For domain root (Hostinger):
RewriteBase /

# For subdirectory (e.g. public_html/sitebuilder/):
RewriteBase /sitebuilder/

Wildcard DNS Setup (Hostinger)

Step-by-step for Hostinger (similar process for other registrars):

  1. Login to hPanelDomains → select your domain
  2. Go to DNS / NameserversDNS Records
  3. Click Add Record and fill in:
    TypeName (Host)Points To (Value)TTL
    A*Your server IP address14400
  4. Click Save
  5. Wait 15 minutes to 48 hours for DNS propagation
  6. Test: visit test123.yourdomain.com — should hit your server (may show "Site Not Found" which is correct)
warning
Hostinger Shared Hosting Note

Wildcard subdomains may require Business plan or higher on Hostinger shared hosting. Check hPanel → Hosting → Subdomains to confirm wildcard support. If not available, consider upgrading or using a VPS.

For VPS (DigitalOcean, AWS, etc.)

Add a wildcard Apache virtual host:

<VirtualHost *:80>
    ServerName yourdomain.com
    ServerAlias *.yourdomain.com
    DocumentRoot /var/www/sitebuilder

    <Directory /var/www/sitebuilder>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Then restart Apache:

sudo systemctl restart apache2

Custom Domain Setup (Per Site)

Users can connect their own domain (e.g. www.clientsite.com) to any site. Here's the full flow:

Step 1: Add Domain in Site Settings

  1. Go to Admin → Sites
  2. Click the site's Settings icon
  3. Enter the custom domain in the Domain field (e.g. www.clientsite.com)
  4. Save

Step 2: Configure DNS at Client's Registrar

The client needs to add one of these DNS records at their domain registrar:

TypeName / HostValue / Points ToWhen to Use
CNAME www yourdomain.com (your platform domain) Recommended — works with most registrars
A @ (root) Your server IP address Use if registrar doesn't support CNAME on root domain

Step 3: Verify DNS

  1. Wait for DNS propagation (15 min – 48 hours)
  2. Go to Admin → Sites → Manage Domains for the site
  3. Click "Verify DNS Now"
  4. The system checks both CNAME and A records automatically
  5. Once verified, the site is live on the custom domain
info
Verification API

The verification is handled by api/verify-domain.php which uses dig (with fallback to PHP's dns_get_record) to check DNS records. It verifies CNAME pointing to your platform domain, or A record pointing to your SERVER_IP.

Step 4: Install SSL for Custom Domain

Custom domains need their own SSL certificate (not covered by your wildcard cert):

  • Hostinger: hPanel → SSL → Install for the custom domain (free Let's Encrypt)
  • VPS: sudo certbot --apache -d clientdomain.com -d www.clientdomain.com

SSL / HTTPS

Hosting ModeSSL MethodNotes
Platform subdomains Wildcard SSL certificate (*.yourdomain.com) On Hostinger: enable in hPanel → SSL. Covers all subdomains automatically.
Custom domains (Hostinger) Per-domain SSL via hPanel hPanel → SSL → select the custom domain → Install (free Let's Encrypt)
Custom domains (VPS) Let's Encrypt via Certbot sudo certbot --apache -d domain.com -d www.domain.com

The .htaccess includes an HTTPS redirect rule (enabled by default for non-localhost):

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^localhost [NC]
RewriteCond %{HTTP_HOST} !^127\.0\.0\.1 [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Troubleshooting

IssueSolution
Subdomain shows "Site Not Found" Check the site slug matches, and /sites/{slug}/index.html exists. Regenerate the site if needed.
Subdomain shows platform homepage instead of site The subdomain router block in .htaccess is still commented out. Uncomment it.
Custom domain says "DNS not verified" DNS may not have propagated yet (can take up to 48h). Verify with: dig yourdomain.com A or dig www.yourdomain.com CNAME
Verification says "A record points to X but expected Y" Ensure SERVER_IP in .env matches your actual server's public IP address.
SSL not working on custom domain Custom domains need their own SSL certificate — install separately via hPanel or Certbot.
Wildcard subdomains not working on Hostinger Shared hosting may not support wildcard subdomains. Upgrade to Business plan or use a VPS.
"SERVER_IP is not set" error in verification Add SERVER_IP=your.ip.here to .env. Find your IP with curl ifconfig.me on the server.
Custom domain shows wrong site Check that only one site has that domain set. Look in DB: SELECT * FROM sites WHERE domain LIKE '%clientdomain%'

Files Reference

All files involved in the domain/hosting system:

FilePurpose
.envPLATFORM_DOMAIN and SERVER_IP configuration
.htaccessSubdomain/custom domain rewrite rules (uncomment for production)
subdomain-router.phpMain router — resolves hostname to site, serves static files
config/domain-migration.sqlDatabase migration — adds subdomain/domain columns (run once)
admin/domains.phpDomain management UI per site (DNS instructions, verify button)
api/verify-domain.phpDNS verification API — checks CNAME and A records
check_circle
Quick Checklist for Going Live
  • PLATFORM_DOMAIN set in .env
  • SERVER_IP set in .env
  • config/domain-migration.sql imported
  • ✅ Wildcard DNS record (* → server IP) added at registrar
  • ✅ Subdomain router block uncommented in .htaccess
  • RewriteBase / set (for domain root deployment)
  • ✅ Wildcard SSL certificate installed (for subdomains)
  • ✅ Test: visit slug.yourdomain.com — site loads