Skip Navigation

Find cheat sheets for every topic, or make your own to share with your friends.

All Added Bytes cheat sheets are available free at Cheatography!

Visit Cheatography »

mod_rewrite Cheat Sheet (V1)

A quick reference guide for mod_rewrite, including server variables, flags and regular expression syntax. Also includes examples of commonly-used rules.

There is a newer version of this cheat sheet!

The mod_rewrite cheat sheet is designed to act as a reminder and reference sheet, listing useful information about mod_rewrite. It includes a list of flags for the RewriteRule and RewriteCond directives, list of server variables, a regular expression guide and several examples of common rules. A description of what is on the cheat sheet follows, or if you are impatient, you can go straight to the full size mod_rewrite cheat sheet:

Regular Expression Syntax

Thumbnail highlighting regular expression syntax. URL Rewriting with mod_rewrite depends a great deal upon a solid knowledge and understanding of regular expressions. The "RewriteRule" uses regular expressions in patterns extensively. This guide outlines the basic syntax of regular expression.

Redirection Header Codes

Thumbnail highlighting redirection header codes. When redirecting users with mod_rewrite, sometimes a status code must be sent back to the user. This status code is interpreted by the browser - sometimes it will mean the user is sent on to a new page, sometimes that they are shown a message. This section lists the most commonly used status codes with their meanings.

RewriteRule Flags

Thumbnail highlighting rewrite rule flags. Rewrite Rules in mod_rewrite can have flags appended to them, indicating to the server how the action described by the rule should be taken. For example, the 'L' flag tells the server not to process any more rules if the current rule is used. This section lists the various RewriteRule flags.

RewriteCond Flags

Thumbnail highlighting pseudo selectors list. Conditions in mod_rewrite can also have flags appended to them, and again these tell the server how to interpret the current condition. The "NC" flag indicates the condition is case-insensitive, and an "OR" flag between conditions tells the server that the following rule should be applied if any of the preceding conditions are true. The default in mod_rewrite is that, if a rule is preceded by a list of conditions, it should only be applied if all conditions are met. This section lists the RewriteCond flags.

Example Rules

Thumbnail highlighting example rules. This section lists a few of the most situations mod_rewrite is used for, along with a rule to achieve the desired affect.

Server Variables

Thumbnail highlighting server variables. Sometimes it is necessary to rewrite URLs based upon variables like the referring URL or the browser being used. These variables can be used in mod_rewrite (including in the RewriteRule or RewriteCond sections), and this section lists the variables available.


Thumbnail highlighting directives. mod_rewrite gives the server a series of instructions, called directives. For example, "RewriteEngine On" tells Apache that RewriteRules may be used and to interpret them if found. This section simply lists the directives used by mod_rewrite.


So now that you know what it does, please feel free to print out the mod_rewrite cheat sheet:

Please note: If you wish to link to the mod_rewrite cheat sheet from elsewhere, please link to this page so others find the description, rather than linking directly to the sheet.

And finally, if you like the cheat sheets, and want to say thanks, please consider buying me something from my Amazon Wishlist. Thankyou very much to those who have already hunted it down and sent me something nice - I'm very grateful!

Related Cheat Sheets

No documents found.

comments powered by Disqus