· Abderrahmane Smimite · tutorials  · 2 min read

Nginx rewrite rules - the easy way

Using nginx rewrite rules to keep old URLs working during a website migration: key principles and the most common redirect patterns.

Using nginx rewrite rules to keep old URLs working during a website migration: key principles and the most common redirect patterns.

Unlike other posts or articles that I’m used to sharing, this is not about Cyber Security, Product Management, Agile practices, or data. It’s just something that I’ve spent some time on recently, and I thought it could save someone some valuable time.

Nginx (or Apache) has powerful URL rewrite capabilities that can simplify your migrations. You might want to take a look at it as it could ease it up.

As part of website/web app migration, we often have to handle two main challenges:

  • Updating the main website URL, which primarily consists of DNS changes. As long as you’re not dealing with CNAME entries on the APEX domain using a provider that doesn’t support DNS flattening, you should be fine.
  • switching URL schemes to adapt to a new format, for instance, redirecting /posts?id=123 to /articles/123

A well-established web server can handle the second aspect. But before diving in, you should consider the effort versus the impact and if it is worth it for your case. Basically, it’s about:

  • Search engine bots previously indexed paged, sending potential 404 errors and degrading your SEO effort.
  • Users that are used to specific patterns or bookmarks could get confused or lost with this change.

If these concerns apply to your case, having Nginx as a proxy can be very handy. The official documentation available here is a good start. If you’re in a hurry, here are the five main things to consider:

  • There are multiple directives; rewrite is the most flexible and comprehensive one.
  • Rules are scoped to a specific location within a specific server. You could have everything at /, but splitting can be pretty convenient.
  • Rewrite supports regex in its basic flavor. I usually experiment with Python or regex101 before applying anything.
  • Nginx processes the rules sequentially, so the order is essential. Be cautious but also use it wisely to simplify complex cases (e.g., having garbage-collector rules after specific ones)

The most common patterns are:

  •  /section/(.*)/product_(.*) /new/catalog/$2 ; if the key is part of the URL and you want to redirect /section/health/product_123 to /new/catalog/123
  •  /section/directory(.*) /section/directory/$arg_user? ; if the key is an argument and you want to redirect /section/directory?user=albert to /section/directory/albert/ ; nginx has built-in $arg_<your_param> variables.

And that’s it! Fly now and rewrite the world!

Back to Blog

Related Posts

View All Posts »
What's New in CISO Assistant — Week 49, 2026 (v4.3.1 – v4.3.4)

What's New in CISO Assistant — Week 49, 2026 (v4.3.1 – v4.3.4)

v4.3.1 to v4.3.4 bring an experimental auditor pre-read for ISO 27001 certification audits, a GLPI integration, automatic reference IDs, workflow-driven field defaults, implementation, documentation and maturity scores in audit reports, MCP document tools and ChatGPT sign-in, plus ISO 9001, SAMA IT Governance, NDMO, the EU cloud sovereignty frameworks and new CMMC, NIST 800-171 and Essential Eight mappings. Auto-lock of overdue audits is now off by default.

Java4Shell (CVE-2026-114938): CISO Assistant is not affected

Java4Shell (CVE-2026-114938): CISO Assistant is not affected

A memory corruption flaw in the Java Base64 decoder can lead to remote code execution in Jira, Jenkins, Keycloak and other Java applications. CISO Assistant does not use Java, so it is not affected. Here is what the flaw is, and what to do if you run Java elsewhere.

What's New in CISO Assistant — Week 48, 2026 (v4.2.3 – v4.3.0)

What's New in CISO Assistant — Week 48, 2026 (v4.2.3 – v4.3.0)

v4.3.0 lets AI apps connect to the MCP server with an OAuth sign-in, adds an evidence review queue with a four-eyes option, a briefing-style home page, a richer framework report with evidence zips, scenario selection across risk assessments and their exports, a denser control plan, federated service accounts, a dedicated space for third parties and optional memcached, plus ITSP.10.033, ISO 14001:2015, LYSS and a Hungarian NIS2 preset.