📄 asg10.htm
字号:
Type:
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Handler Management</FONT>
</TABLE><P>The mod_actions module is compiled into Apache by default. It adds the functionality of setting user-defined handlers that execute CGI programs based on the MIME type of a request or the HTTP access method used for the request.
<BR>
<BR>
<A NAME="E69E89"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>mod_actions</B><B> Directives</B></FONT></CENTER></H4>
<BR>
<P>mod_actions adds two directives:
<BR>
<UL>
<LI>Action
<BR>
<BR>
<LI>Script
<BR>
<BR>
</UL>
<BR>
<A NAME="E70E48"></A>
<H5 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Action</B></FONT></CENTER></H5>
<BR>
<TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="80%" CELLPADDING=2 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Syntax:
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Action <I>mime-type cgi</I></FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Context:
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
server configuration, virtual host, directory, .htaccess</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Override:
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
AllowOverride FileInfo</FONT>
</TABLE><P>The Action directive adds a handler that runs <I>cgi</I> when <I>mime-type</I> is requested. The Action directive sets the URL and filepath of the request using the standard CGI environment variables PATH_INFO and PATH_TRANSLATED, respectively. The CGI program can then perform whatever action it needs to handle the request.
<BR>
<BR>
<A NAME="E70E49"></A>
<H5 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Script</B></FONT></CENTER></H5>
<BR>
<TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="80%" CELLPADDING=2 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Syntax:
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Script <I>http-method cgi</I></FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Context:
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
server configuration, virtual host, directory, .htaccess</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Override:
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
AllowOverride FileInfo</FONT>
</TABLE><P>The Script directive adds a handler that runs <I>cgi</I> when a file is requested using the <I>http-method</I>. Supported HTTP methods are GET, POST, PUT, or DELETE. The Action directive sets the URL and filepath of the request using the standard CGI environment variables PATH_INFO and PATH_TRANSLATED, respectively. The CGI program can then perform whatever action it needs to handle the request.
<BR>
<P>Script handlers only define default actions. If some resource is capable of handling the request internally, that resource will be called. GET requests are only passed to handler when they have query arguments—that is, the query string contains a question mark (?). This directive provides you with a way of implementing the PUT or DELETE methods in Apache.
<BR>
<BR>
<A NAME="E68E111"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>The </B><B>mod_alias</B><B> Module</B></FONT></CENTER></H3>
<BR>
<TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="80%" CELLPADDING=2 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Source:
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
mod_alias.c</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Base:
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Yes</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Type:
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Resource Location</FONT>
</TABLE><P>This module is compiled into Apache by default. It provides directives that allowF you to map document and CGI program directories that are in the local filesystem, but outside of DocumentRoot, into the server's document tree. This allows clients to reference these resources as if they were inside your DocumentRoot. The alias module also provides facilities for <I>uniform resource locator</I> (URL) redirection, which allows you to redirect the request to a different URL, perhaps in a different network.
<BR>
<BR>
<A NAME="E69E90"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>mod_alias</B><B> </B><B>Directives</B></FONT></CENTER></H4>
<BR>
<P>The directives provided are
<BR>
<UL>
<LI>Alias
<BR>
<BR>
<LI>Redirect
<BR>
<BR>
<LI>ScriptAlias
<BR>
<BR>
</UL>
<P>Typically, these directives are specified in the conf/srm.conf configuration file.
<BR>
<BR>
<A NAME="E70E50"></A>
<H5 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Alias</B></FONT></CENTER></H5>
<BR>
<TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="80%" CELLPADDING=2 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Syntax:
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Alias url-path directory-filename</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Context:
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
server configuration, virtual host</FONT>
</TABLE><P>The Alias directive allows you to reference directories in your local filesystem that are outside of your DocumentRoot as if they were located inside it. The Alias directive maps the request to <I>url-path</I> into the directory tree specified by <I>directory-filename</I>:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">Alias /icons/ /usr/local/etc/httpd/icons/</FONT></PRE>
<P>A request for http://www.mydomain.com/icons/text.gif will be mapped by the server to the file /usr/local/etc/httpd/icons/text.gif.
<BR>
<BR>
<A NAME="E70E51"></A>
<H5 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Redirect</B></FONT></CENTER></H5>
<BR>
<TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="80%" CELLPADDING=2 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Syntax:
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Redirect <I>url differenturl</I></FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Context:
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
server configuration, virtual host, and .htaccess (in Apache 1.1 or better).</FONT>
</TABLE><P>The Redirect directive allows you to map one URL into another. It can redirect a local request to a different Web server or an external URL. When the server receives a request for <I>url</I>, it returns <I>differenturl</I> to the client along with a REDIRECT HTTP response code. Better clients automatically re-requests the materials from the new URL:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">Redirect /projectA http://www.domain.dom/projectA</FONT></PRE>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>Use Redirect if you change the name of an often-accessed file. That way the error logs won't fill up with requests for the file from users who have bookmarked the URL, and visitors will have less trouble finding the new location.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>Apache 1.1 allows you to use the Redirect directive from an .htaccess file if the FileInfo option is enabled by the AllowOverride directive.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>Redirect directives take precedence over Alias and ScriptAlias directives.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BR>
<A NAME="E70E52"></A>
<H5 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>ScriptAlias</B></FONT></CENTER></H5>
<BR>
<TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="80%" CELLPADDING=2 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Syntax:
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
ScriptAlias <I>path URL</I></FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Context:
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
server configuration, virtual host</FONT>
</TABLE><P>The ScriptAlias directive is similar to the Alias directive. The ScriptAlias directive allows you to reference a CGI directory that is stored outside of your DocumentRoot, but in your local filesystem, as if it were inside your DocumentRoot. The difference is that the server marks the directory as containing CGI programs and permits their execution:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">ScriptAlias /cgi-bin/ /usr/local/etc/httpd/cgi-bin/</FONT></PRE>
<P>In this example, a request for http://www.mydomain.com/cgi-bin/foo.cgi will make the server run the program /usr/local/etc/httpd/cgi-bin/foo.cgi.
<BR>
<BR>
<A NAME="E68E112"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>The </B><B>mod_asis</B><B> </B><B>Module</B></FONT></CENTER></H3>
<BR>
<TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="80%" CELLPADDING=2 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Source:
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
mod_asis.c</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Base:
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Yes</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Type:
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
handler management</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Context:
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
server configuration</FONT>
</TABLE><P>The mod_asis module is built into Apache by default. This module allows you to specify <I>type</I> as a filetype that is to be sent without HTTP headers except for date and server headers. This module is internally used to send server redirects and other responses without the need for a CGI or a no parse header (nph) program.
<BR>
<P>Because the server does not return headers, you'll need to add them yourself. You'll need to return a status header (a three-digit HTTP response code) followed by a message. Apache can return any of the following HTTP response codes:
<BR>
<UL>
<UL>
<P><B> </B>200: OK
</UL></UL>
<UL>
<UL>
<P> 302: Found
</UL></UL>
<UL>
<UL>
<P> 304: Not Modified
</UL></UL>
<UL>
<UL>
<P> 400: Bad Request
</UL></UL>
<UL>
<UL>
<P> 401: Unauthorized
</UL></UL>
<UL>
<UL>
<P> 403: Forbidden
</UL></UL>
<UL>
<UL>
<P> 404: Not Found
</UL></UL>
<UL>
<UL>
<P> 500: Server Error
</UL></UL>
<UL>
<UL>
<P> 503: Out Of Resources (Service Unavailable)
</UL></UL>
<UL>
<UL>
<P> 501: Not Implemented
</UL></UL>
<UL>
<UL>
<P> 502: Bad Gateway
<BR>
</UL></UL>
<P>Here's an example of how to enable mod_asis:
<BR>
<UL>
<UL>
<P>Syntax: AddType httpd/send-as-is <I>type</I>
<BR>
</UL></UL>
<P>The following example defines the filetype .asis as a send-as-is filetype:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">AddType httpd/send-as-is asis</FONT></PRE>
<P>Here's an example that implements redirection using the send-as-is feature. A <I>redirection</I> makes the client look for the requested resource in a different location:
<BR>
<PRE>
<FONT COLOR="#000080">Status: 302 Site closed, go to a different server.
Location: http://www.mirror.com/index.html
Content-type: text/html
<HTML>
<HEAD>
<TITLE>This portion of our site is currently under remodeling, please visit a mirror site.</TITLE>
</HEAD>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -