Chapter 11. Rewrite Rules

WHAT'S IN THIS CHAPTER?

  • Basic rewrite rules, taking into account the regular expressions reviewed in Chapter 1

  • Conditional rules to display or deny access to content depending on the available data

  • Logging rewrite events and optimizing rules and conditions

  • Using built-in rewrite maps where a one-to-one data relationship can be used as a basis for altering URLs

  • Building a custom rewrite map using PHP

A strong understanding of rewriting web URLs is vitally important for almost any web application. This chapter is one of the only chapters in this book that deals with concepts that are Apache web server-specific. Compatible modules do exist for other web servers; however, they are beyond the scope of this book.

The sections in the chapter include not only a traditional overview of mod_rewrite but also cover extending the rewrite capabilities using PHP and MySQL.

Rewrite rules are one of the final pieces of the PHP and MySQL puzzle and can be found in almost every major application that uses PHP. Rewrite rules serve two major purposes:

  • Hiding the underlying functionality of PHP and thus exposing less of the site internals

  • Creating clean and readable URLs that are easier to remember and aid in search engine optimization

It is important to use all available tools to have a coherent, easy to navigate, and easy to maintain application. A firm grasp of mod_rewrite is a welcome addition to any toolbox. The perfect application is one where a user can become an expert without ...

Get Expert PHP and MySQL® 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.