Mass redirect using Nginx map file

After some migration between applications versions you need to keep backward compatibility. Here example of easy way how to redirect lot of links to new location for Nginx. (Example for Haproxy)

Virtual Host Configuration
map_hash_bucket_size 256;
map $request_uri $new_uri {
  include /etc/nginx/conf.d/redirects.map;
}

server {
  listen 80;
  ...
  if ($new_uri) {
    return 302 $new_uri;
  }
  ...
  location / {
  ...
} 

Redirect MAP
#cat /etc/nginx/conf.d/redirects.map
/old1/link1    https://domain.com/1234;
/old2/link2    https://domain.com/12345;
...

Comments

Popular posts from this blog

Redis with failover replication

FreeRadius and Google Workspace LDAP