My webserver is Apache (I don't have admin rights over it though).
我的网络服务器是Apache(虽然我没有管理员权限)。
In my www/ directory, I have some .c files I'd like to display to the user to view in their browser.
在我的www /目录中,我有一些.c文件我想显示给用户在他们的浏览器中查看。
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?
我怎样才能解决这个问题?是否有某种.htaccess技巧?
2 个解决方案
#1
Putting:
AddType text/plain .c
in the .htaccess should work.
在.htaccess应该工作。
#2
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.
发生这种情况是因为apache不知道如何处理文件类型并将其传递给未触及和未识别的文件。浏览器发现文件类型未标识,无法将文件与应用程序关联,因此请尝试保存。
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.
有两种方法..重新配置Apache以将此文件作为文本文件提供或重命名文件,以便apache像处理文本文件一样处理文件。
If you would prefer to reconfigure Apache find the following line in your configuration and modify:
如果您希望重新配置Apache,请在配置中找到以下行并进行修改:
AddType text/html .html .TXT .c
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.
这指示apache包括在将文件作为text / html文件传输到浏览器时识别文件。请注意.TXT可能在那里。
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.
如果您无权访问配置,请将文件重命名为FILE.C.TXT。很可能,apache已配置为服务器输出文本文件。请注意,这需要将.TXT指定为txt / html处理程序,默认情况下可能不启用。这样做会给你一个快速测试。
Good luck...
#1
Putting:
AddType text/plain .c
in the .htaccess should work.
在.htaccess应该工作。
#2
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.
发生这种情况是因为apache不知道如何处理文件类型并将其传递给未触及和未识别的文件。浏览器发现文件类型未标识,无法将文件与应用程序关联,因此请尝试保存。
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.
有两种方法..重新配置Apache以将此文件作为文本文件提供或重命名文件,以便apache像处理文本文件一样处理文件。
If you would prefer to reconfigure Apache find the following line in your configuration and modify:
如果您希望重新配置Apache,请在配置中找到以下行并进行修改:
AddType text/html .html .TXT .c
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.
这指示apache包括在将文件作为text / html文件传输到浏览器时识别文件。请注意.TXT可能在那里。
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.
如果您无权访问配置,请将文件重命名为FILE.C.TXT。很可能,apache已配置为服务器输出文本文件。请注意,这需要将.TXT指定为txt / html处理程序,默认情况下可能不启用。这样做会给你一个快速测试。
Good luck...