<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Apache 234</title>
	<atom:link href="http://apache234.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://apache234.wordpress.com</link>
	<description>Blog for best httpd Apache234</description>
	<lastBuildDate>Sat, 27 Jun 2009 17:03:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='apache234.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/40693ae9b3b2f5fd4ae00c73476e8f95?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Apache 234</title>
		<link>http://apache234.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://apache234.wordpress.com/osd.xml" title="Apache 234" />
	<atom:link rel='hub' href='http://apache234.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Configuration Logging</title>
		<link>http://apache234.wordpress.com/2009/06/27/configuration-logging/</link>
		<comments>http://apache234.wordpress.com/2009/06/27/configuration-logging/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 16:58:53 +0000</pubDate>
		<dc:creator>apache234</dc:creator>
				<category><![CDATA[Logging]]></category>

		<guid isPermaLink="false">http://apache234.wordpress.com/?p=79</guid>
		<description><![CDATA[Apache is able to report to a client a great deal of what is happening to it internally. The necessary module is contained in the mod_info.c file, which should be included at build time. It provides a comprehensive overview of the server configuration, including all installed modules and directives in the configuration files. This module [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=apache234.wordpress.com&amp;blog=8348681&amp;post=79&amp;subd=apache234&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Apache is able to report to a client a great deal of what is  happening to it internally. The necessary module is contained in the <span>mod_info.c</span> file, which should be included at build  time. It provides a comprehensive overview of the server configuration,  including all installed modules and directives in the configuration files. This  module is not compiled into the server by default. To enable it, either load the  corresponding module if you are running Win32 or Unix with DSO support enabled,  or add the following line to the server build Config file and rebuild the  server:</p>
<pre>AddModule modules/standard/mod_info.o</pre>
<p>It should also be noted that if <span>mod_info</span> is compiled into the server, its handler  capability is available in all configuration files, including per-directory  files (e.g., <span>.htaccess</span>). This may have  security-related ramifications for your site. To demonstrate how this facility  can be applied to any site, the Config file on <em>&#8230;/site.info </em>is the  <em>&#8230;/site.authent </em>file slightly modified:</p>
<pre>User webuser
Group webgroup
ServerName www.butterthlies.com

NameVirtualHost 192.168.123.2

LogLevel debug

&lt;VirtualHost www.butterthlies.com&gt;
#CookieLog logs/cookies
AddModuleInfo mod_setenvif.c "This is what I've added to mod_setenvif"
ServerAdmin sales@butterthlies.com
DocumentRoot /usr/www/APACHE3/site.info/htdocs/customers
ServerName www.butterthlies.com
ErrorLog /usr/www/APACHE3/site.info/logs/error_log
TransferLog /usr/www/APACHE3/site.info/logs/customers/access_log
ScriptAlias /cgi-bin /usr/www/APACHE3/cgi-bin

&lt;Location /server-info&gt;
SetHandler server-info
&lt;/Location&gt;

&lt;/VirtualHost&gt;

&lt;VirtualHost sales.butterthlies.com&gt;
CookieLog logs/cookies
ServerAdmin sales_mgr@butterthlies.com
DocumentRoot /usr/www/APACHE3/site.info/htdocs/salesmen
ServerName sales.butterthlies.com
ErrorLog /usr/www/APACHE3/site.info/logs/error_log
TransferLog /usr/www/APACHE3/site.info/logs/salesmen/access_log
ScriptAlias /cgi-bin /usr/www/APACHE3/cgi-bin
&lt;Directory /usr/www/APACHE3/site.info/htdocs/salesmen&gt;
AuthType Basic
#AuthType Digest
AuthName darkness

AuthUserFile /usr/www/APACHE3/ok_users/sales
AuthGroupFile /usr/www/APACHE3/ok_users/groups

#AuthDBMUserFile /usr/www/APACHE3/ok_dbm/sales
#AuthDBMGroupFile /usr/www/APACHE3/ok_dbm/groups

#AuthDigestFile /usr/www/APACHE3/ok_digest/sales
require valid-user
satisfy any
order deny,allow
allow from 192.168.123.1
deny from all
#require user daphne bill
#require group cleaners
#require group directors
&lt;/Directory&gt;

&lt;Directory /usr/www/APACHE3/cgi-bin&gt;
AuthType Basic
AuthName darkness
AuthUserFile /usr/www/APACHE3/ok_users/sales
AuthGroupFile /usr/www/APACHE3/ok_users/groups
#AuthDBMUserFile /usr/www/APACHE3/ok_dbm/sales
#AuthDBMGroupFile /usr/www/APACHE3/ok_dbm/groups
require valid-user
&lt;/Directory&gt;

&lt;/VirtualHost&gt;</pre>
<p>Note the <tt>AddModuleInfo</tt> line and the <tt>&lt;Location  ...&gt;</tt> block.</p>
<h4>1 AddModuleInfo</h4>
<p>The <tt>AddModule</tt> directive allows the content of  <tt><em>string</em></tt> to be shown as HTML-interpreted additional information  for the module <tt><em>module-name</em></tt>.</p>
<pre>AddModuleInfo <tt><em>module-name string</em></tt>
Server config, virtual host</pre>
<p>For example:</p>
<pre>AddModuleInfo mod_auth.c 'See &lt;A HREF="http://www.apache.org/docs/mod/
    mod auth.html"&gt;http://www.apache.org/docs/mod/mod_auth.html&lt;/A&gt;'</pre>
<p>To invoke the module, browse to <span>www.butterthlies.com/server-info</span>,and you will see  something like the following:</p>
<pre>Apache Server Information
Server Settings, mod_setenvif.c, mod_usertrack.c, mod_auth_digest.c, mod_auth_db.c,
mod_auth_anon.c, mod_auth.c, mod_access.c, mod_rewrite.c, mod_alias.c, mod_userdir.c,
mod_actions.c, mod_imap.c, mod_asis.c, mod_cgi.c, mod_dir.c, mod_autoindex.c, mod_
include.c, mod_info.c, mod_status.c, mod_negotiation.c, mod_mime.c, mod_log_config.c,
mod_env.c, http_core.c
Server Version: Apache/1.3.14 (Unix)
Server Built: Feb 13 2001 15:20:23
API Version: 19990320:10
Run Mode: standalone
User/Group: webuser(1000)/1003
Hostname/port: www.butterthlies.com:0
Daemons: start: 5 min idle: 5 max idle: 10 max: 256
Max Requests: per child: 0 keep alive: on max per connection: 100
Threads: per child: 0
Excess requests: per child: 0
Timeouts: connection: 300 keep-alive: 15
Server Root: /usr/www/APACHE3/site.info
Config File: /usr/www/APACHE3/site.info/conf/httpd.conf
PID File: logs/httpd.pid
Scoreboard File: logs/apache_runtime_status

Module Name: mod_setenvif.c
Content handlers: none
Configuration Phase Participation: Create Directory Config, Merge Directory Configs,
Create Server Config, Merge Server Configs
Request Phase Participation: Post-Read Request, Header Parse
Module Directives:
SetEnvIf - A header-name, regex and a list of variables.
SetEnvIfNoCase - a header-name, regex and a list of variables.
BrowserMatch - A browser regex and a list of variables.
BrowserMatchNoCase - A browser regex and a list of variables.
Current Configuration:
Additional Information:
This is what I've added to mod_setenvif
............</pre>
<p>The file carries on to document all the compiled-in modules.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/apache234.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/apache234.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/apache234.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/apache234.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/apache234.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/apache234.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/apache234.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/apache234.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/apache234.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/apache234.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/apache234.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/apache234.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/apache234.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/apache234.wordpress.com/79/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=apache234.wordpress.com&amp;blog=8348681&amp;post=79&amp;subd=apache234&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://apache234.wordpress.com/2009/06/27/configuration-logging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/362f6b0de20f8ab4fa364d41b94609b4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">apache234</media:title>
		</media:content>
	</item>
		<item>
		<title>Apache&#8217;s Logging Facilities</title>
		<link>http://apache234.wordpress.com/2009/06/27/apaches-logging-facilities/</link>
		<comments>http://apache234.wordpress.com/2009/06/27/apaches-logging-facilities/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 16:58:23 +0000</pubDate>
		<dc:creator>apache234</dc:creator>
				<category><![CDATA[Logging]]></category>

		<guid isPermaLink="false">http://apache234.wordpress.com/?p=77</guid>
		<description><![CDATA[Apache offers a wide range of options for controlling the format of the log files. In line with current thinking, older methods (RefererLog, AgentLog, and CookieLog) have now been replaced by the config_log_module. To illustrate this, we have taken &#8230; /site.authent and copied it to &#8230; /site.logging so that we can play with the logs: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=apache234.wordpress.com&amp;blog=8348681&amp;post=77&amp;subd=apache234&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Apache offers a wide range of options for controlling the  format of the log files. In line with current thinking, older methods  (<tt>RefererLog</tt>, <tt>AgentLog</tt>, and <tt>CookieLog</tt>) have now been  replaced by the <span>config_log_module</span>. To illustrate  this, we have taken <em>&#8230; /site.authent</em> and copied it to <em>&#8230;  /site.logging</em> so that we can play with the logs:</p>
<pre>User webuser
Group webgroup
ServerName www.butterthlies.com

IdentityCheck	on
NameVirtualHost 192.168.123.2
&lt;VirtualHost www.butterthlies.com&gt;
LogFormat "customers: host %h, logname %l, user %u, time %t, request %r,
    status %s,bytes %b,"
CookieLog logs/cookies
ServerAdmin sales@butterthlies.com
DocumentRoot /usr/www/APACHE3/site.logging/htdocs/customers
ServerName www.butterthlies.com
ErrorLog /usr/www/APACHE3/site.logging/logs/customers/error_log
TransferLog /usr/www/APACHE3/site.logging/logs/customers/access_log
ScriptAlias /cgi_bin /usr/www/APACHE3/cgi_bin
&lt;/VirtualHost&gt;
&lt;VirtualHost sales.butterthlies.com&gt;
LogFormat "sales: agent %{httpd_user_agent}i, cookie: %{http_Cookie}i,
    referer: %{Referer}o, host %!200h, logname %!200l, user %u, time %t,
    request %r, status %s,bytes %b,"
CookieLog logs/cookies
ServerAdmin sales_mgr@butterthlies.com
DocumentRoot /usr/www/APACHE3/site.logging/htdocs/salesmen
ServerName sales.butterthlies.com
ErrorLog /usr/www/APACHE3/site.logging/logs/salesmen/error_log
TransferLog /usr/www/APACHE3/site.logging/logs/salesmen/access_log
ScriptAlias /cgi_bin /usr/www/APACHE3/cgi_bin
&lt;Directory /usr/www/APACHE3/site.logging/htdocs/salesmen&gt;
AuthType Basic
AuthName darkness
AuthUserFile /usr/www/APACHE3/ok_users/sales
AuthGroupFile /usr/www/APACHE3/ok_users/groups
require valid-user
&lt;/Directory&gt;
&lt;Directory /usr/www/APACHE3/cgi_bin&gt;
AuthType Basic
AuthName darkness
AuthUserFile /usr/www/APACHE3/ok_users/sales
AuthGroupFile /usr/www/APACHE3/ok_users/groups
#AuthDBMUserFile /usr/www/APACHE3/ok_dbm/sales
#AuthDBMGroupFile /usr/www/APACHE3/ok_dbm/groups
require valid-user
&lt;/Directory&gt;
&lt;/VirtualHost&gt;</pre>
<p>There are a number of directives.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>ErrorLog</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>ErrorLog <tt><em>filename</em></tt>|syslog[:<tt><em>facility</em></tt>]
Default: ErrorLog logs/error_log
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>The <tt>ErrorLog</tt> directive sets the name of the file to  which the server will log any errors it encounters. If the filename does not  begin with a slash (/), it is assumed to be relative to the server root.</p>
<p><img src="unix.gif" border="0" alt="figs/unix.gif" width="24" height="11" /></p>
<p>If the filename begins with a pipe (|), it is assumed to be a  command to spawn a file to handle the error log.</p>
<h4>Apache 1.3 and Above</h4>
<p><img src="unix.gif" border="0" alt="figs/unix.gif" width="24" height="11" /></p>
<p>Using <tt>syslog</tt> instead of a filename enables logging via  <span>syslogd(8)</span> if the system supports it. The default  is to use <span>syslog</span> facility <span>local7</span>, but you can override this by using the  <tt>syslog:<em>facility</em></tt> syntax, where <tt><em>facility</em></tt> can be  one of the names usually documented in <span>syslog(1)</span>.  Using <tt>syslog</tt> allows you to keep logs for multiple servers in a  centralized location, which can be very convenient in larger installations.</p>
<p>Your security could be compromised if the directory where log  files are stored is writable by anyone other than the user who starts the  server.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>TransferLog</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>TransferLog [ <tt><em>file</em></tt> | "| <tt><em>command</em></tt> "]
Default: none
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p><tt>TransferLog</tt> specifies the file in which to store the  log of accesses to the site. If it is not explicitly included in the Config  file, no log will be generated.</p>
<dl>
<dt><span><tt><em>file</em></tt></span> </dt>
<dd>This is a filename relative to the server root (if it doesn&#8217;t  start with a slash), or an absolute path (if it does).</p>
</dd>
<dt><span><tt><em>command</em></tt></span> </dt>
<dd>Note the format: <tt>"|<em> command</em>"</tt>. The double quotes  are needed in the Config file. <tt><em>command</em></tt> is a program to receive  the agent log information on its standard input. Note that a new program is not  started for a virtual host if it inherits the <tt>TransferLog</tt> from the main  server. If a program is used, it runs using the permissions of the user who  started <span>httpd</span>. This is root if the server was  started by <span>root</span>, so be sure the program is  secure. A useful Unix program to which to send is <span>rotatelogs</span>,<span><a href="#EN10-1"><sup>[1]</sup></a></span> which can be found in the Apache  <em>support</em> subdirectory. It closes the log periodically and starts a new  one, and it&#8217;s useful for long-term archiving and log processing. Traditionally,  this is done by shutting Apache down, moving the logs elsewhere, and then  restarting Apache, which is obviously no fun for the clients connected at the  time!</p>
</dd>
</dl>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>AgentLog</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>AgentLog file-pipe
AgentLog logs/agent_log
Server config, virtual host
Not in Apache v2</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>The <tt>AgentLog</tt> directive sets the name of the file to  which the server will log the <tt>User-Agent</tt> header of incoming requests.  <tt>file-pipe</tt> is one of the following:</p>
<pre>A filename
A filename relative to the ServerRoot.
"| &lt;command&gt;"</pre>
<p>This is a program to receive the agent log information on its  standard input. Note that a new program will not be started for a  <tt>VirtualHost</tt> if it inherits the <tt>AgentLog</tt> from the main server.</p>
<p>This directive is provided for compatibility with NCSA 1.4.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>LogLevel</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>LogLevel level
Default: error
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p><tt>LogLevel</tt> controls the amount of information recorded  in the error_log file. The levels are as follows:</p>
<dl>
<dt><span><span>emerg</span></span> </dt>
<dd>The system is unusable — exiting. For example:</p>
<pre>"Child cannot open lock file. Exiting"</pre>
</dd>
<dt><span><span>alert</span></span> </dt>
<dd>Immediate action is necessary. For example:</p>
<pre>"getpwuid: couldn't determine user name from uid"</pre>
</dd>
<dt><span><span>crit</span></span> </dt>
<dd>Critical condition. For example:</p>
<pre>"socket: Failed to get a socket, exiting child"</pre>
</dd>
<dt><span><span>error</span></span> </dt>
<dd>Client is not getting a proper service. For example:</p>
<pre>"Premature end of script headers"</pre>
</dd>
<dt><span><span>warn</span></span> </dt>
<dd>Nonthreatening problems, which may need attention. For example:</p>
<pre>"child process 1234 did not exit, sending another SIGHUP"</pre>
</dd>
<dt><span><span>notice</span></span> </dt>
<dd>Normal events, which may need to be evaluated. For example:</p>
<pre>"httpd: caught SIGBUS, attempting to dump core in ..."</pre>
</dd>
<dt><span><span>info</span></span> </dt>
<dd>For example:</p>
<pre>"Server seems busy, (you may need to increase StartServers, or Min/MaxSpareServers)..."</pre>
</dd>
<dt><span><span>debug</span></span> </dt>
<dd>Logs normal events for debugging purposes.</p>
</dd>
</dl>
<p>Each level will report errors that would have been printed by  higher levels. Use <tt>debug</tt> for development, then switch to, say,  <tt>crit</tt> for production. Remember that if each visitor on a busy site  generates one line in the <em>error_log</em>, the hard disk will soon fill up and  stop the system.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>LogFormat</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>LogFormat <tt><em>format_string [nickname]</em></tt>
Default: "%h %l %u %t \"%r\" %s %b"
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p><tt>LogFormat</tt> sets the information to be included in the  log file and the way in which it is written. The default format is the Common  Log Format (CLF), which is expected by off-the-shelf log analyzers such as  <em>wusage</em> (<a href="http://www.boutell.com/" target="_blank">http://www.boutell.com/</a>) or <em>ANALOG</em>, so if you want to  use one of them, leave this directive alone. The CLF format is as follows:</p>
<pre><tt><em>host ident authuser date request status bytes</em></tt></pre>
<dl>
<dt><span><tt><em>host</em></tt></span> </dt>
<dd>Hostname of the client or its IP number.</p>
</dd>
<dt><span><tt><em>ident</em></tt></span> </dt>
<dd>If <tt>IdentityCheck</tt> is enabled and the client machine  runs <tt>identd</tt>, the identity information reported by the client. (This can  cause performance issues as the server makes <tt>identd</tt> requests that may  or may not be answered.)</p>
</dd>
<dt><span><tt><em>authuser</em></tt></span> </dt>
<dd>If the request was for a password-protected document, is the  user ID.</p>
</dd>
<dt><span><tt><em>date</em></tt></span> </dt>
<dd>The date and time of the request, in the following format:</p>
<pre>[<tt><em>day</em></tt>/<tt><em>month</em></tt>/<tt><em>year:hour:minute:second  tzoffset</em></tt>].</pre>
</dd>
<dt><span><tt><em>request</em></tt></span> </dt>
<dd>Request line from client, in double quotes.</p>
</dd>
<dt><span><tt><em>status</em></tt></span> </dt>
<dd>Three-digit status code returned to the client.</p>
</dd>
<dt><span><tt><em>bytes</em></tt></span> </dt>
<dd>The number of bytes returned, excluding headers.</p>
</dd>
</dl>
<p>The log format can be customized using a  <tt><em>format_string</em></tt>. The commands in it have the format  <tt>%[<em>condition</em>]<em>key_letter </em></tt>; the <tt><em>condition</em></tt> need not be present. If it is and the specified condition is not met, the output  will be a <tt>-</tt>. The <tt><em>key_letter </em></tt>s are as follows:</p>
<pre>%...a: Remote IP-address
%...A: Local IP-address
%...B: Bytes sent, excluding HTTP headers.
%...b: Bytes sent, excluding HTTP headers. In CLF format i.e. a '-' rather than a 0
when no bytes are sent.
%...{Foobar}C: The contents of cookie "Foobar" in the request sent to the server.
%...D: The time taken to serve the request, in microseconds.
%...{FOOBAR}e: The contents of the environment variable FOOBAR
%...f: Filename
%...h: Remote host
%...H The request protocol
%...{Foobar}i: The contents of Foobar: header line(s) in the request sent to the
server.
%...l: Remote logname (from identd, if supplied)
%...m The request method
%...{Foobar}n: The contents of note "Foobar" from another module.
%...{Foobar}o: The contents of Foobar: header line(s) in the reply.
%...p: The canonical Port of the server serving the request
%...P: The process ID of the child that serviced the request.
%...q The query string (prepended with a ? if a query string exists, otherwise an
empty string) %...r: First line of request
%...s: Status. For requests that got internally redirected, this is the status of the
*original* request ---
%...&gt;s for the last.
%...t: Time, in common log format time format (standard english format) %...
{format}t: The time, in the form given by format, which should be in strftime(3)
format. (potentially localized)
%...T: The time taken to serve the request, in seconds.
%...u: Remote user (from auth; may be bogus if return status (%s) is 401)
%...U: The URL path requested, not including any query string.
%...v: The canonical ServerName of the server serving the request.
%...V: The server name according to the UseCanonicalName setting.
%...X: Connection status when response is completed. 'X' = connection aborted before
the response completed. '+' = connection may be kept alive after the response is
sent. '-' = connection will be closed after the response is sent. (This directive was
%...c in late versions of Apache 1.3, but this conflicted with the historical ssl %...{var}c syntax.)</pre>
<p>The format string can contain ordinary text of your choice in  addition to the <tt>%</tt> directives.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>CustomLog</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>CustomLog <tt><em>file</em></tt>|<tt><em>pipe format</em></tt>|<tt><em>nickname</em></tt>
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>The first argument is the filename to which log records should  be written. This is used exactly like the argument to <tt>TransferLog</tt>; that  is, it is either a full path, relative to the current server root, or a pipe to  a program.</p>
<p>The format argument specifies a format for each line of the log  file. The options available for the format are exactly the same as those for the  argument of the <tt>LogFormat</tt> directive. If the format includes any spaces  (which it will in almost all cases), it should be enclosed in double quotes.</p>
<p>Instead of an actual format string, you can use a format  nickname defined with the <tt>LogFormat</tt> directive.</p>
<h4>10.2.1 site.authent —  Another Example</h4>
<p><em>site.authent</em> is set up with two virtual hosts, one for  customers and one for salespeople, and each has its own logs in <em>&#8230;  /logs/customers</em> and <em>&#8230; /logs/salesmen</em>. We can follow that scheme and  apply one <tt>LogFormat</tt> to both, or each can have its own logs with its own  <tt>LogFormat</tt>s inside the <tt>&lt;VirtualHost&gt;</tt> directives. They can  also have common log files, set up by moving <tt>ErrorLog</tt> and  <tt>TransferLog</tt> outside the <tt>&lt;VirtualHost&gt;</tt> sections, with  different <tt>LogFormat</tt>s within the sections to distinguish the entries. In  this last case, the <tt>LogFormat</tt> files could look like this:</p>
<pre>&lt;VirtualHost www.butterthlies.com&gt;
LogFormat "Customer:..."
...
&lt;/VirtualHost&gt;

&lt;VirtualHost sales.butterthlies.com&gt;
LogFormat "Sales:..."
...
&lt;/VirtualHost&gt;</pre>
<p>Let&#8217;s experiment with a format for customers, leaving  everything else the same:</p>
<pre>&lt;VirtualHost www.butterthlies.com&gt;
LogFormat "customers: host %h, logname %l, user %u, time %t, request %r
    status %s, bytes %b,"
...</pre>
<p>We have inserted the words <tt>host</tt><em>, </em><tt>logname</tt>,<em> </em>and so on to make it clear in the file what is  doing what. In real life you probably wouldn&#8217;t want to clutter the file up in  this way because you would look at it regularly and remember what was what or,  more likely, process the logs with a program that would know the format. Logging  on to <span>www.butterthlies.com</span> and going to  <tt>summer</tt> <tt>catalog</tt> produces this log file:</p>
<pre>customers: host 192.168.123.1, logname unknown, user -, time [07/Nov/
    1996:14:28:46 +0000], request GET / HTTP/1.0, status 200,bytes -
customers: host 192.168.123.1, logname unknown, user -, time [07/Nov/
    1996:14:28:49 +0000], request GET /hen.jpg HTTP/1.0, status 200,
    bytes 12291,
customers: host 192.168.123.1, logname unknown, user -, time [07/Nov
    /1996:14:29:04 +0000], request GET /tree.jpg HTTP/1.0, status 200,
    bytes 11532,
customers: host 192.168.123.1, logname unknown, user -, time [07/Nov/
    1996:14:29:19 +0000], request GET /bath.jpg HTTP/1.0, status 200,
    bytes 5880,</pre>
<p>This is not too difficult to follow. Notice that while we have  <tt>logname</tt> <tt>unknown</tt>, the user is -, the usual report for an  unknown value. This is because customers do not have to give an ID; the same log  for salespeople<em>, </em>who do, would have a value here.</p>
<p>We can improve things by inserting lists of conditions based on  the error codes after the <tt>%</tt> and before the command letter. The error  codes are defined in the HTTP 1.0 specification:</p>
<pre>200 OK
302 Found
304 Not Modified
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not found
500 Server error
503 Out of resources
501 Not Implemented
502 Bad Gateway</pre>
<p>The list from HTTP 1.1 is as follows:</p>
<pre>100  Continue
101  Switching Protocols
200  OK
201  Created
202  Accepted
203  Non-Authoritative Information
204  No Content
205  Reset Content
206  Partial Content
300  Multiple Choices
301  Moved Permanently
302  Moved Temporarily
303  See Other
304  Not Modified
305  Use Proxy
400  Bad Request
401  Unauthorized
402  Payment Required
403  Forbidden
404  Not Found
405  Method Not Allowed
406  Not Acceptable
407  Proxy Authentication Required
408  Request Time-out
409  Conflict
410  Gone
411  Length Required
412  Precondition Failed
413  Request Entity Too Large
414  Request-URI Too Large
415  Unsupported Media Type
500  Internal Server Error
501  Not Implemented
502  Bad Gateway
503  Service Unavailable
504  Gateway Time-out
505  HTTP Version not supported</pre>
<p>You can use <tt>!</tt> before a code to mean &#8220;if not.&#8221;  <tt>!200</tt> means &#8220;log this if the response was <span>not</span> OK.&#8221; Let&#8217;s put this in <span>salesmen</span>:</p>
<pre>&lt;VirtualHost sales.butterthlies.com&gt;
LogFormat "sales: host %!200h, logname %!200l, user %u, time %t, request %r,
    status %s,bytes %b,"
...</pre>
<p>An attempt to log in as <span>fred</span> with the password <tt>don't</tt> <tt>know</tt> produces the following entry:</p>
<pre>sales: host 192.168.123.1, logname unknown, user fred, time [19/Aug/
    1996:07:58:04 +0000], request GET HTTP/1.0, status 401, bytes -</pre>
<p>However, if it had been the infamous <em>bill</em> with the  password <tt>theft</tt>, we would see:</p>
<pre>host -, logname -, user bill, ...</pre>
<p>because we asked for <tt>host</tt> and<em> </em><tt>logname</tt> to be logged only if the request was not OK. We can combine more than one  condition, so that if we only want to know about security problems on sales, we  could log usernames only if they failed to authenticate:</p>
<pre>LogFormat "sales: bad user: %400,401,403u"</pre>
<p>We can also extract data from the HTTP headers in both  directions:</p>
<pre>%[<tt><em>condition</em></tt>]{user-agent}i</pre>
<p>This prints the user agent (i.e., the software the client is  running) if <tt><em>condition</em></tt> is met. The old way of doing this was  <tt>AgentLog</tt> <tt><em>logfile</em></tt> and <tt>ReferLog</tt> <tt><em>logfile</em></tt>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/apache234.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/apache234.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/apache234.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/apache234.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/apache234.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/apache234.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/apache234.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/apache234.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/apache234.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/apache234.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/apache234.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/apache234.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/apache234.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/apache234.wordpress.com/77/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=apache234.wordpress.com&amp;blog=8348681&amp;post=77&amp;subd=apache234&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://apache234.wordpress.com/2009/06/27/apaches-logging-facilities/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/362f6b0de20f8ab4fa364d41b94609b4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">apache234</media:title>
		</media:content>

		<media:content url="unix.gif" medium="image">
			<media:title type="html">figs/unix.gif</media:title>
		</media:content>

		<media:content url="unix.gif" medium="image">
			<media:title type="html">figs/unix.gif</media:title>
		</media:content>
	</item>
		<item>
		<title>Logging by Script and Database</title>
		<link>http://apache234.wordpress.com/2009/06/27/logging-by-script-and-database/</link>
		<comments>http://apache234.wordpress.com/2009/06/27/logging-by-script-and-database/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 16:57:09 +0000</pubDate>
		<dc:creator>apache234</dc:creator>
				<category><![CDATA[Logging]]></category>

		<guid isPermaLink="false">http://apache234.wordpress.com/?p=74</guid>
		<description><![CDATA[If your site uses a database manager, you could sidestep this cumbersome procedure by writing scripts on the fly to log everything you want to know about your visitors, reading data about them from the environment variables, and recording their choices as they work through the site. Depending on your needs, it can be much [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=apache234.wordpress.com&amp;blog=8348681&amp;post=74&amp;subd=apache234&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If your site uses a database manager, you could sidestep this  cumbersome procedure by writing scripts on the fly to log everything you want to  know about your visitors, reading data about them from the environment  variables, and recording their choices as they work through the site. Depending  on your needs, it can be much easier to log the data directly than to mine it  out of the log files. For instance, one of the authors (PL) has a medical  encyclopedia web site (<a href="http://www.medic-planet.com/" target="_blank">www.Medic-Planet.com</a>). Simple Perl scripts write database  records to keep track of the following:</p>
<ul>
<li>How often each article has been read</li>
<li>How visitors got to it</li>
<li>How often search engine spiders visit and who they are</li>
<li>How often visitors click through the many links on the site and  where they go</li>
</ul>
<p>Having stored this useful information in the database manager,  it is then not hard to write a script, accessed via an SSL connection (see <a href="_chapter%2011.htm">Chapter 11</a>), which can only be  accessed by the site management to generate HTML reports with totals and  statistics that illuminate marketing problems.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/apache234.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/apache234.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/apache234.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/apache234.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/apache234.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/apache234.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/apache234.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/apache234.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/apache234.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/apache234.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/apache234.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/apache234.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/apache234.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/apache234.wordpress.com/74/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=apache234.wordpress.com&amp;blog=8348681&amp;post=74&amp;subd=apache234&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://apache234.wordpress.com/2009/06/27/logging-by-script-and-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/362f6b0de20f8ab4fa364d41b94609b4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">apache234</media:title>
		</media:content>
	</item>
		<item>
		<title>Performance</title>
		<link>http://apache234.wordpress.com/2009/06/27/performance/</link>
		<comments>http://apache234.wordpress.com/2009/06/27/performance/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 16:56:48 +0000</pubDate>
		<dc:creator>apache234</dc:creator>
				<category><![CDATA[Proxying]]></category>

		<guid isPermaLink="false">http://apache234.wordpress.com/?p=72</guid>
		<description><![CDATA[The proxy server&#8217;s performance can be improved by caching incoming pages so that the next time one is called for, it can be served straight up without having to waste time going over the Web. We can do the same thing for outgoing pages, particularly pages generated on the fly by CGI scripts and database [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=apache234.wordpress.com&amp;blog=8348681&amp;post=72&amp;subd=apache234&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The proxy server&#8217;s performance can be improved by caching  incoming pages so that the next time one is called for, it can be served  straight up without having to waste time going over the Web. We can do the same  thing for outgoing pages, particularly pages generated on the fly by CGI scripts  and database accesses (bearing in mind that this can lead to stale content and  is not invariably desirable).</p>
<h4>1 Inward Caching</h4>
<p>Another reason for using a proxy server is to cache data from  the Web to save the bandwidth of the world&#8217;s clogged telephone systems and  therefore to improve access time on our server. Note, however, that it in  practice it often saves bandwidth at the expense of increased access times.</p>
<p>The directive <tt>CacheRoot</tt>, cunningly inserted in the  Config file shown earlier, and the provision of a properly permissioned cache  directory allow us to show this happening. We start by providing the directory  <em>&#8230; /</em><span>site.proxy/cache,</span> and Apache then  improves on it with some sort of directory structure like <em>&#8230;  /site.proxy/cache/d/o/j/gfqbZ@49rZiy6LOCw.</em></p>
<p>The file <em>gfqbZ@49rZiy6LOCw</em> contains the following:</p>
<pre>320994B6 32098D95 3209956C 00000000 0000001E
X-URL: http://192.168.124.1/message
HTTP/1.0 200 OK
Date: Thu, 08 Aug 1996 07:18:14 GMT
Server: Apache/1.1.1
Content-length: 30
Last-modified Thu, 08 Aug 1996 06:47:49 GMT

I am a web site far out there</pre>
<p>Next time someone wants to access <span>http://192.168.124.1/message</span>, the proxy server does not  have to lug bytes over the Web; it can just go and look it up.</p>
<p>There are a number of housekeeping directives that help with  caching.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>CacheRoot</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>CacheRoot <tt><em>directory</em></tt>
Default: none
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>This directive sets the <tt>directory</tt> to contain cache  files; must be writable by Apache.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>CacheSize</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>CacheSize <tt><em>size_in_kilobytes</em></tt>
Default: 5
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>This directive sets the size of the cache area in kilobytes.  More may be stored temporarily, but garbage collection reduces it to less than  the set number.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>CacheGcInterval</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>CacheGcInterval <tt><em>hours</em></tt>
Default: never
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>This directive specifies how often, in hours, Apache checks the  cache and does a garbage collection if the amount of data exceeds  <tt>CacheSize</tt>.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>CacheMaxExpire</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>CacheMaxExpire <tt><em>hours</em></tt>
Default: 24
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>This directive specifies how long cached documents are  retained. This limit is enforced even if a document is supplied with an  expiration date that is further in the future.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>CacheLastModifiedFactor</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>CacheLastModifiedFactor <tt><em>factor</em></tt>
Default: 0.1
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>If no expiration time is supplied with the document, then  estimate one by multiplying the time since last modification by  <tt><em>factor</em></tt>. <tt>CacheMaxExpire</tt> takes precedence.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>CacheDefaultExpire</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>CacheDefaultExpire <tt><em>hours</em></tt>
Default: 1
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>If the document is fetched by a protocol that does not support  expiration times, use this number. <tt>CacheMaxExpire</tt> does not override it.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>CacheDirLevels and CacheDirLength</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>CacheDirLevels <tt><em>number</em></tt>
Default: 3
CacheDirLength <tt><em>number</em></tt>
Default: 1
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>The proxy module stores its cache with filenames that are a  hash of the URL. The filename is split into <tt>CacheDirLevels</tt> of directory  using <tt>CacheDirLength</tt> characters for each level. This is for efficiency  when retrieving the files (a flat structure is very slow on most systems). So,  for example:</p>
<pre>CacheDirLevels 3
CacheDirLength 2</pre>
<p>converts the hash &#8220;abcdefghijk&#8221; into <em>ab/cd/ef/ghijk</em>. A  real hash is actually 22 characters long, each character being one of a possible  64 (2<sup>6</sup>), so that three levels, each with a length of 1, gives  2<sup>18</sup> directories. This number should be tuned to the anticipated  number of cache entries (2<sup>18</sup> being roughly a quarter of a million,  and therefore good for caches up to several million entries in size).</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>CacheNegotiatedDocs</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>CacheNegotiatedDocs
Default: none
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>If present in the Config file, this directive allows  content-negotiated documents to be cached by proxy servers. This could mean that  clients behind those proxys could retrieve versions of the documents that are  not the best match for their abilities, but it will make caching more efficient.</p>
<p>This directive only applies to requests that come from HTTP 1.0  browsers. HTTP 1.1 provides much better control over the caching of negotiated  documents, and this directive has no effect on responses to HTTP 1.1 requests.  Note that very few browsers are HTTP 1.0 anymore.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>NoCache</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>NoCache [<tt><em>host</em></tt>|<tt><em>domain</em></tt>] [<tt><em>host</em></tt>|<tt><em>domain</em></tt>] ...</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>This directive specifies a list of hosts and/or domains,  separated by spaces, from which documents are not cached, such as the site  delivering your real-time stock market quotes .</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/apache234.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/apache234.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/apache234.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/apache234.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/apache234.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/apache234.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/apache234.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/apache234.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/apache234.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/apache234.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/apache234.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/apache234.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/apache234.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/apache234.wordpress.com/72/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=apache234.wordpress.com&amp;blog=8348681&amp;post=72&amp;subd=apache234&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://apache234.wordpress.com/2009/06/27/performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/362f6b0de20f8ab4fa364d41b94609b4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">apache234</media:title>
		</media:content>
	</item>
		<item>
		<title>Apparent Bug</title>
		<link>http://apache234.wordpress.com/2009/06/27/apparent-bug/</link>
		<comments>http://apache234.wordpress.com/2009/06/27/apparent-bug/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 16:56:09 +0000</pubDate>
		<dc:creator>apache234</dc:creator>
				<category><![CDATA[Proxying]]></category>

		<guid isPermaLink="false">http://apache234.wordpress.com/?p=70</guid>
		<description><![CDATA[When a server is set up as a proxy, then requests of the form: GET http://someone.else.com/ HTTP/1.0 are accepted and proxied to the appropriate web server. By default, Apache does not proxy, but it can appear that it is prepared to — requests like the previous will be accepted and handled by the default configuration. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=apache234.wordpress.com&amp;blog=8348681&amp;post=70&amp;subd=apache234&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When a server is set up as a proxy, then requests of the  form:</p>
<pre>GET http://someone.else.com/ HTTP/1.0</pre>
<p>are accepted and proxied to the appropriate web server. By  default, Apache does not proxy, but it can appear that it is prepared to —  requests like the previous will be accepted and handled by the default  configuration. Apache assumes that <span>someone.else.com</span> is a virtual host on the current  machine. People occasionally think this is a bug, but it is, in fact, correct  behavior. Note that pages served will be the same as those that would be served  for any real unknown virtual host on the same machine, so this does not pose a  security risk.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/apache234.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/apache234.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/apache234.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/apache234.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/apache234.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/apache234.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/apache234.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/apache234.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/apache234.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/apache234.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/apache234.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/apache234.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/apache234.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/apache234.wordpress.com/70/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=apache234.wordpress.com&amp;blog=8348681&amp;post=70&amp;subd=apache234&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://apache234.wordpress.com/2009/06/27/apparent-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/362f6b0de20f8ab4fa364d41b94609b4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">apache234</media:title>
		</media:content>
	</item>
		<item>
		<title>Proxy Directives</title>
		<link>http://apache234.wordpress.com/2009/06/27/proxy-directives/</link>
		<comments>http://apache234.wordpress.com/2009/06/27/proxy-directives/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 16:54:57 +0000</pubDate>
		<dc:creator>apache234</dc:creator>
				<category><![CDATA[Proxying]]></category>

		<guid isPermaLink="false">http://apache234.wordpress.com/?p=68</guid>
		<description><![CDATA[We are not concerned here with firewalls, so we take them for granted. The interesting thing is how we configure the proxy Apache to make life with a firewall tolerable to those behind it. site.proxy has three subdirectories: cache, proxy, real. The Config file from &#8230; /site. proxy/proxy is as follows: User webuser Group webgroup [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=apache234.wordpress.com&amp;blog=8348681&amp;post=68&amp;subd=apache234&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We are not concerned here with firewalls, so we take them for  granted. The interesting thing is how we configure the proxy Apache to make life  with a firewall tolerable to those behind it.</p>
<p><span>site.proxy</span> has three  subdirectories: <span>cache, proxy, real.</span> The Config  file from <em>&#8230; /site. proxy/proxy</em> is as follows:</p>
<pre>User webuser
Group webgroup
ServerName www.butterthlies.com

Port 8000
ProxyRequests on
CacheRoot /usr/www/APACHE3/site.proxy/cache
CacheSize 1000</pre>
<p>The points to notice are as follows:</p>
<ul>
<li>On this site we use <tt>ServerName</tt> <em>www.butterthlies.com.</em></li>
<li>The <tt>Port</tt> number is set to 8000 so we don&#8217;t collide  with the real web server running on the same machine.</li>
<li>We turn <tt>ProxyRequests</tt> <tt>on</tt> and provide a  directory for the cache, which we will discuss later in this chapter.</li>
<li><tt>CacheRoot</tt> is set up in a special directory.</li>
<li><tt>CacheSize</tt> is set to 1000 kilobytes.</li>
</ul>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>AllowCONNECT</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>AllowCONNECT port [port] ...
AllowCONNECT 443 563
Server config, virtual host
Compatibility: AllowCONNECT is only available in Apache 1.3.2 and later.</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>The <tt>AllowCONNECT</tt> directive specifies a list of port  numbers to which the proxy CONNECT method may connect. Today&#8217;s browsers use this  method when a https connection is requested and proxy tunneling over http is in  effect.</p>
<p>By default, only the default <em>https</em> port (443) and the  default <em>snews</em> port (563) are enabled. Use the <tt>AllowCONNECT</tt> directive to override this default and allow connections to the listed ports  only.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>ProxyRequests</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>ProxyRequests [on|off]
Default: off
Server config</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>This directive turns proxy serving on. Even if  <tt>ProxyRequests</tt> is <tt>off</tt>, <tt>ProxyPass</tt> directives are still  honored.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>ProxyRemote</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>ProxyRemote <tt><em>match remote-server</em></tt>
Server config</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>This directive defines remote proxies to this proxy (that is,  proxies that should be used for some requests instead of being satisfied  directly). <tt><em>match</em></tt> is either the name of a URL scheme that the  remote server supports, a partial URL for which the remote server should be  used, or <tt>*</tt> to indicate that the server should be contacted for all  requests. <tt><em>remote-server</em></tt><em> </em>is the URL that should be used to  communicate with the remote server (i.e., it is of the form  <tt>protocol://hostname[:port]</tt>). Currently, only HTTP can be used as the  protocol for the <tt>remote-server</tt>. For example:</p>
<pre>  ProxyRemote ftp http://ftpproxy.mydomain.com:8080
  ProxyRemote http://goodguys.com/ http://mirrorguys.com:8000
  ProxyRemote * http://cleversite.com</pre>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>ProxyPass</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>ProxyPass <tt><em>path url</em></tt>
Server config</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>This command runs on an ordinary server and translates requests  for a named directory and below to a demand to a proxy server. So, on our  ordinary Butterthlies site, we might want to pass requests to <span>/secrets</span> onto a proxy server <em>darkstar.com</em>:</p>
<pre>ProxyPass /secrets http://darkstar.com</pre>
<p>Unfortunately, this is less useful than it might appear, since  the proxy does not modify the HTML returned by <a href="mailto:darkstar.com">darkstar.com</a>. This means that URLs embedded in  the HTML will refer to documents on the main server unless they have been  written carefully. For example, suppose a document <em>one.html</em> is stored on  <span>darkstar.com</span> with the URL <span>http://darkstar.com/one.html</span>, and we want it to refer  to another document in the same directory. Then the following links will work,  when accessed as <span>http://www.butterthlies.com/secrets/one.html</span>:</p>
<pre>&lt;A HREF="two.html"&gt;Two&lt;/A&gt;
&lt;A HREF="/secrets/two.html"&gt;Two&lt;/A&gt;
&lt;A HREF="http://darkstar.com/two.html"&gt;Two&lt;/A&gt;</pre>
<p>But this example will not work:</p>
<pre>&lt;A HREF="/two.html"&gt;Not two&lt;/A&gt;</pre>
<p>When accessed directly, through <span>http://darkstar.com/one.html</span>, these links work:</p>
<pre>&lt;A HREF="two.html"&gt;Two&lt;/A&gt;
&lt;A HREF="/two.html"&gt;Two&lt;/A&gt;
&lt;A HREF="http://darkstar.com/two.html"&gt;Two&lt;/A&gt;</pre>
<p>But the following doesn&#8217;t:</p>
<pre>&lt;A HREF="/secrets/two.html"&gt;Two&lt;/A&gt;</pre>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>ProxyDomain</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>ProxyDomain <tt><em>domain</em></tt>
Server config</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>This directive tends to be useful only for Apache proxy servers  within intranets. The <tt>ProxyDomain</tt> directive specifies the default  domain to which the Apache proxy server will belong. If a request to a host  without a fully qualified domain name is encountered, a redirection response to  the same host with the configured <tt><em>domain</em></tt> appended will be  generated. The point of this is that users on intranets often only type the  first part of the domain name into the browser, but the server requires a fully  qualified domain name to work properly.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>NoProxy</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>NoProxy<tt><em> </em></tt>{ <tt><em>domain</em></tt> | <tt><em>subnet</em></tt> | <tt><em>ip_addr</em></tt> | <tt><em>hostname</em></tt> }
Server config</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>The <tt>NoProxy</tt> directive specifies a list of subnets, IP  addresses, hosts, and/or domains, separated by spaces. A request to a host that  matches one or more of these is always served directly, without forwarding to  the configured <tt>ProxyRemote</tt> proxy server(s).</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>ProxyPassReverse</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>ProxyPassReverse<tt><em> path url</em></tt>
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>A reverse proxy is a way to masquerade one server as another —  perhaps because the &#8220;real&#8221; server is behind a firewall or because you want part  of a web site to be served by a different machine but not to look that way. It  can also be used to share loads between several servers — the frontend server  simply accepts requests and forwards them to one of several backend servers. The  optional module <span>mod_rewrite</span> has some special  stuff in it to support this. This directive lets Apache adjust the URL in the  <tt>Location</tt> response header. If a <tt>ProxyPass</tt> (or <span>mod_rewrite</span>) has been used to do reverse proxying, then  this directive will rewrite <tt>Location</tt> headers coming back from the  reverse-proxied server so that they look as if they came from somewhere else  (normally this server, of course).</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>ProxyVia</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>ProxyVia on|off|full|block
Default: ProxyVia off
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>This directive controls the use of the <tt>Via:</tt> HTTP  header by the proxy. Its intended use is to control the flow of proxy requests  along a chain of proxy servers. See RFC2068 (HTTP 1.1) for an explanation of  <tt>Via:</tt> header lines.</p>
<ul>
<li>If set to <tt>off</tt>, which is the default, no special  processing is performed. If a request or reply contains a <tt>Via:</tt> header,  it is passed through unchanged.</li>
<li>If set to <tt>on</tt>, each request and reply will get a  <tt>Via:</tt> header line added for the current host.</li>
<li>If set to <tt>full</tt>, each generated <tt>Via:</tt> header  line will additionally have the Apache server version shown as a <tt>Via:</tt> comment field.</li>
<li>If set to <tt>block</tt>, every proxy request will have all its  <tt>Via:</tt> header lines removed. No new <tt>Via:</tt> header will be  generated.</li>
</ul>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>ProxyReceiveBufferSize</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>ProxyReceiveBufferSize bytes
Default: None
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>The <tt>ProxyReceiveBufferSize</tt> directive specifies an  explicit network buffer size for outgoing HTTP and FTP connections for increased  throughput. It has to be greater than 512 or set to 0 to indicate that the  system&#8217;s default buffer size should be used.</p>
<h4>Example</h4>
<pre>ProxyReceiveBufferSize 2048</pre>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>ProxyBlock</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>ProxyBlock *|word|host|domain [word|host|domain] ...
Default: None
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>The <tt>ProxyBlock</tt> directive specifies a list of words,  hosts and/or domains, separated by spaces. HTTP, HTTPS, and FTP document  requests to sites whose names contain matched words, hosts, or domains that are  blocked by the proxy server. The proxy module will also attempt to determine IP  addresses of list items that may be hostnames during startup and cache them for  match test as well. For example:</p>
<pre>ProxyBlock joes-garage.com some-host.co.uk rocky.wotsamattau.edu</pre>
<p><span>rocky.wotsamattau.edu</span> would also  be matched if referenced by IP address.</p>
<p>Note that <span>wotsamattau</span> would also  be sufficient to match <span>wotsamattau.edu</span>.</p>
<p>Note also that:</p>
<pre>ProxyBlock *</pre>
<p>blocks connections to all sites.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/apache234.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/apache234.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/apache234.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/apache234.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/apache234.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/apache234.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/apache234.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/apache234.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/apache234.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/apache234.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/apache234.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/apache234.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/apache234.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/apache234.wordpress.com/68/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=apache234.wordpress.com&amp;blog=8348681&amp;post=68&amp;subd=apache234&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://apache234.wordpress.com/2009/06/27/proxy-directives/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/362f6b0de20f8ab4fa364d41b94609b4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">apache234</media:title>
		</media:content>
	</item>
		<item>
		<title>Security</title>
		<link>http://apache234.wordpress.com/2009/06/27/security/</link>
		<comments>http://apache234.wordpress.com/2009/06/27/security/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 16:54:31 +0000</pubDate>
		<dc:creator>apache234</dc:creator>
				<category><![CDATA[Proxying]]></category>

		<guid isPermaLink="false">http://apache234.wordpress.com/?p=66</guid>
		<description><![CDATA[An important concern on the Web is keeping the Bad Guys out of your network. One established technique is to keep the network hidden behind a firewall; this works well, but as soon as you do it, it also means that everyone on the same network suddenly finds that their view of the Net has [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=apache234.wordpress.com&amp;blog=8348681&amp;post=66&amp;subd=apache234&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>An important concern on the Web is keeping the Bad Guys out of  your network. One  established technique is to keep the network hidden behind a firewall; this  works well, but as soon as you do it, it also means that everyone on the same  network suddenly finds that their view of the Net has disappeared (rather like  people living near Miami Beach before and after the building boom). This becomes  an urgent issue at Butterthlies, Inc., as competition heats up and  naughty-minded Bad Guys keep trying to break our security and get in. We install  a firewall and, anticipating the instant outcries from the marketing animals who  need to get out on the Web and surf for prey, we also install a proxy server to  get them out there.</p>
<p>So, in addition to the Apache that serves clients visiting our  sites and is protected by the firewall, we need a copy of Apache to act as a  proxy server to let us, in our turn, access other sites out on the Web. Without  the proxy server, those inside are safe but blind.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/apache234.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/apache234.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/apache234.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/apache234.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/apache234.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/apache234.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/apache234.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/apache234.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/apache234.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/apache234.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/apache234.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/apache234.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/apache234.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/apache234.wordpress.com/66/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=apache234.wordpress.com&amp;blog=8348681&amp;post=66&amp;subd=apache234&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://apache234.wordpress.com/2009/06/27/security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/362f6b0de20f8ab4fa364d41b94609b4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">apache234</media:title>
		</media:content>
	</item>
		<item>
		<title>Rewrite</title>
		<link>http://apache234.wordpress.com/2009/06/27/rewrite/</link>
		<comments>http://apache234.wordpress.com/2009/06/27/rewrite/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 16:53:50 +0000</pubDate>
		<dc:creator>apache234</dc:creator>
				<category><![CDATA[Redirection]]></category>

		<guid isPermaLink="false">http://apache234.wordpress.com/?p=64</guid>
		<description><![CDATA[The preceding section described the Alias module and its allies. Everything these directives can do, and more, can be done instead by mod_rewrite.c, an extremely compendious module that is almost a complete software product in its own right. But for simple tasks Alias and friends are much easier to use. The documentation is thorough, and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=apache234.wordpress.com&amp;blog=8348681&amp;post=64&amp;subd=apache234&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The preceding section described the <em>Alias</em> module and its  allies. Everything these directives can do, and more, can be done instead by  <em>mod_rewrite.c</em>, an extremely compendious module that is almost a complete  software product in its own right. But for simple tasks <tt>Alias</tt> and  friends are much easier to use.</p>
<p>The documentation is thorough, and the reader is referred to <a href="http://www.engelschall.com/pw/apache/rewriteguide/" target="_blank">http://www.engelschall.com/pw/apache/rewriteguide/</a> for any  serious work. You should also look at <a href="http://www.apache.org/docs/mod/mod_rewrite.html" target="_blank">http://www.apache.org/docs/mod/mod_rewrite.html</a>. This section  is intended for orientation only.</p>
<p><tt>Rewrite</tt> takes a<em> </em><span>rewriting pattern</span> and applies it to the URL. If it  matches, a <span>rewriting substitution</span> is applied to  the URL. The patterns are regular expressions<em> </em>familiar to us all in their  simplest form — for example, <tt>mod.*\.c</tt><span>,</span> which matches any module filename. The complete science of regular expressions  is somewhat extensive, and the reader is referred to<em> &#8230;  /src/regex/regex.7</em>, a manpage that can be read with <tt>nroff</tt> <tt>-man</tt> <tt>regex.7</tt> (on FreeBSD, at least). Regular expressions are  also described in the POSIX specification and in Jeffrey Friedl&#8217;s <span>Mastering Regular Expressions</span> (O&#8217;Reilly, 2002).</p>
<p>It might well be worth using Perl to practice with regular  expressions before using them in earnest. To make complicated expressions work,  it is almost essential to build them up from simple ones, testing each change as  you go. Even the most expert find that convoluted regular expressions often do  not work the first time.</p>
<p>The essence of regular expressions is that a number of special  characters can be used to match parts of incoming URLs. The substitutions  available in <em>mod_rewrite</em> can include mapping functions that take bits of  the incoming URL and look them up in databases or even apply programs to them.  The rules can be applied repetitively and recursively to the evolving URL. It is  possible (as the documentation says) to create &#8220;rewriting loops, rewriting  breaks, chained rules, pseudo if-then-else constructs, forced redirects, forced  MIME-types, forced proxy module throughout.&#8221; The functionality is so extensive  that it is probably impossible to master it in the abstract. When and if you  have a problem of this sort, it looks as if <em>mod_rewrite</em> can solve it,  given enough intellectual horsepower on your part!</p>
<p>The module can be used in four situations:</p>
<ul>
<li>By the administrator inside the server Config file to apply in  all contexts. The rules are applied to all URLs of the main server and all URLs  of the virtual servers.</li>
<li>By the administrator inside &lt;<tt>VirtualHost&gt;</tt> blocks. The rules are applied only to the URLs of the virtual server.</li>
<li>By the administrator inside <tt>&lt;Directory&gt;</tt> blocks.  The rules are applied only to the specified directory.</li>
<li>By users in their <em>.htaccess</em> files. The rules are applied  only to the specified directory.</li>
</ul>
<p>The directives look simple enough.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>RewriteEngine</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>RewriteEngine on_or_off
Server config, virtual host, directory</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>Enables or disables the rewriting engine. If <tt>off</tt>, no  rewriting is done at all. Use this directive to switch off functionality rather  than commenting out <tt>Rewrite-Rule</tt> lines.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>RewriteLog</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>RewriteLog <em>filename</em>
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>Sends logging to the specified <tt><em>filename</em></tt>. If the  name does not begin with a slash, it is taken to be relative to the server root.  This directive should appear only once in a Config file.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>RewriteLogLevel</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>RewriteLogLevel <em>number</em>
Default <tt><em>number</em></tt>: 0
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>Controls the verbosity of the logging: <tt>0</tt> means no  logging, and <tt>9</tt> means that almost every action is logged. Note that any  number above 2 slows Apache down.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>RewriteMap</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>RewriteMap <em>mapname</em> {txt,dbm,prg,rnd,int}: <em>filename</em>
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>Defines an external <tt><em>mapname</em></tt> file that inserts  substitution strings through key lookup.Keys may be stored in a variety of  formats, described as follows. The module passes <tt><em>mapname</em></tt><em> </em>a query in the form:</p>
<pre>$(<tt><em>mapname</em></tt> : <tt><em>Lookupkey</em></tt> | <tt><em>DefaultValue</em></tt>)</pre>
<p>If the <tt><em>Lookupkey</em></tt> value is not found,  <tt><em>DefaultValue</em></tt> is returned.</p>
<p>The type of <tt><em>mapname</em></tt> must be specified by the  next argument:</p>
<dl>
<dt><span><span>txt</span> </span> </dt>
<dd>Indicates plain-text format — that is, an ASCII file with blank  lines, comments that begin with <tt>#</tt>, or useful lines, in the format:</p>
<pre><tt><em>MatchingKey
SubstituteValue</em></tt></pre>
</dd>
<dt><span><span>dbm</span></span> </dt>
<dd>Indicates DBM hashfile format — that is, a binary NDBM (the  &#8220;new&#8221; <span>dbm</span> interface, now about 15 years old, also  used for <span>dbm</span> auth) file containing the same  material as the plain-text format file. You create it with any <span>ndbm</span> tool or by using the Perl script <em>dbmmanage</em> from the support directory of the Apache distribution.</p>
</dd>
<dt><span><span>prg</span></span> </dt>
<dd>Indicates program format — that is, an executable (a compiled  program or a CGI script) that is started by Apache. At each lookup, it is passed  the key as a string terminated by newline on <tt>stdin</tt> and returns the  substitution value, or the word <tt>NULL</tt> if lookup fails, in the same way  on <tt>stdout</tt>. The manual gives two warnings:</p>
<ul>
<li>Keep the program or script simple because if it hangs, it hangs  the Apache server.</li>
<li>Don&#8217;t use buffered I/O on <tt>stdout</tt> because it causes a  deadlock. In C, use:<br />
<blockquote><p>setbuf(stdout,NULL)</p></blockquote>
<p>In Perl, use:</p>
<blockquote><p>select(STDOUT); $|=1;]</p></blockquote>
</li>
</ul>
</dd>
<dt><span><span>rnd</span></span> </dt>
<dd>Indicates randomized plain text, which is similar to the  standard plain-text variant but has a special postprocessing feature: after  looking up a value, it is parsed according to contained &#8220;|&#8221; characters that have  the meaning of &#8220;or&#8221;. In other words, they indicate a set of alternatives from  which the actual returned value is chosen randomly. Although this sounds crazy  and useless, it was actually designed for load balancing in a reverse-proxy  situation, in which the looked-up values are server names — each request to a  reverse proxy is routed to a randomly selected server behind it. See also <a href="_chapter%2012.htm#apache3-CHP-12-SECT-6">Section 12.6</a> in  <a href="_chapter%2012.htm">Chapter 12</a>.</p>
</dd>
<dt><span><span>int</span></span> </dt>
<dd>Indicates an internal Apache function. Two functions exist:  <tt>toupper( )</tt><strong> </strong>and <tt>tolower( )</tt>, which convert the looked-up  key to all upper- or all lowercase.</p>
</dd>
</dl>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>RewriteBase</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>RewriteBase <em>BaseURL</em>
directory, .htaccess</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>The effects of this command can be fairly easily achieved by  using the rewrite rules, but it may sometimes be simpler to encapsulate the  process. It explicitly sets the base URL for per-directory rewrites. If  <tt>RewriteRule</tt> is used in an <em>.htaccess</em> file, it is passed a URL  that has had the local directory stripped off so that the rules act only on the  remainder. When the substitution is finished, <tt>RewriteBase</tt> supplies the  necessary prefix. To quote the manual&#8217;s example in <em>.htaccess</em>:</p>
<pre>Alias /xyz /abc/def"
RewriteBase   /xyz
RewriteRule   ^oldstuff\.html$  newstuff.html</pre>
<p>In this example, a request to <em>/xyz/oldstuff.html</em> gets  rewritten to the physical file <em>/abc/def/newstuff.html</em>. Internally, the  following happens:</p>
<dl>
<dt><span>Request </span> </dt>
<dd><em>/xyz/oldstuff.html</em></p>
</dd>
<dt><em><span>Internal processing</span></em> </dt>
<dd>
<pre>/xyz/oldstuff.html     -&gt; /abc/def/oldstuff.html  (per-server Alias)
/abc/def/oldstuff.html -&gt; /abc/def/newstuff.html  (per-dir    RewriteRule)
/abc/def/newstuff.html -&gt; /xyz/newstuff.html      (per-dir    RewriteBase)
/xyz/newstuff.html     -&gt; /abc/def/newstuff.html  (per-server Alias)</pre>
</dd>
<dt><em><span>Result </span></em> </dt>
<dd><em>/abc/def/newstuff.html</em></p>
</dd>
</dl>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>RewriteCond</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>RewriteCond <em>TestString</em> <em>CondPattern</em>
Server config, virtual host, directory</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>One or more <tt>RewriteCond</tt> directives can precede a  <tt>RewriteRule</tt> directive to define conditions under which it is to be  applied. <tt><em>CondPattern</em></tt> is a regular expression matched against the  value retrieved for <tt><em>TestString</em></tt>, which contains server variables  of the form <tt>%{<em>NAME_OF_VARIABLE</em>}</tt>, where  <tt><em>NAME_OF_VARIABLE</em></tt> can be one of the following list:</p>
<table border="1" cellspacing="0" cellpadding="1" width="100%">
<tbody>
<tr>
<td><tt>API_VERSION</tt></td>
<td><tt>PATH_INFO</tt></td>
<td><tt>SERVER_PROTOCOL</tt></td>
</tr>
<tr>
<td><tt>AUTH_TYPE</tt></td>
<td><tt>QUERY_STRING</tt></td>
<td><tt>SERVER_SOFTWARE</tt></td>
</tr>
<tr>
<td><tt>DOCUMENT_ROOT</tt></td>
<td><tt>REMOTE_ADDR</tt></td>
<td><tt>THE_REQUEST</tt></td>
</tr>
<tr>
<td><tt>ENV:any_environment_variable</tt></td>
<td><tt>REMOTE_HOST</tt></td>
<td><tt>TIME</tt></td>
</tr>
<tr>
<td><tt>HTTP_ACCEPT</tt></td>
<td><tt>REMOTE_USER</tt></td>
<td><tt>TIME_DAY</tt></td>
</tr>
<tr>
<td><tt>HTTP_COOKIE</tt></td>
<td><tt>REMOTE_IDENT</tt></td>
<td><tt>TIME_HOUR</tt></td>
</tr>
<tr>
<td><tt>HTTP_FORWARDED</tt></td>
<td><tt>REQUEST_FILENAME</tt></td>
<td><tt>TIME_MIN</tt></td>
</tr>
<tr>
<td><tt>HTTP_HOST</tt></td>
<td><tt>REQUEST_METHOD</tt></td>
<td><tt>TIME_MON</tt></td>
</tr>
<tr>
<td><tt>HTTP_PROXY_CONNECTION</tt></td>
<td><tt>REQUEST_URI</tt></td>
<td><tt>TIME_SEC</tt></td>
</tr>
<tr>
<td><tt>HTTP_REFERER</tt></td>
<td><tt>SCRIPT_FILENAME</tt></td>
<td><tt>TIME_WDAY</tt></td>
</tr>
<tr>
<td><tt>HTTP_USER_AGENT</tt></td>
<td><tt>SERVER_ADMIN</tt></td>
<td><tt>TIME_YEAR</tt></td>
</tr>
<tr>
<td><tt>HTTP:any_HTTP_header</tt></td>
<td><tt>SERVER_NAME</tt></td>
<td></td>
</tr>
<tr>
<td><tt>IS_SUBREQ</tt></td>
<td><tt>SERVER_PORT</tt></td>
<td></td>
</tr>
</tbody>
</table>
<p>These variables all correspond to the similarly named HTTP MIME  headers, C variables of the Apache server, or the current time. If the regular  expression does not match, the <tt>RewriteRule</tt> following it does not apply.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>RewriteLock</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>RewriteLock <tt><em>Filename</em></tt>
Server config</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>This directive sets the filename for a synchronization  lockfile, which <em>mod_rewrite</em> needs to communicate with <tt>RewriteMap</tt> programs. Set this lockfile to a local path (not on a NFS-mounted device) when  you want to use a rewriting map program. It is not required for other types of  rewriting maps.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>RewriteOptions</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>RewriteOptions <tt><em>Option</em></tt>
Default: None
Server config, virtual host, directory, .htaccess</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>The <tt>RewriteOptions</tt> directive sets some special options  for the current per-server or per-directory configuration. Currently, there is  only one <tt><em>Option</em></tt>:</p>
<pre>inherit</pre>
<p>This forces the current configuration to inherit the  configuration of the parent. In per-virtual-server context this means that the  maps, conditions, and rules of the main server are inherited. In per-directory  context this means that conditions and rules of the parent directory&#8217;s  <em>.htaccess</em> configuration are inherited.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>RewriteRule</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>RewriteRule <tt><em>Pattern Substitution</em></tt> [<tt><em>flags</em></tt>]
Server config, virtual host, directory</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>This directive can be used as many times as necessary. Each  occurrence applies the rule to the output of the preceding one, so the order  matters. <tt><em>Pattern</em></tt><em> </em>is matched to the incoming URL; if it  succeeds, the <tt><em>Substitution</em></tt> is made. An optional argument,  <tt><em>flags</em></tt>,<em> </em>can be given. The flags, which follow, can be  abbreviated to one or two letters:</p>
<dl>
<dt><span><span>redirect|R</span></span> </dt>
<dd>Force redirect.</p>
</dd>
<dt><span><span>proxy|P</span></span> </dt>
<dd>Force proxy.</p>
</dd>
<dt><span><span>last|L</span> </span> </dt>
<dd>Last rule — go to top of rule with current URL.</p>
</dd>
<dt><span><span>chain|C</span></span> </dt>
<dd>Apply following chained rule if this rule matches.</p>
</dd>
<dt><span><span>type|T=</span> <tt><em>mime-type</em></tt></span> </dt>
<dd>Force target file to be <tt><em>mime-type.</em></tt></p>
</dd>
<dt><span><span>nosubreq|NS</span></span> </dt>
<dd>Skip rule if it is an internal subrequest.</p>
</dd>
<dt><span><span>env|E=VAR:VAL</span></span> </dt>
<dd>Set an environment variable.</p>
</dd>
<dt><span><span>qsappend|QSA</span></span> </dt>
<dd>Append a query string.</p>
</dd>
<dt><span><span>passthrough|PT</span></span> </dt>
<dd>Pass through to next handler.</p>
</dd>
<dt><span><span>skip|S=</span> <tt><em>num</em></tt></span> </dt>
<dd>Skip the next <tt><em>num</em></tt><em> </em>rules.</p>
</dd>
<dt><span><span>next|N</span></span> </dt>
<dd>Next round — start at the top of the rules again.</p>
</dd>
<dt><span><span>gone|G</span></span> </dt>
<dd>Returns HTTP response 410 — &#8220;URL Gone.&#8221;</p>
</dd>
<dt><span><span>forbidden|F</span></span> </dt>
<dd>Returns HTTP response 403 — &#8220;URL Forbidden.&#8221;</p>
</dd>
<dt><span><span>nocase|NC</span></span> </dt>
<dd>Makes the comparison case insensitive.</p>
</dd>
</dl>
<p>For example, say we want to rewrite URLs of the form:</p>
<pre>/Language/~Realname/.../File</pre>
<p>into:</p>
<pre>/u/Username/.../File.Language</pre>
<p>We take the rewrite map file and save it under  <em>/anywhere/map.real-to-user</em>. Then we only have to add the following lines  to the Apache server Config file:</p>
<pre>RewriteLog   /anywhere/rewrite.log
RewriteMap   real-to-user  txt:/anywhere/map.real-to-host
RewriteRule  ^/([^/]+)/~([^/]+)/(.*)$   /u/${real-to-user:$2|nobody}/$3.$1</pre>
<h4>1 A Rewrite  Example</h4>
<p>The Butterthlies salespeople seem to be taking their jobs more  seriously. Our range has increased so much that the old catalog based around a  single HTML document is no longer workable because there are too many cards. We  have built a database of cards and a utility called <em>cardinfo</em> that  accesses it using the arguments:</p>
<pre>cardinfo <tt><em>cardid query</em></tt></pre>
<p>where <tt><em>cardid</em></tt> is the number of the card and  <tt><em>query</em></tt> is one of the following words: &#8220;price,&#8221; &#8220;artist,&#8221; or  &#8220;size.&#8221; The problem is that the salespeople are too busy to remember the syntax,  so we want to let them log on to the card database as if it were a web site. For  instance, going to <span>http://sales.butterthlies.com/info/2949/price</span> would  return the price of card number 2949. The Config file is in <em>&#8230; /site.rewrite </em>:</p>
<pre>User webuser
Group webgroup
# Apache requires this server name, although in this case it will
# never be used.
# This is used as the default for any server that does not match a
# VirtualHost section.
ServerName www.butterthlies.com

NameVirtualHost 192.168.123.2

&lt;VirtualHost www.butterthlies.com&gt;
ServerAdmin sales@butterthlies.com
DocumentRoot /usr/www/APACHE3/site.rewrite/htdocs/customers
ServerName www.butterthlies.com
ErrorLog /usr/www/APACHE3/site.rewrite/logs/customers/error_log
TransferLog /usr/www/APACHE3/site.rewrite/logs/customers/access_log
&lt;/VirtualHost&gt;

&lt;VirtualHost sales.butterthlies.com&gt;
ServerAdmin sales_mgr@butterthlies.com
DocumentRoot /usr/www/APACHE3/site.rewrite/htdocs/salesmen
Options ExecCGI indexes
ServerName sales.butterthlies.com
ErrorLog /usr/www/APACHE3/site.rewrite/logs/salesmen/error_log
TransferLog /usr/www/APACHE3/site.rewrite/logs/salesmen/access_log
RewriteEngine on
RewriteLog logs/rewrite
RewriteLogLevel 9
RewriteRule ^/info/([^/]+)/([^/]+)$   /cgi-bin/cardinfo?$2+$1 [PT]
ScriptAlias /cgi-bin /usr/www/APACHE3/cgi-bin
&lt;/VirtualHost&gt;</pre>
<p>In real life <tt>cardinfo</tt> would be an elaborate program.  However, here we just have to show that it could work, so it is extremely  simple:</p>
<pre>#!/bin/sh
#
echo "content-type: text/html"
echo sales.butterthlies.com
echo "You made the query $1 on the card $2"</pre>
<p>To make sure everything is in order before we do it for real,  we turn <tt>RewriteEngine</tt> <tt>off</tt> and access <span>http://sales.butterthlies.com/cgi-bin/cardinfo.</span> We get  back the following message:</p>
<pre>The requested URL /info/2949/price was not found on this server.</pre>
<p>This is not surprising. We now stop Apache, turn  <tt>RewriteEngine</tt> <tt>on</tt> and restart with <tt>./go.</tt> Look at the  crucial line in the Config file:</p>
<pre>RewriteRule ^/info/([^/]+)/([^/]+)$ /cgi-bin/cardinfo?$2+$1 [PT]</pre>
<p>Translated into English, this means the following: at the start  of the string, match <tt>/info/</tt>, followed by one or more characters that  aren&#8217;t <tt>/</tt>, and put those characters into the variable <tt>$1</tt> (the  parentheses do this; <tt>$1</tt> because they are the first set). Then match a  <tt>/</tt>, then one or more characters aren&#8217;t <tt>/</tt>, and put those  characters into <tt>$2</tt>. Then match the end of the string, and pass the  result through <tt>[PT]</tt> to the next rule, which is <tt>ScriptAlias</tt>. We  end up as if we had accessed <span>http://sales.butterthlies.com/cgi-bin/cardinfo?&lt;card  ID&gt;+&lt;query&gt;.</span></p>
<p>If the CGI script is on a different web server for some reason,  we could write:</p>
<pre>RewriteRule ^/info/([^/]+)/([^/]+)$ http://somewhere.else.com/cgi-bin/
    cardinfo?$2+$1 [PT]</pre>
<p>Note that this pattern won&#8217;t match <span>/info/123/price/fred</span> because it has too many slashes in  it.</p>
<p>If we run all this with <tt>./go</tt> and access <span>http://sales.butterthlies.com/info/2949/price</span> from the  client, we see the following message:</p>
<pre>You made the query price on card 2949</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/apache234.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/apache234.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/apache234.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/apache234.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/apache234.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/apache234.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/apache234.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/apache234.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/apache234.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/apache234.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/apache234.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/apache234.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/apache234.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/apache234.wordpress.com/64/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=apache234.wordpress.com&amp;blog=8348681&amp;post=64&amp;subd=apache234&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://apache234.wordpress.com/2009/06/27/rewrite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/362f6b0de20f8ab4fa364d41b94609b4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">apache234</media:title>
		</media:content>
	</item>
		<item>
		<title>Alias</title>
		<link>http://apache234.wordpress.com/2009/06/27/alias/</link>
		<comments>http://apache234.wordpress.com/2009/06/27/alias/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 16:52:37 +0000</pubDate>
		<dc:creator>apache234</dc:creator>
				<category><![CDATA[Redirection]]></category>

		<guid isPermaLink="false">http://apache234.wordpress.com/2009/06/27/alias/</guid>
		<description><![CDATA[One of the most useful directives is Alias, which lets you store documents elsewhere. We can demonstrate this simply by creating a new directory, /usr/www/APACHE3/somewhere_else, and putting in it a file lost.txt, which has this message in it: I am somewhere else httpd2.conf has an extra line: ... Alias /somewhere_else /usr/www/APACHE3/somewhere_else ... Stop Apache and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=apache234.wordpress.com&amp;blog=8348681&amp;post=63&amp;subd=apache234&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One of the most useful directives is <tt>Alias</tt>, which lets  you store documents elsewhere. We can demonstrate this simply by creating a new  directory, <em>/usr/www/APACHE3/somewhere_else, </em>and putting in it a file  <em>lost.txt,</em> which has this message in it:</p>
<pre>I am somewhere else</pre>
<p><em>httpd2.conf</em> has an extra line:</p>
<pre>...
Alias /somewhere_else /usr/www/APACHE3/somewhere_else
...</pre>
<p>Stop Apache and run <tt>./go 2</tt>. From the browser, access  <span>http://www.butterthlies.com/somewhere_else/</span>. We  see the following:</p>
<pre>Index of /somewhere_else
. Parent Directory
. lost.txt</pre>
<p>If we click on <tt>Parent</tt> <tt>Directory</tt>, we arrive at  the <tt>DocumentRoot</tt> for this server,  <em>/usr/www/APACHE3/site.alias/htdocs/customers</em>, not, as might be expected,  at <em>/usr/www/APACHE3.</em> This is because <tt>Parent</tt> <tt>Directory</tt> really means &#8220;parent URL,&#8221; which is <span>http://www.butterthlies.com/</span> in this case.</p>
<p>What sometimes puzzles people (even those who know about it but  have temporarily forgotten) is that if you go to <span>http://www.butterthlies.com/</span> and there&#8217;s no ready-made  index, you don&#8217;t see <span>somewhere_else</span> listed.</p>
<h4>1 A Subtle Problem</h4>
<p>Note that you do not want to write:</p>
<pre>Alias /somewhere_else/ /usr/www/APACHE3/somewhere_else</pre>
<p>The trailing / on the alias will prevent things working. To  understand this, imagine that you start with a web server that has a  subdirectory called <em>fred</em> in its <tt>DocumentRoot</tt>. That is, there&#8217;s a  directory called <em>/www/docs/fred</em>, and the Config file says:</p>
<pre>DocumentRoot /www/docs</pre>
<p>The URL <span>http://your.webserver.com/fred</span> fails because there is  no file called <em>fred</em>. However, the request is redirected by Apache to  <span>http://your.webserver.com/fred/</span>, which is then  handled by looking for the directory index of <em>/fred</em>.</p>
<p>So, if you have a web page that says:</p>
<pre>&lt;a href="/fred"&gt;Take a look at fred&lt;/a&gt;</pre>
<p>it will work. When you click on &#8220;Take a look at fred,&#8221; you get  redirected, and your browser looks for:</p>
<pre> http://your.webserver.com/fred/</pre>
<p>as its URL, and all is well.</p>
<p>One day, you move <em>fred</em> to <em>/some/where/else</em>. You  alter your Config file:</p>
<pre>Alias /fred/ /some/where/else</pre>
<p>or, equally ill-advisedly:</p>
<pre>Alias /fred/ /some/where/else/</pre>
<p>You put the trailing / on the aliases because you wanted to  refer to a directory. But either will fail. Why?</p>
<p>The URL <span>http://your.webserver.com/fred</span> fails because there is  no file <em>/www/docs/fred</em> anymore. In spite of the altered line in the  Config file, this is what the URL still maps to, because <em>/fred</em> doesn&#8217;t  match <em>/fred/</em>, and Apache no longer has a reason to redirect.</p>
<p>But using this <tt>Alias</tt> (without the trailing / on the  alias):</p>
<pre>Alias /fred /some/where/else</pre>
<p>means that <span>http://your.webserver.com/fred</span> maps to  <em>/some/where/else</em> instead of <em>/www/docs/fred</em>. It is once more  recognized as a directory and is automatically redirected to the right place.</p>
<p>Note that it would be wrong to make Apache detect this and do  the redirect, because it is legitimate to actually have both a file called  <em>fred</em> in <em>/www/docs</em> and an alias for <em>/fred/</em> that sends  requests for <span>/fred/*</span> elsewhere.</p>
<p>It would also be wrong to make Apache bodge the URL and add a  trailing slash when it is clear that a directory is meant rather than a  filename. The reason is that if a file in that directory wants to refer visitors  to a subdirectory <em>&#8230;/fred/bill, </em>the new URL is made up by the browser.  It can only do this if it knows that <em>fred </em>is a directory, and the only  way it can get to know this is if Apache redirects the request for &#8230;<em>/fred </em>to <em>/fred/.</em></p>
<p>The same effect was produced on our system by leaving the  <tt>ServerName</tt> directive outside the <tt>VirtualHost</tt> block. This is  because, being outside the <tt>VirtualHost</tt> block, it doesn&#8217;t apply to the  virtual host. So the previously mentioned redirect doesn&#8217;t work because it uses  <tt>ServerName</tt> in autogenerated redirects. Presumably this would only cause  a problem depending on IPs, reverse DNS, and so forth.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>Script</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>Script method cgi-script
Server config, virtual host, directory
Script is only available in Apache 1.1 and later; arbitrary method use is only
available with 1.3.10 and later.</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>This directive adds an action, which will activate  <tt>cgi-script</tt> when a file is requested using the method of  <tt>method</tt>. It sends the URL and file path of the requested document using  the standard CGI PATH_INFO and PATH_TRANSLATED environment variables. This is  useful if you want to compress on the fly, for example, or implement PUT.</p>
<p>Prior to Apache 1.3.10, <tt>method</tt> can only be one of GET,  POST, PUT, or DELETE. As of 1.3.10, any arbitrary method name may be used.  Method names are case sensitive, so <tt>Script PUT</tt> and <tt>Script</tt> put  have two entirely different effects.</p>
<p>Note that the <tt>Script</tt> command defines default actions  only. If a CGI script is called, or some other resource that is capable of  handling the requested method internally, it will do so. Also note that  <tt>Script</tt> with a method of GET will only be called if there are query  arguments present (e.g., <em>foo.html?hi)</em>. Otherwise, the request will  proceed normally.</p>
<h4>Examples</h4>
<pre># For &lt;ISINDEX&gt;-style searching
Script GET /cgi-bin/search
# A CGI PUT handler
Script PUT /~bob/put.cgi</pre>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>ScriptAlias </strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>ScriptAlias <tt><em>url_path directory_or_filename </em></tt>
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p><tt>ScriptAlias</tt> allows scripts to be stored safely out of  the way of prying fingers and, moreover, automatically marks the directory where  they are stored as containing CGI scripts. For instance, see  <em>&#8230;site.cgi/conf/httpd0.conf</em>:</p>
<pre>...
ScriptAlias /cgi-bin/ /usr/www/apache3/cgi-bin/
...</pre>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>ScriptAliasMatch</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>ScriptAliasMatch <tt><em>regex directory_or_filename </em></tt>
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>The supplied regular expression is matched against the URL; if  it matches, the server will substitute any parenthesized matches into the given  string and use them as a filename. For example, to activate the standard  <em>/cgi-bin</em>, one might use:</p>
<pre>ScriptAliasMatch ^/cgi-bin/(.*) /usr/local/apache/cgi-bin/$1</pre>
<p><tt>.*</tt> is a regular expression like those in Perl that  match any character (.) any number of times (*). Here, this will be the name of  the file we want to execute. Putting it in parentheses <tt>(.*)</tt> stores the  characters in the variable <tt>$1</tt>, which is then invoked:</p>
<pre>/usr/local/apache/cgi-bin/$1.</pre>
<p>You can start the matching further along. If all your script  filenames start with the letters &#8220;BT,&#8221; you could write:</p>
<pre>ScriptAliasMatch ^/cgi-bin/BT(.*) /usr/local/apache/cgi-bin/BT$1</pre>
<p>If the visitor got here by following a link on the web  page:</p>
<pre>...&lt;a href="/cgi-bin/BTmyscript/customer56/ice_cream"&gt;...</pre>
<p><tt>ScriptAliasMatch</tt> will run <tt>BTmyscript</tt><em>. </em>If it accesses the environment variable <tt>PATH_INFO<em> ,</em></tt> it will find  <tt>/customer56/ice_cream</tt>.</p>
<p>You can have as many of these useful directives as you like in  your Config file to cover different situations. For more information on regular  expressions, see Mastering Regular Expressions by Jeffrey Friedl (O&#8217;Reilly,  2002) or Programming Perl by Larry Wall, Jon Orwant, and Tom Christiansen  (O&#8217;Reilly, 2001).</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>ScriptInterpreterSource</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>ScriptInterpreterSource registry|script
Default: ScriptInterpreterSource script
directory, .htaccess</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p><img src="win32.gif" border="0" alt="figs/win32.gif" width="24" height="11" /></p>
<p>This directive is used to control how Apache 1.3.5 and later  finds the interpreter used to run CGI scripts. The default technique is to use  the interpreter pointed to by the <tt>#!</tt> line in the script. Setting the  <tt>ScriptInterpreterSource</tt> registry will cause the Windows registry to be  searched using the script file extension (e.g., <em>.pl</em>) as a search key.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>Alias</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>Alias <tt><em>url_path directory_or_filename</em></tt>
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p><tt>Alias</tt> is used to map a resource&#8217;s URL to its physical  location in the filesystem, regardless of where it is relative to the document  root. For instance, see <em>&#8230;/site.alias/conf/httpd.conf</em>:</p>
<pre>...
Alias /somewhere_else/ /usr/www/APACHE3/somewhere_else/
...</pre>
<p>There is a directory <em>/usr/www/APACHE3/somewhere_else/, </em>which contains a file <em>lost.txt. </em>If we navigate to<em> www.butterthlies.com/somewhere_else</em>, we see:</p>
<pre>Index of /somewhere_else
    Parent Directory
    lost.txt</pre>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>AliasMatch</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>AliasMatch <tt><em>regex directory_or_filename</em></tt>
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>Again, like <tt>ScriptAliasMatch</tt>, this directive takes a  regular expression as the first argument. Otherwise, it is the same as  <tt>Alias</tt>.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>UserDir</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>UserDir <tt><em>directory</em></tt>
Default: UserDir <tt><em>public_html</em></tt>
Server config, virtual host</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>The basic idea here is that the client is asking for data from  a user&#8217;s home directory. He asks for <span>http://www.butterthlies.com/~peter,</span> which means  &#8220;Peter&#8217;s home directory on the computer whose DNS name is <span>www.butterthlies.com.</span>&#8221; The <tt>UserDir</tt> directive  sets the real directory in a user&#8217;s home directory to use when a request for a  document is received from a user. <tt><em>directory</em></tt> is one of the  following:</p>
<ul>
<li>The name of a directory or a pattern such as those shown in the  examples that follow.</li>
<li>The keyword <tt>disabled</tt>. This turns off all  username-to-directory translations except those explicitly named with the  <tt>enabled</tt> keyword.</li>
<li>The keyword <tt>disabled</tt> followed by a space-delimited  list of usernames. Usernames that appear in such a list will never have  directory translation performed, even if they appear in an <tt>enabled</tt> clause.</li>
<li>The keyword <tt>enabled</tt> followed by a space-delimited list  of usernames. These usernames will have directory translation performed even if  a global disable is in effect, but not if they also appear in a  <tt>disabled</tt> clause.</li>
</ul>
<p>If neither the <tt>enabled</tt> nor the <tt>disabled</tt> keyword appears in the <tt>UserDir</tt> directive, the argument is treated as a  filename pattern and is used to turn the name into a directory specification. A  request for <span>http://www.foo.com/~bob/one/two.html</span> will be translated as follows:</p>
<pre>UserDir <tt><em>public_html</em></tt>     -&gt; <tt><em>~bob/public_html/one/two.html</em></tt>
UserDir <tt><em>/usr/web </em></tt>       -&gt; <tt><em>/usr/web/bob/one/two.html</em></tt>
UserDir <tt><em>/home/*/www/APACHE3 </em></tt>    -&gt; <tt><em>/home/bob/www/APACHE3/one/two.html</em></tt></pre>
<p>The following directives will send the redirects shown to their  right to the client:</p>
<pre>UserDir <tt><em>http://www.foo.com/users</em></tt> -&gt; <tt><em>http://www.foo.com/users/bob/one/two.html</em></tt>
UserDir <tt><em>http://www.foo.com/*/usr</em></tt> -&gt; <tt><em>http://www.foo.com/bob/usr/one/two.html</em></tt>
UserDir <tt><em>http://www.foo.com/~*/ </em></tt>  -&gt; <tt><em>http://www.foo.com/~bob/one/two.html</em></tt></pre>
<p>Be careful when using this directive; for instance,  <tt>UserDir</tt> <tt>./</tt> would map <em>/~root</em> to /, which is probably  undesirable. If you are running Apache 1.3 or above, it is strongly recommended  that your configuration include a <tt>UserDir</tt> <tt>disabled</tt> <tt>root</tt> declaration.</p>
<p><img src="win32.gif" border="0" alt="figs/win32.gif" width="24" height="11" /></p>
<p>Under Win32, Apache does not understand home directories, so  translations that end up in home directories on the righthand side (see the  first example) will not work.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>Redirect</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>Redirect [status] url-path url
Server config, virtual host, directory, .htaccess</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>The <tt>Redirect</tt> directive maps an old URL into a new one.  The new URL is returned to the client, which attempts to fetch the information  again from the new address. <tt>url-path</tt> is a (%-decoded) path; any  requests for documents beginning with this path will be returned a redirect  error to a new (%-encoded) URL beginning with <tt>url</tt>.</p>
<h4>Example</h4>
<pre>Redirect /service http://foo2.bar.com/service</pre>
<p>If the client requests <span>http://myserver/service/foo.txt</span>, it will be told to  access <span>http://foo2.bar.com/service/foo.txt</span> instead.</p>
<p>If no <tt>status</tt> argument is given, the redirect will be  &#8220;temporary&#8221; (HTTP status 302). This indicates to the client that the resource  has moved temporarily. The <tt>status</tt> argument can be used to return other  HTTP status codes:</p>
<dl>
<dt><span><span>permanent</span> </span> </dt>
<dd>Returns a permanent redirect status (301) indicating that the  resource has moved permanently.</p>
</dd>
<dt><span><span>temp</span> </span> </dt>
<dd>Returns a temporary redirect status (302). This is the default.</p>
</dd>
<dt><span><span>seeother</span> </span> </dt>
<dd>Returns a &#8220;See Other&#8221; status (303) indicating that the resource  has been replaced.</p>
</dd>
<dt><span><span>gone</span> </span> </dt>
<dd>Returns a &#8220;Gone&#8221; status (410) indicating that the resource has  been permanently removed. When this status is used, the <tt>url</tt> argument  should be omitted.</p>
</dd>
</dl>
<p>Other status codes can be returned by giving the numeric status  code as the value of <tt>status</tt>. If the status is between 300 and 399, the  <tt>url</tt> argument must be present, otherwise it must be omitted. Note that  the status must be known to the Apache code (see the function  <em>send_error_response</em> in <em>http_protocol.c</em>).</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>RedirectMatch</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>RedirectMatch <tt><em>regex url</em></tt>
Server config, virtual host, directory, .htaccess</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>Again, <tt>RedirectMatch</tt> works like <tt>Redirect</tt>,  except that it takes a regular expression (discussed earlier under  <tt>ScriptAliasMatch</tt>) as its first argument.</p>
<p>In the Butterthlies business, sad to relate, the salespeople  have been abusing their powers and perquisites, and it has been decided to teach  them a lesson by hiding their beloved <em>secrets</em> file and sending them to  the ordinary customers&#8217; site when they try to access it. How humiliating! Easily  done, though.</p>
<p>The Config file is <em>httpd3.conf </em>:</p>
<pre>...
&lt;VirtualHost sales.butterthlies.com&gt;
ServerAdmin sales_mgr@butterthlies.com
Redirect /secrets http://www.butterthlies.com
DocumentRoot /usr/www/APACHE3/site.alias/htdocs/salesmen
...</pre>
<p>The exact placing of the <tt>Redirect</tt> doesn&#8217;t matter, as  long as it is somewhere in the <tt>&lt;VirtualHost&gt;</tt> section. If you now  access <span>http://sales.butterthlies.com/secrets</span>, you  are shunted straight to the customers&#8217; index at <span>http://www.butterthlies.com /</span>.</p>
<p>It is somewhat puzzling that if the <tt>Redirect</tt> line  fails to work because you have misspelled the URL, there may be nothing in the  <em>error_log</em> because the browser is vainly trying to find it out on the Web.</p>
<p>An important difference between <tt>Alias</tt> and  <tt>Redirect</tt> is that the browser becomes aware of the new location in a  <tt>Redirect</tt>, but not in an <tt>Alias</tt>, and this new location will be  used as the basis for relative hot links found in the retrieved HTML.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>RedirectTemp</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>RedirectTemp url-path url
Server config, virtual host, directory, .htaccess</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>This directive makes the client know that the <tt>Redirect</tt> is only temporary (status 302). This is exactly equivalent to <tt>Redirect  temp</tt>.</p>
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left"><strong>RedirectPermanent</strong></td>
<td align="right"></td>
</tr>
</tbody>
</table>
<hr size="3" noshade="noshade" />
<table border="0" cellpadding="5" width="515">
<tbody>
<tr>
<td align="left">
<pre>RedirectPermanent url-path url
Server config, virtual host, directory, .htaccess</pre>
</td>
<td align="right"></td>
</tr>
</tbody>
</table>
<p>This directive makes the client know that the <tt>Redirect</tt> is permanent (status 301). This is exactly equivalent to <tt>Redirect  permanent.</tt></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/apache234.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/apache234.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/apache234.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/apache234.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/apache234.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/apache234.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/apache234.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/apache234.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/apache234.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/apache234.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/apache234.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/apache234.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/apache234.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/apache234.wordpress.com/63/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=apache234.wordpress.com&amp;blog=8348681&amp;post=63&amp;subd=apache234&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://apache234.wordpress.com/2009/06/27/alias/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/362f6b0de20f8ab4fa364d41b94609b4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">apache234</media:title>
		</media:content>

		<media:content url="win32.gif" medium="image">
			<media:title type="html">figs/win32.gif</media:title>
		</media:content>

		<media:content url="win32.gif" medium="image">
			<media:title type="html">figs/win32.gif</media:title>
		</media:content>
	</item>
		<item>
		<title>Redirection</title>
		<link>http://apache234.wordpress.com/2009/06/27/redirection/</link>
		<comments>http://apache234.wordpress.com/2009/06/27/redirection/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 16:51:40 +0000</pubDate>
		<dc:creator>apache234</dc:creator>
				<category><![CDATA[Redirection]]></category>

		<guid isPermaLink="false">http://apache234.wordpress.com/2009/06/27/redirection/</guid>
		<description><![CDATA[Few things are ever in exactly the right place at the right time, and this is as true of most web servers as of anything else. Alias and Redirect allow requests to be shunted about your filesystem or around the Web. Although in a perfect world it should never be necessary to do this, in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=apache234.wordpress.com&amp;blog=8348681&amp;post=62&amp;subd=apache234&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Few things are ever in exactly the right place at the right  time, and this is as true of most web servers as of anything else.  <tt>Alias</tt> and <tt>Redirect</tt> allow requests to be shunted about your  filesystem or around the Web. Although in a perfect world it should never be  necessary to do this, in practice it is often useful to move HTML files around  on the server — or even to a different server — without having to change all the  links in the HTML document.<span><a href="#EN8-1"><sup>[1]</sup></a></span> A more legitimate use — of  <tt>Alias</tt>, at least — is to rationalize directories spread around the  system. For example, they may be maintained by different users and may even be  held on remotely mounted filesystems. But <tt>Alias</tt> can make them appear to  be grouped in a more logical way.</p>
<p>A related directive, <tt>ScriptAlias</tt>, allows you to run  CGI scripts, discussed in <a href="_chapter%2016.htm">Chapter  16</a>. You have a choice: everything that <tt>ScriptAlias</tt> does, and much  more, can be done by the new <tt>Rewrite</tt> directive (described later in this  chapter), but at a cost of some real programming effort. <tt>ScriptAlias</tt> is  relatively simple to use, but it is also a good example of Apache&#8217;s modularity  being a little less modular than we might like. Although <tt>ScriptAlias</tt> is  defined in <em>mod_alias.c </em>in the Apache source code, it needs <em>mod_cgi.c </em>(or any module that does CGI) to function — it does, after all, run CGI  scripts. <em>mod_alias.c</em> is compiled into Apache by default.</p>
<p>Some care is necessary in arranging the order of all these  directives in the Config file. Generally, the narrower choices should come  first, with the &#8220;catch-all&#8221; versions at the bottom. Be prepared to move them  around (restarting Apache each time, of course) until you get the effect you  want.</p>
<p>Our base <em>httpd1.conf</em> file on &#8230; /<em>site.alias</em>, to  which we will add some directives, contains the following:</p>
<pre>User webuser
Group webgroup

NameVirtualHost 192.168.123.2

&lt;VirtualHost www.butterthlies.com&gt;
ServerName www.butterthlies.com
DocumentRoot /usr/www/APACHE3/site.alias/htdocs/customers
ErrorLog /usr/www/APACHE3/site.alias/logs/error_log
TransferLog /usr/www/APACHE3/site.alias/logs/access_log
&lt;/VirtualHost&gt;

&lt;VirtualHost sales.butterthlies.com&gt;
DocumentRoot /usr/www/APACHE3/site.alias/htdocs/salesmen
ServerName sales.butterthlies.com
ErrorLog /usr/www/APACHE3/site.alias/logs/error_log
TransferLog /usr/www/APACHE3/site.alias/logs/access_log
&lt;/VirtualHost&gt;</pre>
<p>Start it with <tt>./go 1</tt>. It should work as you would  expect, showing you the customers&#8217; and salespeople&#8217;s directories.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/apache234.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/apache234.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/apache234.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/apache234.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/apache234.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/apache234.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/apache234.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/apache234.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/apache234.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/apache234.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/apache234.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/apache234.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/apache234.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/apache234.wordpress.com/62/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=apache234.wordpress.com&amp;blog=8348681&amp;post=62&amp;subd=apache234&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://apache234.wordpress.com/2009/06/27/redirection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/362f6b0de20f8ab4fa364d41b94609b4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">apache234</media:title>
		</media:content>
	</item>
	</channel>
</rss>
