About Rich Text Format files
RTF is plain text with control words such as \b for bold, readable by almost every word processor. Both application/rtf and text/rtf are registered; prefer application/rtf, because with text/ some clients may display the raw markup instead of handing it to a word processor.
Other types seen for these files:
text/rtf
. Accept them when reading uploads, but send application/rtf yourself.
File signature
RTF files start with 7B 5C 72 74 66 ("{\rtf"). The extension and the type a browser reports for an upload both
come from the file name, so check these bytes on the server before trusting a file.
Serve .rtf with the right Content-Type
Content-Type: application/rtf
application/rtf rtf;
AddType application/rtf .rtf
@rtf path *.rtf
header @rtf Content-Type "application/rtf"
curl -sI https://example.com/file.rtf | grep -i '^content-type'
# Content-Type: application/rtf
Set the type in code
res.set('Content-Type', 'application/rtf');
// Or make the browser download it:
res.attachment('file.rtf');
import mimetypes
mimetypes.add_type('application/rtf', '.rtf') # if your system doesn't know it
mimetypes.guess_type('file.rtf')[0] # 'application/rtf'
mime.AddExtensionType(".rtf", "application/rtf")
w.Header().Set("Content-Type", "application/rtf")
Accept .rtf uploads
<input type="file" accept=".rtf,application/rtf">
The accept attribute only filters the file picker; users can still choose another file. Listing the
extension as well as the type matters, because operating systems don’t always report the type you expect.
Related types
-
.doc (
application/msword): Word 97–2003 document -
.docx (
application/vnd.openxmlformats-officedocument.wordprocessingml.document): Word document -
.txt (
text/plain): Plain text
More documents
.pdf , .xls , .xlsx , .ppt , .pptx , .odt , .epub . Look up any extension or type with the MIME type lookup.
Sources
Spotted a mistake? Email hello@devtoolsmith.com and we’ll fix it.
Frequently asked questions
What is the MIME type for .rtf files?
application/rtf. You may also see text/rtf, which is older or unofficial; send application/rtf. The full header is "Content-Type: application/rtf".
Why does my server send the wrong Content-Type for .rtf?
Web servers pick the type from the file extension using a table (mime.types in nginx and Apache). If .rtf is missing from that table, they send a default such as application/octet-stream or text/plain. Add the mapping as shown on this page, then check the response with "curl -sI".
How can I check that a file really is RTF?
Look at the first bytes rather than the extension or the type the browser reports, which both come from the file name. RTF files start with 7B 5C 72 74 66 ("{\rtf"). The MIME type lookup on this site reads them for you when you drop a file on it.