mod_rewrite cheat sheet
mod_rewrite Tutorials
http://httpd.apache.org/docs/current/rewrite/
http://www.addedbytes.com/for-beginners/url-rewriting-for-beginners/
http://net.tutsplus.com/tutorials/other/a-deeper-look-at-mod_rewrite-for-apache/
mod_rewrite RewriteRule Flags
C
Chained with next rule
CO=cookie
Set specified cookie
E=var:value
Set environmental variable “var” to “value”
F
Forbidden (403 header)
G
Gone – no longer exists
H=handler
Set handler
L
Last – stop processing rules
N
Next – continue processing
NC
Case insensitive
NE
Do not escape output
NS
Ignore if subrequest
P
Proxy
PT
Pass through
R[=code]
Redirect to new URL, with optional code (see below)
QSA
Append query string
S=x
Skip next x rules
T=mime-type
Set mime type
mod_rewrite RewriteCond Flags
NC
Case insensitive
OR
Combine with next rule using ‘OR’ instead of the default of ‘AND’
Redirection Header Codes
301
Moved permanently
302
Moved temporarily (default)
mod_rewrite Directives
RewriteEngine
RewriteOptions
RewriteLog
RewriteLogLevel
RewriteLock
RewriteMap
RewriteBase
RewriteCond
RewriteRule
Regular Expressions Syntax
^
Start of string
$
End of string
.
Any single character
(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*?
Zero or more, ungreedy
a+
One or more of a
a+?
One or more, ungreedy
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
a{3,6}?
3 to 6 of a, ungreedy
\
Escape character
[:punct:]
Any punctuation symbol
[:space:]
Any space character
[:blank:]
Space or tab
There’s an excellent regular expression tester at: http://regexpal.com/
mod_rewrite Server Variables: HTTP Headers
%{HTTP_USER_AGENT}
%{HTTP_REFERER}
%{HTTP_COOKIE}
%{HTTP_FORWARDED}
%{HTTP_HOST}
%{HTTP_PROXY_CONNECTION}
%{HTTP_ACCEPT}
mod_rewrite Server Variables: Server Internals
%{DOCUMENT_ROOT}
%{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 [R=301,L]
Rewrites domain.com to domain2.com
mod_rewrite Sample Rule: Temporary Page Move
# Page has moved temporarily
RewriteRule ^page.html$ new_page.html [R,NC,L]
Rewrites domain.com/page.html to domain.com/new_page.html
mod_rewrite Sample Rule: Nice URLs
# Nice URLs (no query string)
RewriteRule ^([A-Za-z0-9-]+)/?$ categories.php?name=$1 [L]
Rewrites domain.com/category-name-1/ to domain.com/categories.php?name=category-name-1
mod_rewrite Server Variables: Special
%{API_VERSION}
%{THE_REQUEST}
%{REQUEST_URI}
%{REQUEST_FILENAME}
%{IS_SUBREQ}
%{HTTPS}
mod_rewrite Server Variables: Request
%{REMOTE_ADDR}
%{REMOTE_HOST}
%{REMOTE_PORT}
%{REMOTE_USER}
%{REMOTE_IDENT}
%{REQUEST_METHOD}
%{SCRIPT_FILENAME}
%{PATH_INFO}
%{QUERY_STRING}
%{AUTH_TYPE}
mod_rewrite Server Variables: Time
%{TIME_YEAR}
%{TIME_MON}
%{TIME_DAY}
%{TIME_HOUR}
%{TIME_MIN}
%{TIME_SEC}
%{TIME_WDAY}
%{TIME}
I just want to say I am newbie to blogging and definitely liked you’re web blog. Almost certainly I’m planning to bookmark your website . You amazingly have really good stories. Many thanks for revealing your webpage.
Very interesting topic, thank you for posting.
Very interesting topic, appreciate it for posting.
Hey. Self-same cool website!! Guy .. Magnificent .. Amazing .. I will bookmark your website and obtain the feeds additionally…I’m happy to find numerous helpful in rank right now within the article. Be grateful you for sharing…
Very interesting subject, thanks for putting up.
Excellent issue: will be the design template on your site has been done to help purchase or can be purchased general? Since I must say i appreciated and wish to utilize similar to that will working for you. Thank you so much before hand on your response.
Hi,
Yes the design can be purchased.
I really enjoy looking through on this web site , it holds superb content .
Thank you for sharing excellent informations. Your website is very cool. I am impressed by the details that you have on this site. It reveals how nicely you perceive this subject. Bookmarked this website page, will come back for more articles. You, my friend, ROCK! I found just the information I already searched everywhere and just couldn’t come across. What a perfect site.
Useful info. Lucky me I found your website by accident, and I am shocked why this coincidence did not happened in advance! I bookmarked it.
I consider this is among the so very much significant info personally. And now i’m glad studying your article. However want to observation upon some common issues, The site taste is excellent, the articles is actually nice: D. Good job, cheers
Hi my loved one! I wish to say that this post is amazing, great written and include approximately all significant infos. I’d like to look extra posts like this .
I intended to write you this bit of note in order to thank you so much yet again for the magnificent concepts you’ve shown on this site. This has been certainly extremely open-handed with people like you to provide without restraint all that a number of people would have advertised for an e book to get some cash for themselves, and in particular considering that you could possibly have tried it if you ever decided. Those advice in addition served as the fantastic way to fully grasp the rest have the identical zeal just as my own to realize a little more around this matter. I am certain there are a lot more enjoyable opportunities in the future for many who browse through your blog.
A person essentially assist to make severely articles I might state. This is the first time I frequented your web page and up to now? I amazed with the analysis you made to make this actual put up extraordinary. Wonderful job!
I am impressed with this site, real I am a fan.
This blog was… how do you say it? Relevant!! Finally I’ve found something that helped me. Cheers!
Im grateful for the post.Really looking forward to read more. Really Cool.
I enjoy your current method to the problem, really healthful along with individual. Very well you may still find folks who may spend their selves about what they certainly, in addition to most likely therefore , as a result leading his edge. Best of luck!
I’m new to your blog and i really appreciate the nice posts and great layout.:.;,’
I blog frequently and I really thank you for your content. Your article has truly peaked my interest. I’m going to take a note of your site and keep checking for new details about once a week. I subscribed to your RSS feed too.
Good post! We are linking to this great content on our website. Keep up the good writing.
Excellent web site you’ve got here.. It’s difficult to find high-quality writing like yours nowadays. I honestly appreciate individuals like you! Take care!!
Amaze, astounding site system! Just how long were you blogging and site-building for the purpose of? You have made operating a blog appearance quick. The complete start looking of the online site can be great, much less this content! Great report!
There is definately a great deal to find out about this subject. I really like all the points you’ve made.
Fantastic site. Plenty of helpful info here. I am sending it to a few buddies ans also sharing in delicious. And certainly, thank you for your sweat!
I like reading through an article that will make people think. Also, thank you for allowing for me to comment!