mod_rewrite Tutorials
http://httpd.apache.org/docs/current/rewrite/
301
Moved permanently
http://www.addedbytes.com/for-beginners/url-
302
rewriting-for-beginners/
http://net.tutsplus.com/tutorials/other/a-deeperlook-at-mod_rewrite-for-apache/
mod_rewrite RewriteRule Flags
C
CO=cookie
E=var:valu
to value
H=handler
Set handler
NC
Case insensitive
NE
NS
Ignore if subrequest
Proxy
PT
Pass through
R[=code]
QSA
S=x
T=mime-
type
mod_rewrite RewriteCond Flags
Headers
%{HTTP_USER_AGENT}
%{HTTP_REFERER}
mod_rewrite Directives
%{HTTP_COOKIE}
RewriteEngine
RewriteMap
%{HTTP_FORWARDED}
RewriteOptions
RewriteBase
%{HTTP_HOST}
RewriteLog
RewriteCond
%{HTTP_PROXY_CONNECTION}
RewriteLogLevel
RewriteRule
%{HTTP_ACCEPT}
RewriteLock
mod_rewrite Server Variables: Server
Regular Expressions Syntax
Internals
%{DOCUMENT_ROOT}
Start of string
End of string
(a|b)
a or b
(...)
Group section
[abc]
In range (a, b or c)
[^abc]
Not in range
\s
White space
a?
Zero or one of a
a*
Zero or more of a
a*?
a+
One or more of a
a+?
[R=301,L]
a{3}
Exactly 3 of a
a{3,}
3 or more of a
a{,6}
Up to 6 of a
a{3,6}
3 to 6 of a
NC
Case insensitive
a{3,6}?
3 to 6 of a, ungreedy
OR
Escape character
[:punct:]
[:space:]
[:blank:]
Space or tab
%{SERVER_ADMIN}
%{SERVER_NAME}
%{SERVER_ADDR}
%{SERVER_PORT}
%{SERVER_PROTOCOL}
%{SERVER_SOFTWARE}
mod_rewrite Sample Rule: Site Moved
# Site moved permanently
RewriteCond %{HTTP_HOST}
^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain2.com/$1
Sponsored by Readability-Score.com
cheatography.com/davechild/
www.addedbytes.com
Page 1 of 2.
https://readability-score.com
Sponsored by Readability-Score.com
cheatography.com/davechild/
www.addedbytes.com
Page 2 of 2.
https://readability-score.com