Appendix B. The Rewrite Rule Guide

This appendix is meant to introduce the rewrite module in NGINX and serve as a guide for creating new rules as well as translating legacy Apache rewrite rules into NGINX's format. In this appendix, we will discuss the following topics:

  • Introducing the rewrite module
  • Creating new rewrite rules
  • Translating from Apache

Introducing the rewrite module

The rewrite module of NGINX is a simple regular expression matcher combined with a virtual stack machine. The first part of any rewrite rule is a regular expression. As such, it is possible to use parentheses to define certain parts as captures, which can later be referenced by positional variables. A positional variable is one in which its value depends on the order of the ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.