6

What configuration is required to make Apache serve all files as text files in the browser window? For example if I have a file program.c, how can I make Apache serve it as plain text in the browser window rather than as a download?

I'm using Apache 1.3.

Shane Madden
  • 116,404
  • 13
  • 187
  • 256

3 Answers3

14

You want ALL files to go over as plain text?? Or do you have a subset of filetypes you want to send as plain text? Not sure if there's a way to set everything to go over as plain text.

For certain file types you would just add directives to your /etc/mime.types file, site-wide Apache config, or local .htaccess file

AddType text/plain .c
AddType text/plain .h

etc.

Kevin E
  • 155
  • 9
squillman
  • 38,163
9

You can use this to force the data type of all files, e.g. for a specific location:

<Location "/programfiles">
    ForceType text/plain
</Location>

So, no matter what's in there, even .php files, they're treated as plain text and shown to the browser instead of being download or even executed on the server side.

For more info see the mod_mime reference page for ForceType.

squillman
  • 38,163
mhaller
  • 283
2

Create .htaccess in target directory (applies to it's subfolders too):

<Files "\.(html|c|php)$">
    ForceType text/plain
</Files>

To apply to all extensions, use asterisk *:

<Files "*">
...
T.Todua
  • 222