tags:

views:

171

answers:

2

My webserver is Apache (I don't have admin rights over it though).

In my www/ directory, I have some .c files I'd like to display to the user to view in their browser.

Currently though, the website tries to make the user download the files instead of simply displaying them.

How can I fix this? Is there some sort of .htaccess trick?

A: 

This happens because apache does not know how to handle the file type and delivers it untouched and unidentified. You browser sees that the file type is not identified, can't associate the file with an application, so tries to save it.

There are a couple of ways.. Reconfigure Apache to serve this file as a text file or Rename The File so apache handles the file like a text file.

If you would prefer to reconfigure Apache find the following line in your configuration and modify:

AddType text/html .html .TXT .c

This instructs apache to include identify the file upon transmission to the browser as a text/html file. Note that .TXT may be there.

If you don't have access to the configuration, rename the file as FILE.C.TXT. Chances are, apache is already configured to server out text files. Note that this requires the .TXT to be specified as an txt/html handler and may not be on by default. Doing this will give you a quick test.

Good luck...

CMB
Even if you don't have access to the apache conf file, you should be able to add this in a .htaccess file in the directory containing the .c files.
chris
Shouldn't the type be text/plain?
erikkallen
This didn't work for me, still downloads.
samoz
+3  A: 

Putting:

AddType text/plain .c

in the .htaccess should work.

Mehmet Ergut
This didn't work for me, still downloads.
samoz
Try wrapping it with <IfModule mime_module></IfModule>. And be sure to CTRL+F5 in your browser, the cached version doesn't include the Content-Type: text/plain header that forces the browser to display the file.
Mehmet Ergut