A small yet handy cheat sheet for mod_rewrite. The most used items to build a mod_rewrite pattern.
Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo.
RewriteRule Pattern Substituion [Flag(s)]
RewriteRule &/oldfile\.html$ /newfile.html
. Every char < > = Compare \ Escape a char .+ One more, more chars .* No chars or multiple chars ^ Start $ End (…) Group a|b .A or B (a|b) .A or B group a{5} Exact 5 times a a{1,5} Between 1 and 5 times a [a-z]* Match chars -d Directory -f File -l Symbolic link
[NC] No case sensitive [OR] Allows multiple lines [R=#] Redirect where # is number: 404. [L] Terminate routine
%{HTTP_ACCEPT} Media types accepted by the client, ?text/plain? %{HTTP_COOKIE} Cookies set for the client. %{HTTP_HOST} Domain name of the virtual host queried. %{HTTP_REFERER} Page with a link to this page (can be omitted). %{HTTP_USER_AGENT} Client, such as ?Mozilla/4.0? %{QUERY_STRING} Query string transferred by a GET form. %{REMOTE_ADDR} Client IP address. %{REMOTE_HOST} Domain name of client. %{REMOTE_USER} User name of the client. %{REQUEST_URI} The URI requested by the client. %{REQUEST_FILENAME} The corresponding file on the local file system. %{SERVER_ADDR} Server IP
Jan 19
This entry was posted on Friday, January 19th, 2007 at 9:25 pmand is filed under apache. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Leave a Reply Apache Mod_Rewrite Cheat Sheet