Skip to content

Instantly share code, notes, and snippets.

@wesort
Created April 29, 2024 08:40
Show Gist options
  • Save wesort/3c6d5776b9779f2c9c31ad3fa4c222d1 to your computer and use it in GitHub Desktop.
Save wesort/3c6d5776b9779f2c9c31ad3fa4c222d1 to your computer and use it in GitHub Desktop.
Redirects.map for bulk redirect of URLs via nginx.conf

Redirects

docs/legacy-redirects.map: a file listing source and destination (separated by a space) ending each line with a ;

/source /destination;
/news/old-post-2005 /blog;

nginx.conf as set via forge.laravel.com

AFTER include (L1) (NB: edit the domain)

map $uri$is_args$args $new_uri {
    default 0;
    include /home/forge/example.com/docs/legacy-redirects.map;
}

BEFORE location / {

if ($new_uri) {
    return 301 $new_uri;
}
# Dynamically set the try_files locations.
# Statically cached files should only be loaded for GET requests.
set $try_files @default;
if ($request_method = GET) {
    set $try_files @static;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment