Chapter 14. The Rewrite API

WHAT'S IN THIS CHAPTER?

  • Understanding the concepts of URL rewriting

  • Creating Rewrite rules in plugins

  • Making a complete, new permalink structure

  • Integrating a non-WordPress page with the same URL layout

  • Generating a custom feed

The Rewrite API is often considered as one of the trickiest areas in WordPress and is certainly one of the least documented on the Web. This chapter first gives you some background information on why URLs are rewritten, then explains how to do this in WordPress, and finally shows you real-life client situations in which you can leverage the Rewrite API.

WHY REWRITE URLS

Dynamic sites use URLs that generate content from query string parameters. These URLs are often rewritten to resemble URLs for static pages on a site with a subdirectory hierarchy. For example, the URL to a wiki page might be http://example.com/index.php?title=Rewrite_URL and be actually rewritten to http://example.com/Rewrite_URL. A request to this latter, prettier URL will be transparently rewritten by the web server to the former URL.

This introductory section familiarizes you with the concept of "pretty permalinks" (sometimes called "fancy URLs" in web applications) and URL rewriting, in general and specifically in WordPress.

Permalink Principles

Web applications and sites can have two completely different audiences: human readers and search engines. Online resources should be both search engine and user friendly.

Search Engine Friendly

Suppose you have coded a complete ...

Get Professional WordPress® Plugin Development now with the O’Reilly learning platform.

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