Creating new rewrite rules

When creating new rules from scratch, just as with any configuration block, plan out exactly what needs to be done. Some questions to ask yourself are as follows:

  • What pattern(s) do I have in my URLs?
  • Is there more than one way to reach a particular page?
  • Do I want to capture any parts of the URL into variables?
  • Am I redirecting to a site not on this server, or could my rule be seen again?
  • Do I want to replace the query string arguments?

In examining the layout of your website or application, it should be clear what patterns you have in your URLs. If there is more than one way to reach a certain page, create a rewrite rule to send a permanent redirect back to the client. Using this knowledge, you can construct a canonical ...

Get Mastering NGINX - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.