Skip to content

Instantly share code, notes, and snippets.

@wesort
Last active December 17, 2025 13:31
Show Gist options
  • Select an option

  • Save wesort/c8f4522379f710b70e289c89a21d463d to your computer and use it in GitHub Desktop.

Select an option

Save wesort/c8f4522379f710b70e289c89a21d463d to your computer and use it in GitHub Desktop.
Redirect via Nginx

Redirect all traffic from an alias or legacy domain

  • This passes on the path, eg: /contact-us, as part of the redirect
  • When using a separate 'site' in Laravel Forge.
  • Implement the below first
  • Then add each domain and issue a certificate

Nginx Configuration

Look for something like this in the nginx.conf interface:

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/00000000/server/*;

Ensure the following is included and update the redirect destination domain.

# Handle Let's Encrypt first and stop processing other blocks
location ^~ /.well-known/acme-challenge/ {
    allow all;
}

# Redirect (that won't affect Let's Encrypt)
location / {
    return 301 https://destination-domain.co.uk$request_uri;
}

# Security: Deny other hidden files
location ~ /\.(?!well-known).* {
    deny all;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment