我在我的OSX上build立我的第一个网站,这只是为了在我的机器上使用,所以我可以试用HTML片段。 当我打开本地站点并select任何HTML文件时,它将以文本forms返回。 我的testingHTML文件如下:
<html> <head> </head> <body> <a>Hello World</a> </body> </html>
它显示为实际文本而不是解释器文本。 实际返回的HTML是:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Style-Type" content="text/css"> <title></title> <meta name="Generator" content="Cocoa HTML Writer"> <meta name="CocoaVersion" content="1038.36"> <style type="text/css"> p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Courier} </style> </head> <body> <p class="p1"><html></p> <p class="p1"><span class="Apple-converted-space"> </span><head></p> <p class="p1"><span class="Apple-converted-space"> </span><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></p> <p class="p1"><span class="Apple-converted-space"> </span></head></p> <p class="p1"><body></p> <p class="p1"><span class="Apple-converted-space"> </span><a>Hello World</a></p> <p class="p1"></body></p> <p class="p1"></html></p> </body> </html>
我的网站的apacheconfiguration是:
<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "/Users/X/web_dump/" ServerName web_dump ErrorLog /usr/local/logs/web_dump.log CustomLog /usr/local/logs/web_dump.log common AddType text/html .html </VirtualHost> <Directory "/Users/X/web_dump/"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all AddType text/html .html </Directory>
而萤火虫表示返回的页面是文本/ html格式:
Date: Wed, 30 Nov 2011 20:10:26 GMT Server: Apache/2.2.20 (Unix) mod_ssl/2.2.20 OpenSSL/0.9.8r DAV/2 Last-Modified: Wed, 30 Nov 2011 20:10:10 GMT Etag: "a833cc-3ec-4b2f952a52c80" Accept-Ranges: bytes Content-Length: 1004 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: text/html
所以我真正愚蠢的问题是:我如何将HTML文件作为HTML文件返回?
顺便说一句:我的Apache系统对于我正在处理的其他应用程序运行良好。
你的文本编辑器(TextEdit? "Cocoa HTML Writer"似乎是通用的,它可能是别的东西)认为你想修改和HTML文件的内容,而不看底层的代码。 因此,你input的所有HTML都逃脱了,认为这是预期的内容。
用一些不会试图隐藏底层HTML的东西来编辑它。
问题不在于web服务器,而在于编辑html文件的方式:您正在使用TextEdit,在Rich Text模式下编辑并保存为html。
相反,您应该select菜单选项“格式” – >“制作纯文本”,并将其另存为带有html扩展名的纯文本文件。