<section id="sampleconf"><title>Sample Configuration</title>
<example><title>Adding an output filter </title>
- # In the following example, the sed filter will change the string<br />
- # "monday" to "MON" and the string "sunday" to SUN in html documents<br />
- # before sending to the client.<br />
- <indent>
- <Directory "/var/www/docs/sed"> <br />
- <indent>
- AddOutputFilter Sed html <br />
- OutputSed "s/monday/MON/g" <br />
- OutputSed "s/sunday/SUN/g" <br />
- </indent>
- </Directory> <br />
- </indent>
+ <highlight language="config">
+# In the following example, the sed filter will change the string
+# "monday" to "MON" and the string "sunday" to SUN in html documents
+# before sending to the client.
+<Directory "/var/www/docs/sed">
+ AddOutputFilter Sed html
+ OutputSed "s/monday/MON/g"
+ OutputSed "s/sunday/SUN/g"
+</Directory>
+ </highlight>
</example>
<example><title>Adding an input filter </title>
- # In the following example, the sed filter will change the string<br />
- # "monday" to "MON" and the string "sunday" to SUN in the POST data<br />
- # sent to PHP.<br />
- <indent>
- <Directory "/var/www/docs/sed"> <br />
- <indent>
- AddInputFilter Sed php <br />
- InputSed "s/monday/MON/g" <br />
- InputSed "s/sunday/SUN/g" <br />
- </indent>
- </Directory> <br />
- </indent>
+ <highlight language="config">
+# In the following example, the sed filter will change the string
+# "monday" to "MON" and the string "sunday" to SUN in the POST data
+# sent to PHP.
+<Directory "/var/www/docs/sed">
+ AddInputFilter Sed php
+ InputSed "s/monday/MON/g"
+ InputSed "s/sunday/SUN/g"
+</Directory>
+ </highlight>
</example>
</section>
<section id="sed_commands"><title>Sed Commands</title>
stored on the browser, in a cookie called <code>session</code>.</p>
<example><title>Browser based session</title>
- Session On<br />
- SessionCookieName session path=/<br />
+ <highlight language="config">
+Session On
+SessionCookieName session path=/
+ </highlight>
</example>
<p>The session is not useful unless it can be written to or read from. The
<code>X-Replace-Session</code>.</p>
<example><title>Writing to a session</title>
- Session On<br />
- SessionCookieName session path=/<br />
- SessionHeader X-Replace-Session<br />
+ <highlight language="config">
+Session On
+SessionCookieName session path=/
+SessionHeader X-Replace-Session
+ </highlight>
</example>
<p>The header should contain name value pairs expressed in the same format
empty string has the effect of removing that key from the session.</p>
<example><title>CGI to write to a session</title>
- #!/bin/bash<br />
- echo "Content-Type: text/plain"<br />
- echo "X-Replace-Session: key1=foo&key2=&key3=bar"<br />
- echo<br />
- env<br />
+ <highlight language="sh">
+#!/bin/bash
+echo "Content-Type: text/plain"
+echo "X-Replace-Session: key1=foo&key2=&key3=bar"
+echo
+env
+ </highlight>
</example>
<p>If configured, the session can be read back from the HTTP_SESSION
<directive module="mod_session">SessionEnv</directive> directive.</p>
<example><title>Read from a session</title>
- Session On<br />
- SessionEnv On<br />
- SessionCookieName session path=/<br />
- SessionHeader X-Replace-Session<br />
+ <highlight language="config">
+Session On
+SessionEnv On
+SessionCookieName session path=/
+SessionHeader X-Replace-Session
+ </highlight>
</example>
<p>Once read, the CGI variable <code>HTTP_SESSION</code> should contain
module.</p>
<example><title>Browser based encrypted session</title>
- Session On<br />
- SessionCryptoPassphrase secret<br />
- SessionCookieName session path=/<br />
+ <highlight language="config">
+Session On
+SessionCryptoPassphrase secret
+SessionCookieName session path=/
+ </highlight>
</example>
<p>The session will be automatically decrypted on load, and encrypted on
as in the example below.</p>
<example><title>Setting cookie parameters</title>
- Session On<br />
- SessionCryptoPassphrase secret<br />
- SessionCookieName session path=/private;domain=example.com;httponly;secure;<br />
+ <highlight language="config">
+Session On
+SessionCryptoPassphrase secret
+SessionCookieName session path=/private;domain=example.com;httponly;secure;
+ </highlight>
</example>
<p>In cases where the Apache server forms the frontend for backend origin servers,
the session.</p>
<example><title>Form based authentication</title>
- Session On<br />
- SessionCryptoPassphrase secret<br />
- SessionCookieName session path=/<br />
- AuthFormProvider file<br />
- AuthUserFile conf/passwd<br />
- AuthType form<br />
- AuthName realm<br />
- ...<br />
+ <highlight language="config">
+Session On
+SessionCryptoPassphrase secret
+SessionCookieName session path=/
+AuthFormProvider file
+AuthUserFile conf/passwd
+AuthType form
+AuthName realm
+#...
+ </highlight>
</example>
<p>See the <module>mod_auth_form</module> module for documentation and complete
<var>session</var>, configure the session as follows:</p>
<example><title>Browser based session</title>
- Session On<br />
- SessionCookieName session path=/<br />
+ <highlight language="config">
+Session On
+SessionCookieName session path=/
+ </highlight>
</example>
<p>For more examples on how the session can be configured to be read
</p>
<example><title>Cookie with attributes</title>
- Session On<br />
- SessionCookieName session path=/private;domain=example.com;httponly;secure;version=1;<br />
+ <highlight language="config">
+Session On
+SessionCookieName session path=/private;domain=example.com;httponly;secure;version=1;
+ </highlight>
</example>
</usage>
</p>
<example><title>Cookie2 with attributes</title>
- Session On<br />
- SessionCookieName2 session path=/private;domain=example.com;httponly;secure;version=1;<br />
+ <highlight language="config">
+Session On
+SessionCookieName2 session path=/private;domain=example.com;httponly;secure;version=1;
+ </highlight>
</example>
</usage>
<var>session</var>, configure the session as follows:</p>
<example><title>Browser based encrypted session</title>
- Session On<br />
- SessionCookieName session path=/<br />
- SessionCryptoPassphrase secret
+ <highlight language="config">
+Session On
+SessionCookieName session path=/
+SessionCryptoPassphrase secret
+ </highlight>
</example>
<p>The session will be encrypted with the given key. Different servers can
which are specified as parameters with optional values after the driver name.</p>
<example><title>NSS without a certificate database</title>
+ <highlight language="config">
SessionCryptoDriver nss
+ </highlight>
</example>
<example><title>NSS with certificate database</title>
+ <highlight language="config">
SessionCryptoDriver nss dir=certs
+ </highlight>
</example>
<example><title>NSS with certificate database and parameters</title>
+ <highlight language="config">
SessionCryptoDriver nss dir=certs key3=key3.db cert7=cert7.db secmod=secmod
+ </highlight>
</example>
<example><title>NSS with paths containing spaces</title>
+ <highlight language="config">
SessionCryptoDriver nss "dir=My Certs" key3=key3.db cert7=cert7.db secmod=secmod
+ </highlight>
</example>
<p>The <var>NSS</var> crypto driver might have already been configured by another
To avoid this warning, use the noinit parameter as follows.</p>
<example><title>NSS with certificate database</title>
+ <highlight language="config">
SessionCryptoDriver nss noinit
+ </highlight>
</example>
<p>To prevent confusion, ensure that all modules requiring NSS are configured with
the engine to be used for encryption.</p>
<example><title>OpenSSL with engine support</title>
+ <highlight language="config">
SessionCryptoDriver openssl engine=name
+ </highlight>
</example>
</usage>
session. These queries are configured as per the example below.</p>
<example><title>Sample DBD configuration</title>
- DBDriver pgsql<br />
- DBDParams "dbname=apachesession user=apache password=xxxxx host=localhost"<br />
- DBDPrepareSQL "delete from session where key = %s" deletesession<br />
- DBDPrepareSQL "update session set value = %s, expiry = %lld where key = %s" updatesession<br />
- DBDPrepareSQL "insert into session (value, expiry, key) values (%s, %lld, %s)" insertsession<br />
- DBDPrepareSQL "select value from session where key = %s and (expiry = 0 or expiry > %lld)" selectsession<br />
- DBDPrepareSQL "delete from session where expiry != 0 and expiry < %lld" cleansession<br />
+ <highlight language="config">
+DBDriver pgsql
+DBDParams "dbname=apachesession user=apache password=xxxxx host=localhost"
+DBDPrepareSQL "delete from session where key = %s" deletesession
+DBDPrepareSQL "update session set value = %s, expiry = %lld where key = %s" updatesession
+DBDPrepareSQL "insert into session (value, expiry, key) values (%s, %lld, %s)" insertsession
+DBDPrepareSQL "select value from session where key = %s and (expiry = 0 or expiry > %lld)" selectsession
+DBDPrepareSQL "delete from session where expiry != 0 and expiry < %lld" cleansession
+ </highlight>
</example>
</section>
called <var>session</var>, configure the session as follows:</p>
<example><title>SQL based anonymous session</title>
- Session On<br />
- SessionDBDCookieName session path=/<br />
+ <highlight language="config">
+Session On
+SessionDBDCookieName session path=/
+ </highlight>
</example>
<p>For more examples on how the session can be configured to be read
userid, configure the session as follows:</p>
<example><title>SQL based per user session</title>
- Session On<br />
- SessionDBDPerUser On<br />
+ <highlight language="config">
+Session On
+SessionDBDPerUser On
+ </highlight>
</example>
</section>
</p>
<example><title>Cookie with attributes</title>
- Session On<br />
- SessionDBDCookieName session path=/private;domain=example.com;httponly;secure;version=1;<br />
+ <highlight language="config">
+Session On
+SessionDBDCookieName session path=/private;domain=example.com;httponly;secure;version=1;
+ </highlight>
</example>
</usage>
</p>
<example><title>Cookie2 with attributes</title>
- Session On<br />
- SessionDBDCookieName2 session path=/private;domain=example.com;httponly;secure;version=1;<br />
+ <highlight language="config">
+Session On
+SessionDBDCookieName2 session path=/private;domain=example.com;httponly;secure;version=1;
+ </highlight>
</example>
</usage>
such as this example, which sets <code>netscape</code> if the
browser is mozilla but not MSIE.</p>
-<example>
- BrowserMatch ^Mozilla netscape<br />
- BrowserMatch MSIE !netscape<br />
-</example>
+<highlight language="config">
+BrowserMatch ^Mozilla netscape
+BrowserMatch MSIE !netscape
+</highlight>
</summary>
<seealso><a href="../env.html">Environment Variables in Apache HTTP Server</a></seealso>
sets environment variables conditional on the
<code>User-Agent</code> HTTP request header. The following two
lines have the same effect:</p>
-<example>
- BrowserMatchNoCase Robot is_a_robot<br />
- SetEnvIfNoCase User-Agent Robot is_a_robot<br />
-</example>
+<highlight language="config">
+BrowserMatchNoCase Robot is_a_robot
+SetEnvIfNoCase User-Agent Robot is_a_robot
+</highlight>
<p>Some additional examples:</p>
-<example>
- BrowserMatch ^Mozilla forms jpeg=yes browser=netscape<br />
- BrowserMatch "^Mozilla/[2-3]" tables agif frames javascript<br />
- BrowserMatch MSIE !javascript<br />
-</example>
+<highlight language="config">
+BrowserMatch ^Mozilla forms jpeg=yes browser=netscape
+BrowserMatch "^Mozilla/[2-3]" tables agif frames javascript
+BrowserMatch MSIE !javascript
+</highlight>
</usage>
</directivesynopsis>
module="mod_setenvif">BrowserMatch</directive> directive.
However, it provides for case-insensitive matching. For
example:</p>
-<example>
- BrowserMatchNoCase mac platform=macintosh<br />
- BrowserMatchNoCase win platform=windows<br />
-</example>
+<highlight language="config">
+BrowserMatchNoCase mac platform=macintosh
+BrowserMatchNoCase win platform=windows
+</highlight>
<p>The <directive>BrowserMatch</directive> and
<directive>BrowserMatchNoCase</directive> directives are special cases of
the <directive module="mod_setenvif">SetEnvIf</directive> and <directive
module="mod_setenvif">SetEnvIfNoCase</directive>
directives. The following two lines have the same effect:</p>
-<example>
- BrowserMatchNoCase Robot is_a_robot<br />
- SetEnvIfNoCase User-Agent Robot is_a_robot<br />
-</example>
+<highlight language="config">
+BrowserMatchNoCase Robot is_a_robot
+SetEnvIfNoCase User-Agent Robot is_a_robot
+</highlight>
</usage>
</directivesynopsis>
<var>value</var> and replace them by parenthesized subexpressions
of <var>regex</var>.</p>
-<example>
-<title>Example:</title>
- SetEnvIf Request_URI "\.gif$" object_is_image=gif<br />
- SetEnvIf Request_URI "\.jpg$" object_is_image=jpg<br />
- SetEnvIf Request_URI "\.xbm$" object_is_image=xbm<br />
- :<br />
- SetEnvIf Referer www\.mydomain\.example\.com intra_site_referral<br />
- :<br />
- SetEnvIf object_is_image xbm XBIT_PROCESSING=1<br />
- :<br />
- SetEnvIf ^TS ^[a-z] HAVE_TS<br />
-</example>
+<highlight language="config">
+SetEnvIf Request_URI "\.gif$" object_is_image=gif
+SetEnvIf Request_URI "\.jpg$" object_is_image=jpg
+SetEnvIf Request_URI "\.xbm$" object_is_image=xbm
+
+SetEnvIf Referer www\.mydomain\.example\.com intra_site_referral
+
+SetEnvIf object_is_image xbm XBIT_PROCESSING=1
+
+SetEnvIf ^TS ^[a-z] HAVE_TS
+</highlight>
<p>The first three will set the environment variable
<code>object_is_image</code> if the request was for an image
and applied <em>env-variable</em> in the same fashion as <directive
>SetEnvIf</directive>.</p>
-<example>
+<highlight language="config">
SetEnvIfExpr "tolower(req('X-Sendfile')) == 'd:\images\very_big.iso')" iso_delivered
-</example>
+</highlight>
<p>This would set the environment variable <code>iso_delivered</code>
every time our application attempts to send it via <code>X-Sendfile</code></p>
<p>A more useful example would be to set the variable rfc1918 if the
remote IP address is a private address according to RFC 1918:</p>
-<example>
+<highlight language="config">
SetEnvIfExpr "-R '10.0.0.0/8' || -R '172.16.0.0/12' || -R '192.168.0.0/16'" rfc1918
-</example>
+</highlight>
</usage>
<seealso><a href="../expr.html">Expressions in Apache HTTP Server</a>,
the <directive module="mod_setenvif">SetEnvIf</directive> directive,
and differs only in that the regular expression matching is
performed in a case-insensitive manner. For example:</p>
-<example>
+<highlight language="config">
SetEnvIfNoCase Host Example\.Org site=example
-</example>
+</highlight>
<p>This will cause the <code>site</code> environment variable
to be set to "<code>example</code>" if the HTTP request header
<p>For example:</p>
- <example>LoadFile libexec/libxmlparse.so</example>
+ <highlight language="config">LoadFile libexec/libxmlparse.so</highlight>
</usage>
</directivesynopsis>
href="module-dict.html#ModuleIdentifier">Module Identifier</a>
in the module documentation. Example:</p>
- <example>
+ <highlight language="config">
LoadModule status_module modules/mod_status.so
- </example>
+ </highlight>
<p>loads the named module from the modules subdirectory of the
ServerRoot.</p>
<p>To enable status reports only for browsers from the example.com
domain add this code to your <code>httpd.conf</code>
configuration file</p>
-<example>
- <Location /server-status><br />
- <indent>
- SetHandler server-status<br />
-<br />
- Require host example.com<br />
- </indent>
- </Location>
-</example>
+<highlight language="config">
+<Location /server-status>
+ SetHandler server-status
+ Require host example.com
+</Location>
+</highlight>
<p>You can now access server statistics by using a Web browser
to access the page
</dl>
<example><title>Example</title>
- <Location />
- <indent>
- AddOutputFilterByType SUBSTITUTE text/html<br />
- Substitute s/foo/bar/ni<br />
- </indent>
- </Location>
+ <highlight language="config">
+<Location />
+ AddOutputFilterByType SUBSTITUTE text/html
+ Substitute s/foo/bar/ni
+</Location>
+ </highlight>
</example>
<p>If either the pattern or the substitution contain a slash
character then an alternative delimiter should be used:</p>
<example><title>Example of using an alternate delimiter</title>
- <Location />
- <indent>
- AddOutputFilterByType SUBSTITUTE text/html<br />
- Substitute "s|<BR */?>|<br />|i"
- </indent>
- </Location>
+ <highlight language="config">
+<Location />
+ AddOutputFilterByType SUBSTITUTE text/html
+ Substitute "s|<BR */?>|<br />|i"
+</Location>
+ </highlight>
</example>
<p>Backreferences can be used in the comparison and in the substitution,
when regular expressions are used, as illustrated in the following example: </p>
<example><title>Example of using backreferences and captures</title>
- <Location />
- <indent>
- AddOutputFilterByType SUBSTITUTE text/html<br />
- # "foo=k,bar=k" -> "foo/bar=k" <br />
- Substitute "s|foo=(\w+),bar=\1|foo/bar=$1"
- </indent>
- </Location>
+ <highlight language="config">
+<Location />
+ AddOutputFilterByType SUBSTITUTE text/html
+ # "foo=k,bar=k" -> "foo/bar=k"
+ Substitute "s|foo=(\w+),bar=\1|foo/bar=$1"
+</Location>
+ </highlight>
</example>
<p>A common use scenario for <code>mod_substitute</code> is the
those URLs into something that will work from the front end:</p>
<example><title>Rewriting URLs embedded in proxied content</title>
- ProxyPass /blog/ http://internal.blog.example.com<br />
- ProxyPassReverse /blog/ http://internal.blog.example.com/<br />
- <br />
- Substitute "s|http://internal.blog.example.com/|http://www.example.com/blog/|i"
+ <highlight language="config">
+ProxyPass /blog/ http://internal.blog.example.com
+ProxyPassReverse /blog/ http://internal.blog.example.com/
+
+Substitute "s|http://internal.blog.example.com/|http://www.example.com/blog/|i"
+ </highlight>
</example>
<p><directive module="mod_proxy">ProxyPassReverse</directive>
<example>
<title>Example</title>
+ <highlight language="config">
SuexecUserGroup nobody nogroup
+ </highlight>
</example>
<p>In Apache httpd 2.3.9 and later, startup will fail if this