Nginx 301 Redirect Example

A narrow path redirect example for Nginx. Test syntax and Location headers before using permanent redirects widely.

Nginx snippet
server {
    listen 80;
    server_name example.com;

    location = /old-page {
        return 301 https://example.com/new-page;
    }
}

How to use this example

  1. Paste into the matching server block or adapt as a separate block.
  2. Run nginx -t before reload.
  3. Verify with curl -I http://example.com/old-page.

Notes

  • Use 302 while testing uncertain redirects.
  • Avoid duplicating the same redirect in CDN and app code.

Related tools and fixes

Last updated: May 18, 2026