100% found this document useful (5 votes)
2K views

Mod Rewrite Cheat Sheet

Uploaded by

anon-808774
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (5 votes)
2K views

Mod Rewrite Cheat Sheet

Uploaded by

anon-808774
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

mod_rewrite

Server Variables

Format
^ Start of string R[=code] Redirect to new URL, with %{NAME_OF_VAR}
$ End of string optional code (see below).
HTTP Headers
. Any single character F Forbidden (sends 403 header)
HTTP_USER_AGENT
(a|b) a or b G Gone (no longer exists) HTTP_REFERER
(...) Group section P Proxy HTTP_COOKIE
[abc] Item in range (a or b or c) L Last Rule HTTP_FORWARDED
HTTP_HOST
[^abc] Not in range (not a or b or c) N Next (i.e. restart rules)
HTTP_PROXY_CONNECTION
a? Zero or one of a C Chain HTTP_ACCEPT
a* Zero or more of a T=mime-type Set Mime Type
a+ One or more of a NS Skip if internal sub-request Request
REMOTE_ADDR
a{3} Exactly 3 of a NC Case insensitive
REMOTE_HOST
a{3,} 3 or more of a QSA Append query string REMOTE_USER
a{3,6} Between 3 and 6 of a NE Do not escape output REMOTE_IDENT
!(pattern) "Not" prefix. Apply rule when PT Pass through REQUEST_METHOD
SCRIPT_FILENAME
URL does not match pattern. S=x Skip next x rules
PATH_INFO
E=var:value Set environmental variable QUERY_STRING
"var" to "value". AUTH_TYPE

Server
301 Moved permanently DOCUMENT_ROOT
302 Moved temporarily SERVER_ADMIN
403 Forbidden NC Case insensitive SERVER_NAME
OR Allows a rule to apply if one of SERVER_ADDR
404 Not Found SERVER_PORT
410 Gone a series of conditions are true. SERVER_PROTOCOL
SERVER_SOFTWARE

Time
TIME_YEAR
# Site has permanently moved to new domain TIME_MON
# domain.com to domain2.com TIME_DAY
TIME_HOUR
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
TIME_MIN
RewriteRule ^(.*)$ http://www.domain2.com/$1 [R=301,L] TIME_SEC
TIME_WDAY
# Page has moved temporarily TIME
# domain.com/page.htm to domain.com/new_page.htm
Special
RewriteRule ^page.htm$ new_page.htm [R,NC,L] API_VERSION
THE_REQUEST
# Nice looking URLs (no querystring) REQUEST_URI
REQUEST_FILENAME
# domain.com/category-name-1/ to domain.com/categories.php?name=category-name-1
IS_SUBREQ
RewriteRule ^([A-Za-z0-9-]+)/?$ categories.php?name=$1 [L]

# Nice looking URLs (no querystring) with pagination


Directives
# domain.com/articles/title/5/ to domain.com/article.php?name=title&page=5
RewriteEngine
RewriteRule ^articles/([A-Za-z0-9-]+)/([0-9]+)/?$ article.php?name=$1&page=$2 [L] RewriteOptions
RewriteLog
# Block referrer spam RewriteLogLevel
RewriteLock
RewriteCond %{HTTP_REFERER} (weight) [NC,OR]
RewriteMap
RewriteCond %{HTTP_REFERER} (drugs) [NC] RewriteBase
RewriteRule .* - [F] RewriteCond
RewriteRule

Available free from www.ILoveJackDaniels.com

You might also like