#!/bin/bash
# Fix: www.inou.com should 301 redirect to inou.com
# Problem: www serves content (HTTP 200) instead of redirecting,
#          causing GSC "Alternate page with proper canonical tag" warnings
#
# Run on caddy server (192.168.0.2):
#   ssh root@caddy 'bash -s' < fix-inou-www-redirect.sh
#
# Or manually add this block to /etc/caddy/Caddyfile:

echo "Adding www redirect to Caddyfile..."

# Check if www redirect already exists
if grep -q 'www.inou.com' /etc/caddy/Caddyfile; then
    echo "www.inou.com block already exists in Caddyfile"
    exit 0
fi

# Add the redirect block
cat >> /etc/caddy/Caddyfile << 'CADDY'

# Redirect www to non-www (fixes GSC indexing issue)
www.inou.com {
    redir https://inou.com{uri} permanent
}
CADDY

# Reload Caddy
systemctl reload caddy

echo "Done! Verify: curl -I https://www.inou.com"
echo "Expected: HTTP/2 301, Location: https://inou.com/"
