Rewrite rules

The most common source of worry during an HTTP server switch are the rewrite rules. Unfortunately, Nginx is not directly compatible with the Apache rewrite rules in two regards:

  • Usually, rewrite rules are placed within the .htaccess files, as discussed in the previous section. Nginx offers no such mechanism, so rewrite rules will have to be placed in a different location.
  • The syntax of the rewrite instructions and conditions is quite different, and will need to be adapted. Thankfully, the regular expression syntax itself does not change.

This section will approach some of the issues encountered when porting rules to Nginx, and then will provide some prewritten rules for a couple of major web applications.

General remarks

Before studying ...

Get Nginx HTTP Server - Third 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.