📄 699-702.html
字号:
<HTML>
<HEAD>
<TITLE>Special Edition Using Linux, Fourth Edition:Configuring Apache</TITLE>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!--ISBN=0789717468//-->
<!--TITLE=Special Edition Using Linux, Fourth Edition//-->
<!--AUTHOR=Jack Tackett//-->
<!--AUTHOR=Jr.//-->
<!--AUTHOR=Steve Burnett//-->
<!--PUBLISHER=Macmillan Computer Publishing//-->
<!--IMPRINT=Que//-->
<!--CHAPTER=36//-->
<!--PAGES=699-702//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="697-699.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="702-705.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>In your access.conf file, find the line that sets the options for the part of the site for which you want to enable content negotiation. (You can also set content negotiation for the whole site.) If <TT>MultiViews</TT> isn’t present in that line, it must be. Ironically enough, the <TT>All</TT> value doesn’t include <TT>MultiViews</TT>. This is again for backward compatibility. So, you might have a line that looks like</P>
<!-- CODE SNIP //-->
<PRE>
Options Indexes Includes Multiviews
</PRE>
<!-- END CODE SNIP //-->
<P>or
</P>
<!-- CODE SNIP //-->
<PRE>
Options All MultiViews
</PRE>
<!-- END CODE SNIP //-->
<P>When the <TT>MultiViews</TT> parameter is changed, you need to restart your server to implement the new configuration.</P>
<P>With <TT>MultiViews</TT> turned on, you can do the following: Place a JPEG image in a directory, such as /path/, and call it image.jpg. Now, make an equivalent GIF format image and place it in the same /path/ directory as image.gif. The URLs for these two objects are</P>
<!-- CODE SNIP //-->
<PRE>
<A HREF="http://host/path/image.jpg">http://host/path/image.jpg</A>
</PRE>
<!-- END CODE SNIP //-->
<P>and
</P>
<!-- CODE SNIP //-->
<PRE>
<A HREF="http://host/path/image.gif">http://host/path/image.gif</A>
</PRE>
<!-- END CODE SNIP //-->
<P>respectively. Now, if you ask your Web browser to fetch
</P>
<!-- CODE SNIP //-->
<PRE>
<A HREF="http://host/path/image">http://host/path/image</A>
</PRE>
<!-- END CODE SNIP //-->
<P>the server will go into the /path/ directory, see the two image files, and then determine which image format to send based on what the client says it can support. In the case where the client says it can accept JPEG or GIF images equally, the server will choose the version of the image that’s smaller and send that to the client. Usually, JPEG images are much smaller than GIF images.
</P>
<P>So if you made your HTML look something like the following,</P>
<!-- CODE SNIP //-->
<PRE>
<HTML><HEAD>
<TITLE>Welcome to the Gizmo Home Page!</TITLE>
</HEAD><BODY>
<IMG SRC="/header" ALT="GIZMO Logo">
Welcome to Gizmo!
<IMG SRC="/products" ALT="Products">
<IMG SRC="/services" ALT="Services">
</PRE>
<!-- END CODE SNIP //-->
<P>you can have separate GIF and JPEG files for header, products, and services. The clients will, for the most part, get what they claim they can support.
</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>If you have a file named image and a file named image.gif, the file named image will be returned if a request is made for image. Likewise, a request specifically for image.gif would never return image.jpg, even if the client knew how to render JPEG images.<HR></FONT>
</BLOCKQUOTE>
<P><FONT SIZE="+1"><B>Human-Language Negotiation</B></FONT></P>
<P>If <TT>MultiViews</TT> is enabled, you can also distinguish resources by the language they’re in, such as French, English, and Japanese. This is done by adding more entries to the file suffix name space, which map to the languages the server wants to use, and then by giving them a ranking in which ties can be broken. Specifically, in the srm.conf file, add two new directives—<TT>AddLanguage</TT> and <TT>LanguagePriority</TT>. The formats are as follows:</P>
<!-- CODE SNIP //-->
<PRE>
AddLanguage en .en
AddLanguage it .it
AddLanguage fr .fr
AddLanguage jp .jp
LanguagePriority en fr jp it
</PRE>
<!-- END CODE SNIP //-->
<P>Suppose that you want to negotiate the language on the file index.html, which you have available in English, French, Italian, and Japanese. You would create index.html.en, index.html.fr, index.html.it, and index.html.jp, respectively, and then reference the document as index.html. When a multilingual client connects, it should indicate in one of the request headers (specifically, <TT>Accept-Language</TT>) which languages it prefers, and the browser expresses that in standard two-letter notation. The server sees what the clients can accept and gives them “the best one.” <TT>LanguagePriority</TT> is what organizes that decision of “the best one.” If English is unacceptable to the client, try French; otherwise, try Japanese; otherwise, try Italian. <TT>LanguagePriority</TT> also states which one should be served if there’s no <TT>Accept-Language</TT> header.</P>
<P>Because the language-mapping suffixes and the content-type suffixes share the same name space, you can mix them around. index.fr.html is the same as index.html.fr. Just make sure that you reference it with the correct negotiable resource.</P>
<H4 ALIGN="LEFT"><A NAME="Heading14"></A><FONT COLOR="#000077">As-Is Files</FONT></H4>
<P>Often, you want to use headers in your documents, such as <TT>Expires:</TT>, but don’t want to make the page a CGI script. The easiest way is to add the httpd/send-as-is MIME type to the srm.conf file.</P>
<!-- CODE SNIP //-->
<PRE>
AddType httpd/send-as-is asis
</PRE>
<!-- END CODE SNIP //-->
<P>This means that any file that ends in .asis can include its own MIME headers. However, it must include two carriage returns before the actual body of the content. Actually, it should include two carriage-return/line-feed combinations, but Apache is forgiving and will insert the line feed for you. So if you want to send a document with a special custom MIME type that you don’t want registered with the server, you can send the following:
</P>
<!-- CODE SNIP //-->
<PRE>
Content-type: text/foobar
This is text in a very special "foobar" MIME type.
</PRE>
<!-- END CODE SNIP //-->
<P>The most significant application I’ve run across for this is as an extremely efficient mechanism for doing <I>server-push</I> (inline graphic animation) objects without CGI scripts. The reason a CGI script is needed to create a server-push usually is that the content type usually includes the multipart separator (because a server-push is actually a MIME multipart message). In the following examples, <TT>XXXXXXXX</TT> indicates the boundary between the parts of the multipart message:</P>
<!-- CODE //-->
<PRE>
Content-type: multipart/x-mixed-replace;boundary=XXXXXXXX
--XXXXXXXX
Content-type: image/gif
....(GIF data)....
--XXXXXXXX
Content-type: image/gif
....(GIF data)....
--XXXXXXXX
....
</PRE>
<!-- END CODE //-->
<P>By making a stream of data a simple file with the .asis parameter in the <TT>AddType</TT> directive instead of with a CGI script, you potentially save yourself a lot of overhead. Just about the only thing you lose is the capability to do timed pushes. For many people, slow Internet connection acts as a sufficient time valve.</P>
<P>If you have <TT>MultiViews</TT> turned on, you can add .asis to the end of a filename, and none of your links needs to be renamed. For example, foobar.html can easily become foobar.html.asis, yet you can still call it foobar.html.</P>
<P>One last compelling application of “asis” is being able to do HTTP redirection without needing access to server config files. For example, the following .asis file will redirect people to another location:</P>
<!-- CODE //-->
<PRE>
Status 302 Moved
Location: http://some.other.place.com/path/
Content-type: text/html
<HTML>
<HEAD><TITLE>We've Moved!</TITLE></HEAD>
<BODY>
<H1>We used to be here, but now we're
<A HREF="http://some.other.place.com/path/">over there. </A>
</H1>
</BODY></HTML>
</PRE>
<!-- END CODE //-->
<P>The HTML body is there simply for clients who don’t understand the 302 response.
</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="697-699.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="702-705.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -