如何设置您的网络服务器和网络服务器?文档的 html 能否正确提供 HTML5 文档?
也许我是个白痴,但我不太明白 HTML 标头中的内容如何使用 XHTML w/ HTML5。这还好吗,我们只需添加 HTML5 标签?:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html dir="ltr" lang="eng" xmlns="http://www.w3.org/1999/xhtml">
或者是 还是什么?
然后在 A List Apart 他们说:
如果您确实使用 XHTML 5,请记住您的服务器必须提供具有 application/xhtml+xml 或 text/xml MIME 类型的文档。
请向我解释一下,就好像我很愚蠢一样:)这在实际意义上意味着什么? “交付文件”?意思是html? php 会发生什么?以这种方式设置网络服务器需要哪些步骤?
Maybe I'm an idiot but I don't quite get what goes in the header of my HTML to use XHTML w/ HTML5. Is this still good and we just add the HTML5 tags?:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html dir="ltr" lang="eng" xmlns="http://www.w3.org/1999/xhtml">
Or is it <!DOCTYPE html>
or what?
Then at A List Apart they say:
If you do go with XHTML 5, remember that your server must deliver the documents with a MIME type of application/xhtml+xml or text/xml.
Please explain to me as if I was stupid :) what that means in a practical sense? "deliver the documents"? Meaning html? What happens to php? What are the steps required to set up your web server this way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
要正确提供 HTML5 文档,您无需执行任何异常操作。服务器默认为适合 HTML5 的内容类型。只需使用以下内容开始您的文档:(
元并不是绝对必要的,但使用它是个好主意,否则您可能会得到 Windows 1250 编码或更糟糕的情况)。
只有 XHTML5 的服务需要跳过额外的障碍。您必须发送
Content-Type: application/xhtml+xml
标头。 没有办法从任何类型的 DOCTYPE 或文档中执行此操作。它绝对必须是文档外 HTTP 标头。如何执行此操作取决于您使用的服务器/语言。在 PHP 中您会这样做:
但是,您可能不想这样做,因为 IE 根本不支持 XHTML5。坚持使用 HTML5,它与旧版 UA 具有更好的兼容性。
To correctly serve HTML5 document, you don't have to do anything unusual. Servers default to content-type appropriate for HTML5. Just start your documents with:
(meta is not strictly necessary, but it's a good idea to use it, otherwise you might get Windows 1250 encoding or something worse).
Only serving of XHTML5 requires extra hoops to jump through. You have to send
Content-Type: application/xhtml+xml
header. There is no way to do it from within document with any kind of DOCTYPE or<meta>
. It absolutely has to be out-of-document HTTP header. How to do that depends on server/language you use. In PHP you'd do:However, you probably don't want to do that, because IE doesn't support XHTML5 at all. Stick to HTML5, which has much better compatibility with legacy UAs.
HTML5/XHTML5 的 Doctype 为:
&在 XHTML 5 中,您需要指定命名空间
。
内容
类型可以是在元标记中设置,就像在任何其他 html/xhtml 文档中一样,使用 content 属性,如就 header 而言,建议使用
text/html
for HTML5 [and任何其他 HTML]:(.html、.htm)或application/xhtml+xml、application/xml
对于XHTML5 [或任何其他 XHTML]:.xhtml、.xht、.xml< /代码>。
如果服务器没有自动检测正确的内容类型并将其设置为应有的值(您可以使用 Firebug),可以在php中使用 header 函数设置,如下所示:
您还可以在 Apache 服务器上协商内容。
以下是 WHATWG Wiki 关于 (X)HTL5 中的 mime 类型的说法:
对于有关该主题的一些简单阅读,您应该查看有关 HTML5 的维基百科条目了解更多详细信息,如下所示以及WHATWG 常见问题解答。如果您喜欢大量阅读,请阅读 HTML 5 最后草案标准 。
最后,现在 HTML 和 XHTML 之间还有更多差异,您应该检查一下。
祝你好运!
Doctype for HTML5/XHTML5 is:
<!DOCTYPE html>
& in XHTML 5 you are required to specify the namespace<html xmlns="http://www.w3.org/1999/xhtml">
.Content
typecan be set in meta tag, just as in any other html/xhtml document, using content attribute, likeAs far as header is concerned, it is recomended to use
text/html
for HTML5 [and any other HTML]: (.html, .htm) orapplication/xhtml+xml, application/xml
forXHTML5 [or any other XHTML]: .xhtml, .xht, .xml
.If server doesn't automatically detect proper content type and set it as it should (You can check Response Headers using Net panel in Firebug), it can be set in php, using header function, like this:
You can also negotiate content on Apache server.
Here is what WHATWG Wiki says on mime types in (X)HTL5:
For some light reading on the subject, you should check Wikipedia entry on HTML5 for more details, as well as WHATWG FAQ. If you prefer heavy reading, go for HTML 5 last draft standard.
Finally, now there are few more differences between HTML and XHTML you should check out.
Good luck!
XHTML5标准还没有写出来,所以你想要的东西是无法实现的。此外,HTML5和XHTML 1.0是不同的、不相关的HTML标准。
mime-type 告诉用户代理如何处理当前资源。这与 doctype 声明不同,doctype 声明告诉用户代理当前资源的定义是什么。基于 SGML 的 HTML 的 mime 类型是 text/html。 HTML 的 SGML 形式包括:HTML 4、HTML 5、XHTML 1.0 以及所有早期版本的 HTML。 HTML 的 XML 形式必须使用 application/xml+html mime-type 进行处理,该类型仅适用于 XHTML 1.1 和 XHTML 5。SGML
形式和 XML 形式之间最大的区别是马虎。 SGML 表单本质上是一个文本文档,通常被视为标签汤,其中验证通常是无关紧要的,浏览器会尽力做到最好。在 XML 形式中,代码中任何一点的任何错误都将导致文档在用户代理处失败并向屏幕抛出错误,就像任何其他编程语言一样。在这种情况下,HTML 的 XML 形式被视为一个应用程序,其中评估代码以进行处理,而不仅仅是字符的平面文本文档。
使用 SGML 形式的优点是完全可以容忍对技术的完全无能和无知。如果浏览器处理该代码,那么无论该代码多么无效,它都足够好。其缺点是体验仅限于浏览器可以向最终用户直观地处理的内容,这意味着辅助技术处于严重劣势。 XML 形式的优点,特别是如果它是使用模式而不是文档类型来定义的,是文档的行为就像一个应用程序,它本质上自我了解自己的结构及其功能。要么总是有效,要么失败,这意味着代码在语法上总是统一的,这使得辅助技术的集成变得简单实用。 XML 形式的缺点是无能和懒惰的作者无法发布可以正常工作的文档。就我个人而言,我不认为这是一个缺点,因为对于任何其他形式的计算来说,这绝对是所有其他方面的最低期望。
XHTML5 standard is not written yet, so want you want is not achievable. Additionally, HTML5 and XHTML 1.0 are different unrelated standards of HTML.
The mime-type tells the user-agent how to process the current resource. That is different than the doctype declaration, which tells the user-agent what the definition of the current resource is. The mime-type for SGML based HTML is text/html. SGML forms of HTML include: HTML 4, HTML 5, XHTML 1.0, and all earlier versions of HTML. XML forms of HTML must be processed with the application/xml+html mime-type which is only for XHTML 1.1 and XHTML 5.
The biggest differences between the SGML form and the XML form is sloppiness. The SGML form is essentially a text document and is typically regarded as tag soup where validation is often irrelevant and browsers try to do the best they can. In the XML form any error at any point in the code will cause the document to fail at the user-agent and throw an error to the screen, much like any other programming language. In this case the XML form of HTML is treated like an application where code is evaluated for processing opposed to merely a flat text document of characters.
The advantage of using the SGML form is that complete incompetence and ignorance of the technologies is perfectly tolerable. If the browser processes the code then the code is good enough no matter how invalid. The disadvantage to that is that the experience is limited to what the browser can visually process to the end user, which means assisting technologies are at a severe disadvantage. The advantage of the XML form, especially if it is defined using schema instead of doctype, is that the document acts like an application where it is inherently self-aware of its own structure and what its capabilities are. The is always valid or it fails, which means the code is always syntactically uniform, which makes integration of assisting technologies simple and practical. The disadvantage to the XML form is that incompetent and lazy authors cannot publish documents that work correctly. Personally, I do not see that as a disadvantage since its a minimal expectation in absolutely every other regard to any other form of computing.
我总是说,迟到总比不到好。这是我很久以前就在寻找的答案:
...当从服务器用作“application/xhtml+xml”时,将告诉浏览器它应该使用 xhtml 而不仅仅是 html 来解析页面。
Better late than never, I always say. Here is the answer I was looking for way back when:
...when served as 'application/xhtml+xml' from the server, will tell the browser that it should parse the page using as xhtml and not just html.
我想如果它还没有设置你可以使用apache的AddType指令:
http://httpd.apache.org/docs/1.3/mod/mod_mime.html#addtype:
“AddType 指令将给定的文件扩展名映射到指定的内容类型。” -- 因此您可以根据需要添加 .php 处理程序、.html、.shtml 等。
I would think if it's not already set up you could use apache's AddType directive:
http://httpd.apache.org/docs/1.3/mod/mod_mime.html#addtype:
"The AddType directive maps the given filename extensions onto the specified content type." -- so you would add a .php handler, .html, .shtml, etc as needed.
经过一段时间的谷歌搜索后,我仍在尝试将 xHTML5 的东西拼凑在一起。使用此:
...使用此标头时正确:
header("Content-Type:application/xhtml+xml;charset=UTF-8");
...来自服务器。或者应该是这样的:
...对于真正的 xhtml5 作为 mime 类型“applicaton/xhtml+xml”?
I am still trying to piece this xHTML5 thing together after some time Googling. So is using this:
...correct when using this header:
header("Content-Type:application/xhtml+xml;charset=UTF-8");
...from the server. Or should it be this:
...for true xhtml5 served as mime type 'applicaton/xhtml+xml'?