Domain Set-Up Notes Copypasta, Domain Management

Domain Set-Up Notes

Some notes from setting up domains to assist in the process next time I want or need to.

Basic Domain Setup Notes

A few simple notes to help set up a new domain on my VPS.

robots.txt

A very basic initial file looks something like:

User-agent: *
Disallow: /assets/

Sitemap: https://www.jmbsquared.com/sitemap.xml

sitemap.xml

Once launched a quick sitemap can be generated at XML-Sitemaps.

htaccess

A fairly complete htaccess would look something like this:

# =============================================
# 0. GENERAL SETTINGS
# =============================================
AddDefaultCharset UTF-8

# =============================================
# 1. SEO & SECURITY: Canonical Domain (Force non-www and HTTPS)
# =============================================
RewriteEngine On
RewriteBase /

# Force non-www:
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]

# Force HTTPS (Proxy-Safe):
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# =============================================
# 2. PERFORMANCE: Compression & Browser Caching
# =============================================
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript application/json image/svg+xml
</IfModule>

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault                          "access plus 1 month"
  ExpiresByType text/html                 "access plus 0 seconds"
  
  # Bumped static assets to 1 year for better Lighthouse/PageSpeed scores
  ExpiresByType image/x-icon              "access plus 1 year"
  ExpiresByType image/gif                 "access plus 1 year"
  ExpiresByType image/png                 "access plus 1 year"
  ExpiresByType image/jpeg                "access plus 1 year"
  ExpiresByType image/webp                "access plus 1 year"
  ExpiresByType image/svg+xml             "access plus 1 year"
  ExpiresByType font/woff                 "access plus 1 year"
  ExpiresByType font/woff2                "access plus 1 year"
  ExpiresByType text/css                  "access plus 1 year"
  ExpiresByType application/javascript    "access plus 1 year"
</IfModule>

# =============================================
# 3. SECURITY: HTTP Headers
# =============================================
<IfModule mod_headers.c>
  Header always set X-Frame-Options "SAMEORIGIN"
  Header always set X-Content-Type-Options "nosniff"
  Header always set Referrer-Policy "strict-origin-when-cross-origin"
  
  # HSTS (Removed includeSubDomains to prevent accidental lockouts)
  Header always set Strict-Transport-Security "max-age=31536000"
  
  # Content Security Policy 
  # Note: Add a report-uri if you want to capture these reports externally!
  Header always set Content-Security-Policy-Report-Only "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self';"
</IfModule>

# =============================================
# 4. GENERAL SECURITY & ERROR HANDLING
# =============================================
# MultiViews MUST be off for extensionless URL routing to work properly
Options -Indexes -MultiViews

<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>

ErrorDocument 404 /404.html

# =============================================
# 5. URL AESTHETICS & ROUTING (Internal Rewrites)
# =============================================
# Force trailing slash for ACTUAL directories
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]

# Remove trailing slash from non-directories (prevents 404 on /page/)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# SEO: Redirect /index.html to root /
RewriteCond %{THE_REQUEST} \s/+(.*?/)?index\.html[\s?] [NC]
RewriteRule ^ /%1 [R=301,L]

# SEO: Redirect /page.html directly to /page
RewriteCond %{THE_REQUEST} \s/+(.+)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=301,L]

# INTERNAL: Allow accessing /page by serving /page.html silently
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html [L]

This requires that 404.html is present in the web root.

Favicon

Start with a 512 x 512 pixel PNG, and keep it simple. An online generator can produce the various files needed for different devices and contexts, such as RealFaviconGenerator. Place the files in the web root or subfolder (and/or update the paths below accordingly).

Then in the HTML header add:

<link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
<meta name="apple-mobile-web-app-title" content="MyWebSite" />
<link rel="manifest" href="/site.webmanifest" />
Search Titles & Keywords