<?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/"
	>

<channel>
	<title>AskApache &#187; Search Results  &#187;  firefox</title>
	<atom:link href="http://www.askapache.com/search/firefox/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.askapache.com</link>
	<description>Advanced Web Development</description>
	<lastBuildDate>Thu, 26 Apr 2012 11:29:28 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Mod_Rewrite Security</title>
		<link>http://www.askapache.com/security/mod_rewrite.html</link>
		<comments>http://www.askapache.com/security/mod_rewrite.html#comments</comments>
		<pubDate>Sat, 18 Feb 2012 06:54:18 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[RewriteCond]]></category>
		<category><![CDATA[RewriteRule]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=7045</guid>
		<description><![CDATA[<p><a class="hs hs13" href="http://www.askapache.com/security/mod_rewrite.html" title="Mod_Rewrite Artwork"></a>These are a few of the mod_rewrite uses that <a href="http://blogsecurity.net/">BlogSecurity</a> declared <strong>pushed the boundaries of Mod_Rewrite!</strong>  Some of these snippets are quite exotic and unlike anything you may have seen before, also only for those who understand them as they can kill a website pretty quick.<br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/security/mod_rewrite.html"></a><a href="http://www.askapache.com/security/mod_rewrite.html"><cite>AskApache.com</cite></a></p><p>Here are some <a href="http://www.askapache.com/htaccess/htaccess.html" title="Htaccess Tutorial">specific htaccess</a> examples taken mostly from my WordPress Password Protection plugin, which does alot more than password protection as you will see from the following mod_rewrite examples. These are a few of the mod_rewrite uses that <a href="http://blogsecurity.net/">BlogSecurity</a> declared <strong>pushed the boundaries of Mod_Rewrite!</strong>  Some of these snippets are quite exotic and unlike anything you may have seen before, also only for those who understand them as they can kill a website pretty quick.</p>

<h4>Directory Protection</h4>
<p>Enable the DirectoryIndex Protection, preventing directory index listings and defaulting. [<a href="/htaccess/htaccess.html">Disable</a>]</p>
<pre>
Options -Indexes
DirectoryIndex index.html index.php /index.php
</pre>

<h4>Password Protect wp-login.php</h4>
<p>Requires a valid user/pass to access the login page[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-401">401</a>]</p>
<pre>
&lt;Files wp-login.php&gt;
Order Deny,Allow
Deny from All
Satisfy Any
AuthName "Protected By AskApache"
AuthUserFile /home/askapache.com/.htpasswda1
AuthType Basic
Require valid-user
&lt;/Files&gt;
</pre>


<h4>Password Protect wp-admin</h4>
<p>Requires a valid user/pass to access any non-static (css, js, images) file in this directory.[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-401">401</a>]</p>
<pre>
Options -ExecCGI -Indexes +FollowSymLinks -Includes
DirectoryIndex index.php /index.php
Order Deny,Allow
Deny from All
Satisfy Any
AuthName "Protected By AskApache"
AuthUserFile /home/askapache.com/.htpasswda1
AuthType Basic
Require valid-user
&lt;FilesMatch "\.(ico|pdf|flv|jpg|jpeg|mp3|mpg|mp4|mov|wav|wmv|png|gif|swf|css|js)$"&gt;
Allow from All
&lt;/FilesMatch&gt;
&lt;FilesMatch "(async-upload)\.php$"&gt;
&lt;IfModule mod_security.c&gt;
SecFilterEngine Off
&lt;/IfModule&gt;
Allow from All
&lt;/FilesMatch&gt;
</pre>

<h4>Protect wp-content</h4>
<p>Denies any Direct request for files ending in .php with a 403 Forbidden.. May break plugins/themes [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-401">401</a>]</p>
<pre>
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /wp-content/.*$ [NC]
RewriteCond %{REQUEST_FILENAME} !^.+flexible-upload-wp25js.php$
RewriteCond %{REQUEST_FILENAME} ^.+\.(php|html|htm|txt)$
RewriteRule .* - [F,NS,L]
</pre>

<h4>Protect wp-includes</h4>
<p>Denies any Direct request for files ending in .php with a 403 Forbidden.. May break plugins/themes [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /wp-includes/.*$ [NC]
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ /wp-includes/js/.+/.+\ HTTP/ [NC]
RewriteCond %{REQUEST_FILENAME} ^.+\.php$
RewriteRule .* - [F,NS,L]
</pre>

<h4>Common Exploits</h4>
<p>Block common exploit requests with 403 Forbidden. These can help alot, may break some plugins. [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ ///.*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\?\=?(http|ftp|ssl|https):/.*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\?\?.*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.(asp|ini|dll).*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.(htpasswd|htaccess|aahtpasswd).*\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>Stop Hotlinking</h4>
<p>Denies any request for static files (images, css, etc) if referrer is not local site or empty. [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{HTTP_REFERER} !^http://www.askapache.com.*$ [NC]
RewriteRule \.(ico|pdf|flv|jpg|jpeg|mp3|mpg|mp4|mov|wav|wmv|png|gif|swf|css|js)$ - [F,NS,L]
</pre>

<h4>Safe Request Methods</h4>
<p>Denies any request not using <a href="http://www.askapache.com/online-tools/request-method-scanner/">GET,PROPFIND,POST,OPTIONS,PUT,HEAD</a>[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|POST|PROPFIND|OPTIONS|PUT)$ [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>Forbid Proxies</h4>
<p>Denies any POST Request using a Proxy Server. Can still access site, but not comment.  See <a href="http://perishablepress.com/press/2008/04/20/how-to-block-proxy-servers-via-htaccess/">Perishable Press</a> [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP:VIA}%{HTTP:FORWARDED}%{HTTP:USERAGENT_VIA}%{HTTP:X_FORWARDED_FOR}%{HTTP:PROXY_CONNECTION} !^$ [OR]
RewriteCond %{HTTP:XPROXY_CONNECTION}%{HTTP:HTTP_PC_REMOTE_ADDR}%{HTTP:HTTP_CLIENT_IP} !^$
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>Real wp-comments-post.php</h4>
<p>Denies any POST attempt made to a non-existing wp-comments-post.php[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*/wp-comments-post\.php.*\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>HTTP PROTOCOL</h4>
<p>Denies any badly formed HTTP PROTOCOL in the request, 0.9, 1.0, and 1.1 only[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ .+\ HTTP/(0\.9|1\.0|1\.1) [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>SPECIFY CHARACTERS</h4>
<p>Denies any request for a url containing characters other than "a-zA-Z0-9.+/-?=&amp;"  - REALLY helps but may break your site depending on your links. [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;amp;]+\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>BAD Content Length</h4>
<p>Denies any POST request that doesnt have a Content-Length Header[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP:Content-Length} ^$
RewriteCond %{REQUEST_URI} !^/(wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>BAD Content Type</h4>
<p>Denies any POST request with a content type other than application/x-www-form-urlencoded|multipart/form-data[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP:Content-Type} !^(application/x-www-form-urlencoded|multipart/form-data.*(boundary.*)?)$ [NC]
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>Missing HTTP_HOST</h4>
<p>Denies requests that dont contain a HTTP HOST Header.[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{HTTP_HOST} ^$
RewriteRule .* - [F,NS,L]
</pre>

<h4>Bogus Graphics Exploit</h4>
<p>Denies obvious exploit using bogus graphics[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{HTTP:Content-Disposition} \.php [NC]
RewriteCond %{HTTP:Content-Type} image/.+ [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>No UserAgent, Not POST</h4>
<p>Denies POST requests by blank user-agents.  May prevent a small number of visitors from POSTING. [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP_USER_AGENT} ^-?$
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>No Referer, No Comment</h4>
<p>Denies any comment attempt with a blank HTTP_REFERER field, highly indicative of spam.  May prevent some visitors from POSTING. [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*/wp-comments-post\.php.*\ HTTP/ [NC]
RewriteCond %{HTTP_REFERER} ^-?$
RewriteRule .* - [F,NS,L]
</pre>

<h4>Trackback Spam</h4>
<p>Denies obvious trackback spam.  See Holy Shmoly! [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP_USER_AGENT} ^.*(opera|mozilla|firefox|msie|safari).*$ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.+/trackback/?\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>Map all URIs except those corresponding to existing files to a handler</h4>
<pre>
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule . /script.php
</pre>

<h4>Map any request to a handler</h4>
<p>In the case where all URIs should be sent to the same place (including potentially requests for static content) the method to use depends on the type of the handler. For php scripts, use:
For other handlers such as php scripts, use:</p>
<pre>
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/script.php
RewriteRule .* /script.php
</pre>

<h4>And for CGI scripts:</h4>
<pre>
ScriptAliasMatch .* /var/www/script.cgi
</pre>

<h4>Map URIs corresponding to existing files to a handler instead</h4>
<pre>
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f
RewriteCond %{REQUEST_URI} !=/script.php
RewriteRule .* /script.php
</pre>
<p>If the existing files you wish to have handled by your script have a common set of file extensions distinct from that of the hander, you can bypass mod_rewrite and use instead mod_actions. Let's say you want all .html and .tpl files to be dealt with by your script:</p>
<pre>
Action foo-action /script.php
AddHandler foo-action html tpl
</pre>

<h4>Deny access if var=val contains the string foo.</h4>
<pre>
RewriteCond %{QUERY_STRING} foo
RewriteRule ^/url - [F]
</pre>

<h4>Removing the Query String</h4>
<pre>
RewriteRule ^/url /url?
</pre>

<h4>Adding to the Query String</h4>
<p>Keep the existing query string using the Query String Append flag, but add var=val to the end.</p>
<pre>
RewriteRule ^/url /url?var=val [QSA]
</pre>

<h4>Rewriting For Certain Query Strings</h4>
<p>Rewrite URLs like http://askapache.com/url1?var=val to http://askapache.com/url2?var=val but don't rewrite if val isn't present.</p>
<pre>
RewriteCond %{QUERY_STRING} val
RewriteRule ^/url1 /url2
</pre>

<h4>Modifying the Query String</h4>
<p>Change any single instance of val in the query string to other_val when accessing /path. Note that %1 and %2 are back-references to the matched part of the regular expression in the previous RewriteCond.</p>
<pre>
RewriteCond %{QUERY_STRING} ^(.*)val(.*)$
RewriteRule /path /path?%1other_val%2
</pre>
<hr class="C" />
<p><a href="http://www.askapache.com/security/mod_rewrite.html"></a><a href="http://www.askapache.com/security/mod_rewrite.html">Mod_Rewrite Security</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/security/mod_rewrite.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Raw HTTP Header Debugger</title>
		<link>http://www.askapache.com/online-tools/http-headers-tool</link>
		<comments>http://www.askapache.com/online-tools/http-headers-tool#comments</comments>
		<pubDate>Wed, 26 Oct 2011 15:14:08 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
		
		<guid isPermaLink="false">http://www.askapache.com/online-tools/http-headers-tool/</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/online-tools/http-headers-tool"></a><a href="http://www.askapache.com/online-tools/http-headers-tool"><cite>AskApache.com</cite></a></p><hr class="C" />
<h2>HTTP Headers</h2>
<table>
    <thead>
        <tr>
            <td><strong>HTTP Header Name</strong></td>
            <td><strong>Header Description</strong></td>
            <td><strong>Example HTTP Header</strong></td>
        </tr>
    </thead>
    <tr>
        <td>Accept</td>
        <td>Content-Types that are acceptable</td>
        <td><code>Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5</code></td>
    </tr>
    <tr>
        <td>Accept-Charset</td>
        <td>Character sets that are acceptable</td>
        <td><code>Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7</code></td>
    </tr>
    <tr>
        <td>Accept-Encoding</td>
        <td>Acceptable encodings</td>
        <td><code>Accept-Encoding: gzip,deflate</code></td>
    </tr>
    <tr>
        <td>Accept-Language</td>
        <td>Acceptable languages for response</td>
        <td><code>Accept-Language: en-us,en</code></td>
    </tr>
    <tr>
        <td>Accept-Ranges</td>
        <td>What partial content range types this server supports</td>
        <td><code>Accept-Ranges: bytes</code></td>
    </tr>
    <tr>
        <td>Age</td>
        <td>The age the object has been in a proxy cache in seconds</td>
        <td><code>Age: 7200</code></td>
    </tr>
    <tr>
        <td>Allow</td>
        <td>Valid actions for a specified resource. To be used for a 405 Method not allowed</td>
        <td><code>Allow: GET,HEAD,POST,OPTIONS,TRACE</code></td>
    </tr>
    <tr>
        <td>Authorization</td>
        <td>Authentication credentials for HTTP authentication</td>
        <td><code>Authorization: Basic UXNrYXBhggRfoopc5NteWFzcw==</code></td>
    </tr>
    <tr>
        <td>Cache-Control</td>
        <td>Controls how proxies may cache this object</td>
        <td><code>Cache-Control: max-age=7200, public</code></td>
    </tr>
    <tr>
        <td>Connection</td>
        <td>What type of connection the user-agent would prefer</td>
        <td><code>Connection: Keep-Alive</code></td>
    </tr>
    <tr>
        <td>Content-Encoding</td>
        <td>The type of encoding used on the data</td>
        <td><code>Content-Encoding: gzip</code></td>
    </tr>
    <tr>
        <td>Content-Language</td>
        <td>The language the content is in</td>
        <td><code>Content-Language: en-us</code></td>
    </tr>
    <tr>
        <td>Content-Length</td>
        <td>The length of the content in bytes</td>
        <td><code>Content-Length: 5356</code></td>
    </tr>
    <tr>
        <td>Content-Location</td>
        <td>An alternate location for the returned data</td>
        <td><code>Content-Location: /index.html</code></td>
    </tr>
    <tr>
        <td>Content-MD5</td>
        <td>An MD5 sum of the content of the response</td>
        <td><code>Content-MD5: 1167b9c13ad2b6d3694493fc47976c8</code></td>
    </tr>
    <tr>
        <td>Content-Range</td>
        <td>Where in a full body message this partial message belongs</td>
        <td><code>Content-Range: bytes 110-2034/2035</code></td>
    </tr>
    <tr>
        <td>Content-Type</td>
        <td>The mime type of this content</td>
        <td><code>Content-Type: text/html; charset=UTF-8</code></td>
    </tr>
    <tr>
        <td>Date</td>
        <td>The date and time that the message was sent</td>
        <td><code>Date: Sat, 05 Jan 2008 09:27:35 GMT</code></td>
    </tr>
    <tr>
        <td>Host</td>
        <td>The domain name of the server (for virtual hosting)</td>
        <td><code>Host: www.askapache.com</code></td>
    </tr>
    <tr>
        <td>If-Modified-Since</td>
        <td>Allows a 304 Not Modified to be returned</td>
        <td><code>If-Modified-Since: Sat, 05 Jan 2007 09:26:12 GMT</code></td>
    </tr>
    <tr>
        <td>Last-Modified</td>
        <td>The last modified date for the requested object</td>
        <td><code>Last-Modified: Sat, 05 Jan 2008 09:26:12 GMT</code></td>
    </tr>
    <tr>
        <td>Location</td>
        <td>Used in redirection</td>
        <td><code>Location: http://www.askapache.com/</code></td>
    </tr>
    <tr>
        <td>Server</td>
        <td>A name for the server</td>
        <td><code>Server: Apache/2.0.61 (Unix) PHP/4.4.7 mod_ssl/2.0.61 OpenSSL/0.9.7e mod_fastcgi/2.4.2 DAV/2 SVN/1.4.2</code></td>
    </tr>
    <tr>
        <td>User-Agent</td>
        <td>The user agent string of the user agent</td>
        <td><code>User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7</code></td>
    </tr>
</table>
<hr class="C" />


<address>part of <a rev='Section' href='http://www.w3.org/Protocols/rfc2616/rfc2616.html'>Hypertext Transfer Protocol -- HTTP/1.1</a><br />RFC 2616 Fielding, et al.</address>
<h2><a id='sec9'>9</a> Method Definitions</h2>
<p>The set of common methods for HTTP/1.1 is defined below. Although this set can be expanded, additional methods cannot be assumed to share the same semantics for separately extended clients and servers.</p>
<p>The Host request-header field (section <a rel='xref' href='http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.23'>14.23</a>) MUST accompany all HTTP/1.1 requests.</p>
<h3><a id='sec9.1'>9.1</a> Safe and Idempotent Methods</h3>
<h3><a id='sec9.1.1'>9.1.1</a> Safe Methods</h3>
<p>Implementors should be aware that the software represents the user in their interactions over the Internet, and should be careful to allow the user to be aware of any actions they might take which may have an unexpected significance to themselves or others.</p>
<p>In particular, the convention has been established that the GET and HEAD methods SHOULD NOT have the significance of taking an action other than retrieval. These methods ought to be considered "safe". This allows user agents to represent other methods, such as POST, PUT and DELETE, in a special way, so that the user is made aware of the fact that a possibly unsafe action is being requested.</p>
<p>Naturally, it is not possible to ensure that the server does not generate side-effects as a result of performing a GET request; in fact, some dynamic resources consider that a feature. The important distinction here is that the user did not request the side-effects, so therefore cannot be held accountable for them.</p>
<h3><a id='sec9.1.2'>9.1.2</a> Idempotent Methods</h3>
<p>Methods can also have the property of "idempotence" in that (aside from error or expiration issues) the side-effects of N > 0 identical requests is the same as for a single request. The methods GET, HEAD, PUT and DELETE share this property. Also, the methods OPTIONS and TRACE SHOULD NOT have side effects, and so are inherently idempotent.</p>
<p>However, it is possible that a sequence of several requests is non- idempotent, even if all of the methods executed in that sequence are idempotent. (A sequence is idempotent if a single execution of the entire sequence always yields a result that is not changed by a reexecution of all, or part, of that sequence.) For example, a sequence is non-idempotent if its result depends on a value that is later modified in the same sequence.</p>
<p>A sequence that never has side effects is idempotent, by definition (provided that no concurrent operations are being executed on the same set of resources).</p>
<h3><a id='sec9.2'>9.2</a> OPTIONS</h3>
<p>The OPTIONS method represents a request for information about the communication options available on the request/response chain identified by the Request-URI. This method allows the client to determine the options and/or requirements associated with a resource, or the capabilities of a server, without implying a resource action or initiating a resource retrieval.</p>
<p>Responses to this method are not cacheable.</p>
<p>If the OPTIONS request includes an entity-body (as indicated by the presence of Content-Length or Transfer-Encoding), then the media type MUST be indicated by a Content-Type field. Although this specification does not define any use for such a body, future extensions to HTTP might use the OPTIONS body to make more detailed queries on the server. A server that does not support such an extension MAY discard the request body.</p>
<p>If the Request-URI is an asterisk ("*"), the OPTIONS request is intended to apply to the server in general rather than to a specific resource. Since a server's communication options typically depend on the resource, the "*" request is only useful as a "ping" or "no-op" type of method; it does nothing beyond allowing the client to test the capabilities of the server. For example, this can be used to test a proxy for HTTP/1.1 compliance (or lack thereof).</p>
<p>If the Request-URI is not an asterisk, the OPTIONS request applies only to the options that are available when communicating with that resource.</p>
<p>A 200 response SHOULD include any header fields that indicate optional features implemented by the server and applicable to that resource (e.g., Allow), possibly including extensions not defined by this specification. The response body, if any, SHOULD also include information about the communication options. The format for such a</p>
<p>body is not defined by this specification, but might be defined by future extensions to HTTP. Content negotiation MAY be used to select the appropriate response format. If no response body is included, the response MUST include a Content-Length field with a field-value of "0".</p>
<p>The Max-Forwards request-header field MAY be used to target a specific proxy in the request chain. When a proxy receives an OPTIONS request on an absoluteURI for which request forwarding is permitted, the proxy MUST check for a Max-Forwards field. If the Max-Forwards field-value is zero ("0"), the proxy MUST NOT forward the message; instead, the proxy SHOULD respond with its own communication options. If the Max-Forwards field-value is an integer greater than zero, the proxy MUST decrement the field-value when it forwards the request. If no Max-Forwards field is present in the request, then the forwarded request MUST NOT include a Max-Forwards field.</p>
<h3><a id='sec9.3'>9.3</a> GET</h3>
<p>The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. If the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity in the response and not the source text of the process, unless that text happens to be the output of the process.</p>
<p>The semantics of the GET method change to a "conditional GET" if the request message includes an If-Modified-Since, If-Unmodified-Since, If-Match, If-None-Match, or If-Range header field. A conditional GET method requests that the entity be transferred only under the circumstances described by the conditional header field(s). The conditional GET method is intended to reduce unnecessary network usage by allowing cached entities to be refreshed without requiring multiple requests or transferring data already held by the client.</p>
<p>The semantics of the GET method change to a "partial GET" if the request message includes a Range header field. A partial GET requests that only part of the entity be transferred, as described in section <a rel='xref' href='http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35'>14.35</a>. The partial GET method is intended to reduce unnecessary network usage by allowing partially-retrieved entities to be completed without transferring data already held by the client.</p>
<p>The response to a GET request is cacheable if and only if it meets the requirements for HTTP caching described in section 13.</p>
<p>See section <a rel='xref' href='http://www.w3.org/Protocols/rfc2616/rfc2616-sec15.html#sec15.1.3'>15.1.3</a> for security considerations when used for forms.</p>
<h3><a id='sec9.4'>9.4</a> HEAD</h3>
<p>The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. The metainformation contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information sent in response to a GET request. This method can be used for obtaining metainformation about the entity implied by the request without transferring the entity-body itself. This method is often used for testing hypertext links for validity, accessibility, and recent modification.</p>
<p>The response to a HEAD request MAY be cacheable in the sense that the information contained in the response MAY be used to update a previously cached entity from that resource. If the new field values indicate that the cached entity differs from the current entity (as would be indicated by a change in Content-Length, Content-MD5, ETag or Last-Modified), then the cache MUST treat the cache entry as stale.</p>
<h3><a id='sec9.5'>9.5</a> POST</h3>
<p>The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line. POST is designed to allow a uniform method to cover the following functions:</p>
<pre>      - Annotation of existing resources; </pre>
<pre>      - Posting a message to a bulletin board, newsgroup, mailing list, or similar group of articles; </pre>
<pre>      - Providing a block of data, such as the result of submitting a form, to a data-handling process; </pre>
<pre>      - Extending a database through an append operation. </pre>
<p>The actual function performed by the POST method is determined by the server and is usually dependent on the Request-URI. The posted entity is subordinate to that URI in the same way that a file is subordinate to a directory containing it, a news article is subordinate to a newsgroup to which it is posted, or a record is subordinate to a database.</p>
<p>The action performed by the POST method might not result in a resource that can be identified by a URI. In this case, either 200 (OK) or 204 (No Content) is the appropriate response status, depending on whether or not the response includes an entity that describes the result.</p>
<p>If a resource has been created on the origin server, the response SHOULD be 201 (Created) and contain an entity which describes the status of the request and refers to the new resource, and a Location header (see section <a rel='xref' href='http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30'>14.30</a>).</p>
<p>Responses to this method are not cacheable, unless the response includes appropriate Cache-Control or Expires header fields. However, the 303 (See Other) response can be used to direct the user agent to retrieve a cacheable resource.</p>
<p>POST requests MUST obey the message transmission requirements set out in section 8.2.</p>
<p>See section <a rel='xref' href='http://www.w3.org/Protocols/rfc2616/rfc2616-sec15.html#sec15.1.3'>15.1.3</a> for security considerations.</p>
<h3><a id='sec9.6'>9.6</a> PUT</h3>
<p>The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. If the Request-URI does not point to an existing resource, and that URI is capable of being defined as a new resource by the requesting user agent, the origin server can create the resource with that URI. If a new resource is created, the origin server MUST inform the user agent via the 201 (Created) response. If an existing resource is modified, either the 200 (OK) or 204 (No Content) response codes SHOULD be sent to indicate successful completion of the request. If the resource could not be created or modified with the Request-URI, an appropriate error response SHOULD be given that reflects the nature of the problem. The recipient of the entity MUST NOT ignore any Content-* (e.g. Content-Range) headers that it does not understand or implement and MUST return a 501 (Not Implemented) response in such cases.</p>
<p>If the request passes through a cache and the Request-URI identifies one or more currently cached entities, those entries SHOULD be treated as stale. Responses to this method are not cacheable.</p>
<p>The fundamental difference between the POST and PUT requests is reflected in the different meaning of the Request-URI. The URI in a POST request identifies the resource that will handle the enclosed entity. That resource might be a data-accepting process, a gateway to some other protocol, or a separate entity that accepts annotations. In contrast, the URI in a PUT request identifies the entity enclosed with the request -- the user agent knows what URI is intended and the server MUST NOT attempt to apply the request to some other resource. If the server desires that the request be applied to a different URI,</p>
<p>it MUST send a 301 (Moved Permanently) response; the user agent MAY then make its own decision regarding whether or not to redirect the request.</p>
<p>A single resource MAY be identified by many different URIs. For example, an article might have a URI for identifying "the current version" which is separate from the URI identifying each particular version. In this case, a PUT request on a general URI might result in several other URIs being defined by the origin server.</p>
<p>HTTP/1.1 does not define how a PUT method affects the state of an origin server.</p>
<p>PUT requests MUST obey the message transmission requirements set out in section 8.2.</p>
<p>Unless otherwise specified for a particular entity-header, the entity-headers in the PUT request SHOULD be applied to the resource created or modified by the PUT.</p>
<h3><a id='sec9.7'>9.7</a> DELETE</h3>
<p>The DELETE method requests that the origin server delete the resource identified by the Request-URI. This method MAY be overridden by human intervention (or other means) on the origin server. The client cannot be guaranteed that the operation has been carried out, even if the status code returned from the origin server indicates that the action has been completed successfully. However, the server SHOULD NOT indicate success unless, at the time the response is given, it intends to delete the resource or move it to an inaccessible location.</p>
<p>A successful response SHOULD be 200 (OK) if the response includes an entity describing the status, 202 (Accepted) if the action has not yet been enacted, or 204 (No Content) if the action has been enacted but the response does not include an entity.</p>
<p>If the request passes through a cache and the Request-URI identifies one or more currently cached entities, those entries SHOULD be treated as stale. Responses to this method are not cacheable.</p>
<h3><a id='sec9.8'>9.8</a> TRACE</h3>
<p>The TRACE method is used to invoke a remote, application-layer loop- back of the request message. The final recipient of the request SHOULD reflect the message received back to the client as the entity-body of a 200 (OK) response. The final recipient is either the</p>
<p>origin server or the first proxy or gateway to receive a Max-Forwards value of zero (0) in the request (see section 14.31). A TRACE request MUST NOT include an entity.</p>
<p>TRACE allows the client to see what is being received at the other end of the request chain and use that data for testing or diagnostic information. The value of the Via header field (section <a rel='xref' href='http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.45'>14.45</a>) is of particular interest, since it acts as a trace of the request chain. Use of the Max-Forwards header field allows the client to limit the length of the request chain, which is useful for testing a chain of proxies forwarding messages in an infinite loop.</p>
<p>If the request is valid, the response SHOULD contain the entire request message in the entity-body, with a Content-Type of "message/http". Responses to this method MUST NOT be cached.</p>
<h3><a id='sec9.9'>9.9</a> CONNECT</h3>
<p>This specification reserves the method name CONNECT for use with a proxy that can dynamically switch to being a tunnel (e.g. SSL tunneling <a rel='bibref' href='http://www.w3.org/Protocols/rfc2616/rfc2616-sec17.html#bib44'>[44]</a>).</p>


<h2><a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html">List of HTTP Response Status Codes</a></h2>
<h3>1xx Info / Informational</h3>
<h4><code>HTTP_INFO</code> - Request received, continuing process.</h4>
<p>Indicates a provisional response, consisting only of the Status-Line and optional headers, and is terminated by an empty line.</p>
<ul>
    <li><strong>100 Continue</strong> - <code>HTTP_CONTINUE</code></li>
    <li><strong>101 Switching Protocols</strong> - <code>HTTP_SWITCHING_PROTOCOLS</code></li>
    <li><strong>102 Processing</strong> - <code>HTTP_PROCESSING</code></li>
</ul>
<h3>2xx Success / OK</h3>
<h4><code>HTTP_SUCCESS</code> - The action was successfully received, understood, and accepted.</h4>
<p>Indicates that the client's request was successfully received, understood, and accepted.</p>
<ul>
    <li><strong>200 OK</strong> - <code>HTTP_OK</code></li>
    <li><strong>201 Created</strong> - <code>HTTP_CREATED</code></li>
    <li><strong>202 Accepted</strong> - <code>HTTP_ACCEPTED</code></li>
    <li><strong>203 Non-Authoritative Information</strong> - <code>HTTP_NON_AUTHORITATIVE</code></li>
    <li><strong>204 No Content</strong> - <code>HTTP_NO_CONTENT</code></li>
    <li><strong>205 Reset Content</strong> - <code>HTTP_RESET_CONTENT</code></li>
    <li><strong>206 Partial Content</strong> - <code>HTTP_PARTIAL_CONTENT</code></li>
    <li><strong>207 Multi-Status</strong> - <code>HTTP_MULTI_STATUS</code></li>
</ul>
<h3>3xx Redirect</h3>
<h4><code>HTTP_REDIRECT</code> - The client must take additional action to complete the request.</h4>
<p>Indicates that further action needs to be taken by the user-agent in order to fulfill the request. The action required may be carried out by the user agent without interaction with the user if and only if the method used in the second request is GET or HEAD. A user agent should not automatically <em>redirect a request more than 5 times</em>, since such redirections usually indicate an <strong>infinite loop</strong>.</p>
<ul>
    <li><strong>300 Multiple Choices</strong> - <code>HTTP_MULTIPLE_CHOICES</code></li>
    <li><strong>301 Moved Permanently</strong> - <code>HTTP_MOVED_PERMANENTLY</code></li>
    <li><strong>302 Found</strong> - <code>HTTP_MOVED_TEMPORARILY</code></li>
    <li><strong>303 See Other</strong> - <code>HTTP_SEE_OTHER</code></li>
    <li><strong>304 Not Modified</strong> - <code>HTTP_NOT_MODIFIED</code></li>
    <li><strong>305 Use Proxy</strong> - <code>HTTP_USE_PROXY</code></li>
    <li><strong>306 unused</strong> - <code>UNUSED</code></li>
    <li><strong>307 Temporary Redirect</strong> - <code>HTTP_TEMPORARY_REDIRECT</code></li>
</ul>
<h3>4xx Client Error</h3>
<h4><code>HTTP_CLIENT_ERROR</code> - The request contains bad syntax or cannot be fulfilled.</h4>
<p>Indicates case where client seems to have erred. Except when responding to a HEAD request, the server should include an entity containing an explanation of the error situation, and whether it is a temporary or permanent condition.</p>
<ul>
    <li><strong>400 Bad Request</strong> - <code>HTTP_BAD_REQUEST</code></li>
    <li><strong>401 Authorization Required</strong> - <code>HTTP_UNAUTHORIZED</code></li>
    <li><strong>402 Payment Required</strong> - <code>HTTP_PAYMENT_REQUIRED</code></li>
    <li><strong>403 Forbidden</strong> - <code>HTTP_FORBIDDEN</code></li>
    <li><strong>404 Not Found</strong> - <code>HTTP_NOT_FOUND</code></li>
    <li><strong>405 Method Not Allowed</strong> - <code>HTTP_METHOD_NOT_ALLOWED</code></li>
    <li><strong>406 Not Acceptable</strong> - <code>HTTP_NOT_ACCEPTABLE</code></li>
    <li><strong>407 Proxy Authentication Required</strong> - <code>HTTP_PROXY_AUTHENTICATION_REQUIRED</code></li>
    <li><strong>408 Request Time-out</strong> - <code>HTTP_REQUEST_TIME_OUT</code></li>
    <li><strong>409 Conflict</strong> - <code>HTTP_CONFLICT</code></li>
    <li><strong>410 Gone</strong> - <code>HTTP_GONE</code></li>
    <li><strong>411 Length Required</strong> - <code>HTTP_LENGTH_REQUIRED</code></li>
    <li><strong>412 Precondition Failed</strong> - <code>HTTP_PRECONDITION_FAILED</code></li>
    <li><strong>413 Request Entity Too Large</strong> - <code>HTTP_REQUEST_ENTITY_TOO_LARGE</code></li>
    <li><strong>414 Request-URI Too Large</strong> - <code>HTTP_REQUEST_URI_TOO_LARGE</code></li>
    <li><strong>415 Unsupported Media Type</strong> - <code>HTTP_UNSUPPORTED_MEDIA_TYPE</code></li>
    <li><strong>416 Requested Range Not Satisfiable</strong> - <code>HTTP_RANGE_NOT_SATISFIABLE</code></li>
    <li><strong>417 Expectation Failed</strong> - <code>HTTP_EXPECTATION_FAILED</code></li>
    <li><strong>418 unused</strong> - <code>UNUSED</code></li>
    <li><strong>419 unused</strong> - <code>UNUSED</code></li>
    <li><strong>420 unused</strong> - <code>UNUSED</code></li>
    <li><strong>421 unused</strong> - <code>UNUSED</code></li>
    <li><strong>422 Unprocessable Entity</strong> - <code>HTTP_UNPROCESSABLE_ENTITY</code></li>
    <li><strong>423 Locked</strong> - <code>HTTP_LOCKED</code></li>
    <li><strong>424 Failed Dependency</strong> - <code>HTTP_FAILED_DEPENDENCY</code></li>
    <li><strong>425 No code</strong> - <code>HTTP_NO_CODE</code></li>
    <li><strong>426 Upgrade Required</strong> - <code>HTTP_UPGRADE_REQUIRED</code></li>
</ul>
<h3>5xx Server Error</h3>
<h4><code>HTTP_SERVER_ERROR</code> - The server failed to fulfill an apparently valid request.</h4>
<p>Indicate cases in which the server is aware that it has erred or is incapable of performing the request. Except when responding to a HEAD request, the server should include an entity containing an explanation of the error situation, and whether it is a temporary or permanent condition. User agents should display any included entity to the user. These response codes are applicable to any request method.</p>
<ul>
    <li><strong>500 Internal Server Error</strong> - <code>HTTP_INTERNAL_SERVER_ERROR</code></li>
    <li><strong>501 Method Not Implemented</strong> - <code>HTTP_NOT_IMPLEMENTED</code></li>
    <li><strong>502 Bad Gateway</strong> - <code>HTTP_BAD_GATEWAY</code></li>
    <li><strong>503 Service Temporarily Unavailable</strong> - <code>HTTP_SERVICE_UNAVAILABLE</code></li>
    <li><strong>504 Gateway Time-out</strong> - <code>HTTP_GATEWAY_TIME_OUT</code></li>
    <li><strong>505 HTTP Version Not Supported</strong> - <code>HTTP_VERSION_NOT_SUPPORTED</code></li>
    <li><strong>506 Variant Also Negotiates</strong> - <code>HTTP_VARIANT_ALSO_VARIES</code></li>
    <li><strong>507 Insufficient Storage</strong> - <code>HTTP_INSUFFICIENT_STORAGE</code></li>
    <li><strong>508 unused</strong> - <code>UNUSED</code></li>
    <li><strong>509 unused</strong> - <code>UNUSED</code></li>
    <li><strong>510 Not Extended</strong> - <code>HTTP_NOT_EXTENDED</code></li>
</ul>
<h2>Helpful HTTP Links</h2>
<ol>
    <li><a href="http://rfc.askapache.com/rfc2616.html#section-10">HTTP specification, Section 10</a></li>
    <li><a href="http://rfc.askapache.com/rfc2817.html#section-4">TLS Upgrade within HTTP specification, Section 4</a></li>
    <li><a href="http://rfc.askapache.com/rfc2817.html#section-7.1">HTTP Status Code Registry</a></li>
    <li><a href="http://rfc.askapache.com/rfc4918.html#section-11">WebDAV specification, Section 11</a></li>
    <li><a href="http://www.iana.org/assignments/http-status-codes">IANA registry</a></li>
    <li><a href="http://livedocs.adobe.com/fms/2/docs/00000338.html">Adobe Flash status code definitions (ie 408)</a></li>
    <li><a href="http://support.microsoft.com/?id=318380">Microsoft Internet Information Server Status Codes and Sub-Codes</a></li>
    <li>httplint</li>
    <li><a href="http://www.w3.org/Protocols/HTTP/HTRQ_Headers.html">HTTP Headers, brief intro.</a></li>
    <li><a href="http://www.w3.org/TR/cuap">Common User-Agent Issues</a></li>
</ol>
<hr class="C" />
<dl>
    <dt>DRP</dt>
    <dd><a href="http://www.w3.org/TR/NOTE-drp-19970825">"The HTTP Distribution and Replication Protocol"</a></dd>
    <dt>DupSup</dt>
    <dd><a href="http://www3.ietf.org/proceedings/98dec/I-D/draft-mogul-http-dupsup-00.txt">"Duplicate Suppression in HTTP"</a></dd>
    <dt>EARL Schema</dt>
    <dd><a href="http://www.w3.org/WAI/ER/EARL10/WD-EARL10-Schema-20060101">"Evaluation and Report Language (EARL) 1.0 Schema"</a></dd>
    <dt>EDD</dt>
    <dd><a href="http://wp.netscape.com/assist/net_sites/pushpull.html">"An exploration of dynamic documents"</a></dd>
    <dt>EdgeArch</dt>
    <dd><a href="http://www.w3.org/TR/2001/NOTE-edge-arch-20010804">"Edge Architecture Specification"</a></dd>
    <dt>HttpClient</dt>
    <dd><a href="http://jakarta.apache.org/commons/httpclient/">Jakarta Commons HttpClient</a></dd>
    <dt>HTML4</dt>
    <dd><a href="http://www.w3.org/TR/1999/REC-html401-19991224/">"HTML 4.01 Specification"</a></dd>
    <dt>JEPI</dt>
    <dd><a href="http://www.w3.org/TR/NOTE-jepi-970519">"White Paper: Joint Electronic Payment Initiative"</a></dd>
    <dt>ObjectHeaders</dt>
    <dd><a href="http://www.w3.org/Protocols/HTTP/Object_Headers.html">"Object Header lines in HTTP"</a></dd>
    <dt>OPS-OverHTTP</dt>
    <dd><a href="http://www.w3.org/TR/NOTE-OPS-OverHTTP">"Implementation of OPS Over HTTP"</a></dd>
    <dt>OPTIONS messages</dt>
    <dd>"Specification of HTTP/1.1 OPTIONS messages"</dd>
    <dt>P3P</dt>
    <dd><a href="http://www.w3.org/TR/2002/REC-P3P-20020416/">"The Platform for Privacy Preferences 1.0 (P3P1.0) Specification"</a></dd>
    <dt>PEP</dt>
    <dd><a href="http://www.w3.org/TR/WD-http-pep-970526">"PEP - an Extension Mechanism for HTTP"</a></dd>
    <dt>PICSLabels</dt>
    <dd><a href="http://www.w3.org/TR/REC-PICS-labels-961031">"PICS Label Distribution Label Syntax and Communication Protocols, Version 1.1"</a></dd>
    <dt>Proxy Notification</dt>
    <dd><a href="http://www.w3.org/TR/WD-proxy-960221">"Notification for Proxy Caches"</a></dd>
    <dt>RDF</dt>
    <dd><a href="http://www.w3.org/TR/rdf-concepts/">"Resource Description Framework (RDF): Concepts and Abstract Syntax"</a></dd>
    <dt>RDF-PRIMER</dt>
    <dd><a href="http://www.w3.org/TR/rdf-primer/"> <acronym title="Resource Description Framework">RDF</acronym> Primer</a></dd>
    <dt>RFC2068</dt>
    <dd><a href="http://rfc.askapache.com/rfc2068/">"Hypertext Transfer Protocol -- HTTP/1.1"</a></dd>
    <dt>RFC2109</dt>
    <dd><a href="http://rfc.askapache.com/rfc2109/">"HTTP State Management Mechanism"</a></dd>
    <dt>RFC2183</dt>
    <dd><a href="http://rfc.askapache.com/rfc2183/">"Communicating Presentation Information in Internet Messages: The Content-Disposition Header Field"</a></dd>
    <dt>RFC2227</dt>
    <dd><a href="http://rfc.askapache.com/rfc2227/">"Simple Hit-Metering and Usage-Limiting for HTTP"</a></dd>
    <dt>RFC2295</dt>
    <dd><a href="http://rfc.askapache.com/rfc2295/">"Transparent Content Negotiation in HTTP"</a></dd>
    <dt>RFC2310</dt>
    <dd><a href="http://rfc.askapache.com/rfc2310/">"The Safe Response Header Field"</a></dd>
    <dt>RFC2324</dt>
    <dd><a href="http://rfc.askapache.com/rfc2324/">"Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0)"</a></dd>
    <dt>RFC2397</dt>
    <dd><a href="http://rfc.askapache.com/rfc2397/">"The 'data' URL scheme"</a></dd>
    <dt>RFC2518</dt>
    <dd><a href="http://rfc.askapache.com/rfc2518/">"HTTP Extensions for Distributed Authoring -- WEBDAV"</a></dd>
    <dt>RFC2616</dt>
    <dd><a href="http://rfc.askapache.com/rfc2616/">"Hypertext Transfer Protocol -- HTTP/1.1"</a></dd>
    <dt>RFC2617</dt>
    <dd><a href="http://rfc.askapache.com/rfc2617/">"HTTP Authentication: Basic and Digest Access Authentication"</a></dd>
    <dt>RFC2660</dt>
    <dd><a href="http://rfc.askapache.com/rfc2660/">"The Secure HyperText Transfer Protocol"</a></dd>
    <dt>RFC2774</dt>
    <dd><a href="http://rfc.askapache.com/rfc2774/">"An HTTP Extension Framework"</a></dd>
    <dt>RFC2965</dt>
    <dd><a href="http://rfc.askapache.com/rfc2965/">"HTTP State Management Mechanism"</a></dd>
    <dt>RFC3229</dt>
    <dd><a href="http://rfc.askapache.com/rfc3229/">"Delta encoding in HTTP"</a></dd>
    <dt>RFC3230</dt>
    <dd><a href="http://rfc.askapache.com/rfc3230/">"Instance Digests in HTTP"</a></dd>
    <dt>RFC3253</dt>
    <dd><a href="http://rfc.askapache.com/rfc3253/">"Versioning Extensions to WebDAV (Web Distributed Authoring and Versioning)"</a></dd>
    <dt>RFC3648</dt>
    <dd><a href="http://rfc.askapache.com/rfc3648/">"Web Distributed Authoring and Versioning (WebDAV) Ordered Collections Protocol"</a></dd>
    <dt>RFC3986</dt>
    <dd><a href="http://rfc.askapache.com/rfc3648/">"Uniform Resource Identifier (URI): Generic Syntax"</a></dd>
    <dt>RFC4229</dt>
    <dd><a href="http://rfc.askapache.com/rfc4229/">"HTTP Header Field Registrations"</a></dd>
    <dt>SOAP1.1</dt>
    <dd><a href="http://www.w3.org/TR/2000/NOTE-SOAP-20000508">"Simple Object Access Protocol (SOAP) 1.1"</a></dd>
    <dt>UA Attributes</dt>
    <dd>"User-Agent Display Attributes Headers"</dd>
    <dt>WIRE</dt>
    <dd><a href="http://www3.ietf.org/proceedings/98dec/I-D/draft-girod-w3-id-res-ext-00.txt">"WIRE - W3 Identifier Resolution Extensions"</a></dd>
</dl><p><a href="http://www.askapache.com/online-tools/http-headers-tool"></a><a href="http://www.askapache.com/online-tools/http-headers-tool">Raw HTTP Header Debugger</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/online-tools/http-headers-tool/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Creating an Offline Version of Page</title>
		<link>http://www.askapache.com/php/scrape-offline-page-curl.html</link>
		<comments>http://www.askapache.com/php/scrape-offline-page-curl.html#comments</comments>
		<pubDate>Fri, 22 Oct 2010 20:06:49 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=4708</guid>
		<description><![CDATA[<p><a class="IFL" href="http://www.askapache.com/php/scrape-offline-page-curl.html"><img src="http://uploads.askapache.com/2010/10/askapache-scraper-350x89.png" alt="I can do anything" title="askapache-scraper" width="350" height="89" class="size-medium wp-image-4709" /></a>So, here's what I hacked together last night, that is being used today.  It's essentially 2 files.<br class="C" /></p>
<ol>
<li>A php file that scrapes uses curl to scrape all the urls for the page (favicon, css, images, pdfs, etc..)</li>
<li>A simple bash shell script acting as a cgi that creates a zip file of all the urls, and a self-extracting exe file for those without a winzip tool</li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/php/scrape-offline-page-curl.html"></a><a href="http://www.askapache.com/php/scrape-offline-page-curl.html"><cite>AskApache.com</cite></a></p><p>A large client has a secure website where they assemble and create presentations consisting of a single Table of Contents page with many pdf's attached to it.  They use the site to make presentations.  This is a big client, a rich client, and they needed a way to guarantee they would be able to access the site.  So I got this request:</p>

<blockquote>Can you make an offline version of the Page that is always updated and available for download so we can download the offline version and present using that in case the website is down or more often, in case Internet Access is unavailable?</blockquote>

<p class="anote"><strong>Update</strong>: I used <strong>COOKIE</strong> based authentication to secure this clients site, so that only logged in users can see anything at all, so how do I enable the curl requests to authenticate as well using the COOKIE of the requesting user in each request made by curl?  Just add the users HTTP_COOKIE to the headers array used by curl like so:</p>
<pre>array(
...
"Cookie: {$_SERVER[&#039;HTTP_COOKIE&#039;]}"
)</pre>
<p>That now means the scraped version of the page is an exact duplicate that the user is looking at.  Very sweet!</p>


<h2>I can GET anything</h2>
<p><a class="IFL" href="http://www.askapache.com/php/scrape-offline-page-curl.html"><img src="http://uploads.askapache.com/2010/10/askapache-scraper-350x89.png" alt="I can do anything" title="askapache-scraper" width="350" height="89" class="size-medium wp-image-4709" /></a>So, here's what I hacked together last night, that is being used today.  It's essentially 2 files.<br class="C" /></p>
<ol>
<li>A php file that scrapes uses curl to scrape all the urls for the page (favicon, css, images, pdfs, etc..)</li>
<li>A simple bash shell script acting as a cgi that creates a zip file of all the urls, and a self-extracting exe file for those without a winzip tool</li>
</ol>


<h2>The PHP File</h2>
<p>This is a simple script that is given 2 parameters:</p>
<ol>
<li>The url to scrape</li>
<li>The type of download to return</li>
</ol>


<h3>scrapeit.php</h3>
<pre>&lt;?php
ob_start();
&nbsp;
/**
* gogeturl2() - grabs a url with curl, and saves it to disk, works for all media types, pdf, js, img, etc.
*
* @return
*/
function gogeturl2($url, $saveto)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
if ($fp = fopen($saveto, &#039;w&#039;)) // {curl_setopt($ch,CURLOPT_STDERR, $fp); curl_setopt($ch,CURLOPT_VERBOSE,1);}
{
  curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  curl_setopt($ch, CURLOPT_MAXCONNECTS, 4);
  curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
  curl_setopt($ch, CURLOPT_FAILONERROR, 1);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
  curl_setopt($ch, CURLOPT_FILE, $fp);
  curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
    "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",
    "Accept-Language: en-us,en;q=0.5",
    "Accept-Encoding: none",
    "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7",
    "Keep-Alive: 300",
    "Connection: Keep-Alive",
    "Pragma:"));
  $r = curl_exec($ch);
  $ch_info = curl_getinfo($ch);
  if (curl_errno($ch)) error_log(print_r($ch_info, 1) . print_r(curl_errno($ch), 1) . print_r(curl_error($ch), 1));
  else curl_close($ch);
  fclose($fp);
}
}
/**
* gogeturl()  returns the source of the requested url (thanks to accept-encoding: none)
*
* @return
*/
function gogeturl($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_MAXCONNECTS, 4);
curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 GTB6",
  "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
  "Accept-Language: en-us,en;q=0.5",
  "Accept-Encoding: none",
  "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7",
  "Keep-Alive: 115",
  "Connection: keep-alive",
  "Pragma:"));
$g = curl_exec($ch);
if (curl_errno($ch)) error_log(print_r(array(
&#039;chinfo&#039; =&gt; $ch_info,
&#039;curl_errno&#039; =&gt; curl_errno($ch),
&#039;curl_error&#039; =&gt; curl_error($ch)
), 1));
curl_close($ch);
return $g;
}
&nbsp;
/**
* _mkdir() makes a directory
*
* @return
*/
function _mkdir($path, $mode = 0755)
{
$old = umask(0);
$res = @mkdir($path, $mode);
umask($old);
return $res;
}
&nbsp;
/**
* rmkdir()  recursively makes a directory tree
*
* @return
*/
function rmkdir($path, $mode = 0755)
{
return is_dir($path) || (rmkdir(dirname($path), $mode) &amp;&amp; _mkdir($path, $mode));
}</pre>

<p>The following should be in a couple functions, but I was running on a tight time schedule, and hey this $hitt aint free... wait yes it is, always.</p>
<pre>// Ok lets get it on!
// first lets setup some variables
if (!isset($_GET[&#039;url&#039;]) || empty($_GET[&#039;url&#039;]))die();
$td = $th = $urls = array();
$FDATE = date("m-d-y-Hms");
$FTMP = &#039;/home/askapache/sites/askapache.com/tmp&#039;;
$fetch_url = $_GET[&#039;url&#039;];
$fu = parse_url($fetch_url);
$fd = substr($FTMP . $fu[&#039;path&#039;], 0, - 1);
$FEXE = "{$fd}-{$FDATE}.exe";
$FZIP = "{$fd}-{$FDATE}.zip";
&nbsp;
// now this is a shortcut to download the css file and add all the images in it to the img_urls array
$img_urls = array();
$gg = preg_match_all("/url\(([^\)]*?)\)/Ui", gogeturl(&#039;https://www.askapache.com/askapache-0128770124.css&#039;), $th);
$imgs = array_unique($th[1]);
foreach($imgs as $img)
{
// only because all the links are relative
$img_urls[] = &#039;https://www.askapache.com&#039; . $img;
}
&nbsp;
// now fetch the main page, and assemble an array of all the external resources into the urls array
$gg = preg_match_all("/(background|href)=([\"\&#039;])([^\"\&#039;#]+?)([\"\&#039;])/Ui", gogeturl($fetch_url), $th);
foreach($th[3] as $url)
{
if (strpos($url, &#039;.js&#039;) !== false)continue;
if (strpos($url, &#039;wp-login.php&#039;) !== false || $url == &#039;https://www.askapache.com/&#039;) continue;
if (strrpos($url, &#039;/&#039;) == strlen($url) - 1)continue;
if (strpos($url, &#039;https://www.askapache.com/&#039;) === false)
{
  if ($url[0] == &#039;/&#039;) $urls[] = &#039;https://www.askapache.com&#039; . $url;
  else continue;
}
else $urls[] = $url;
}
&nbsp;
// now create a uniq array of urls, then download and save each of them
$urls = array_merge(array_unique($img_urls), array_unique($urls));
foreach($urls as $url)
{
  $pu = parse_url($url);
  rmkdir(substr($fd . $pu[&#039;path&#039;], 0, strrpos($fd . $pu[&#039;path&#039;], &#039;/&#039;)));
  gogeturl2($url, $fd . $pu[&#039;path&#039;]);
}
&nbsp;
// deletes dir ie. /this-page/this-page/ when it should be /this-page/index.html
if (is_dir($fd . $fu[&#039;path&#039;])) rmdir($fd . $fu[&#039;path&#039;]);
&nbsp;
// now save the page as index.html
gogeturl2($fetch_url, $fd . &#039;/index.html&#039;);
&nbsp;
// fixup to be able3 to parse
$g = file_get_contents($fd . &#039;/index.html&#039;);
$g = str_replace(&#039;&lt;script&#039;, &#039;&lt;!--&lt;script&#039;, $g);
$g = str_replace(&#039;script&gt;&#039;, &#039;script&gt;!--&gt;&#039;, $g);
$g = str_replace(&#039;href="https://www.askapache.com/&#039;, &#039;href="/&#039;, $g);
$g = str_replace(&#039;src="https://www.askapache.com/&#039;, &#039;src="/&#039;, $g);
$g = str_replace(&#039;href="/&#039;, &#039;href="&#039;, $g);
$g = str_replace(&#039;src="/&#039;, &#039;src="&#039;, $g);
$g = str_replace("href=&#039;https://www.askapache.com/", "href=&#039;/", $g);
$g = str_replace("src=&#039;https://www.askapache.com/", "src=&#039;/", $g);
$g = str_replace("href=&#039;/", "href=&#039;", $g);
$g = str_replace("src=&#039;/", "src=&#039;", $g);
file_put_contents($fd . &#039;/index.html&#039;, $g);
&nbsp;
// fixup for css file
foreach($urls as $url)
{
if (strpos($url, &#039;.css&#039;) !== false)
{
  $fuu = parse_url($url);
  $css = file_get_contents($fd . $fuu[&#039;path&#039;]);
  $css = str_replace(&#039;url(/&#039;, &#039;url(../&#039;, $css);
  file_put_contents($fd . $fuu[&#039;path&#039;], $css);
}
}
&nbsp;
// my favorite technique, using fsockopen to initiate a shell script server-side.
// passing the args in the HTTP Headers... genius!!
// close the sucker fast with HTTP/1.0 and connection: close
$fp = fsockopen ($_SERVER[&#039;SERVER_NAME&#039;], 80, $errno, $errstr, 5);
fwrite($fp, "GET /cgi-bin/sh/zip.sh HTTP/1.0\r\nHost: www.askapache.com\r\nX-Pad: {$fd}\r\nX-Allow: {$FDATE}\r\nConnection: Close\r\n\r\n");
fclose($fp);
&nbsp;
// loop until the file created by /cgi-bin/sh/zip.sh is found
$c = 0;
do
{
$c++;
sleep(1);
clearstatcache();
if (is_file("{$FEXE}")) continue;
}
while ($c &lt; 20);
&nbsp;
// either zip or exe
$type = $_GET[&#039;type&#039;];
if ($type == &#039;zip&#039;) $file = $FZIP;
else $file = $FEXE;
&nbsp;
// wow great debugging dude
error_log($file);
&nbsp;
// if the file is there, do a 302 redirect to initiate download
if (file_exists("{$file}"))
{
  @header("HTTP/1.1 302 Moved", 1, 302);
  @header("Status: 302 Moved", 1, 302);
  @header(&#039;Location: https://www.askapache.com/&#039; . basename($file));
  exit;
}
&nbsp;
exit;
?&gt;</pre>



<h2>zip.sh</h2>
<pre>#!/bin/sh
&nbsp;
# all you need for cgi
  echo -e "Content-type: text/plain\n\n"
&nbsp;
# blank that run log
  echo "" &gt; /home/askapache/sites/askapache.com/tmp/run.log
&nbsp;
# redirect 1 and 2 to the run log for the whole script
  exec &amp;&gt;/home/askapache/sites/askapache.com/tmp/run.log
&nbsp;
# basename
  N=${HTTP_X_PAD//*\/}
&nbsp;
# date-based
  NN=${HTTP_X_ALLOW}
&nbsp;
# create recursively the dir tree
  mkdir -pv $HTTP_X_PAD
&nbsp;
# cd to the tmp
  cd /home/askapache/sites/askapache.com/tmp
&nbsp;
# the zip version with date
  F=$N-$NN.zip
&nbsp;
# the exe version with date
  NN=$N-$NN.exe
&nbsp;
# for debugging, only goes to run log
  echo "F=$F"
  echo "NN=$NN"
  echo "N=$N"
&nbsp;
# create a relative (r is recursive) archive of the entire dir
  /usr/bin/zip -rvv $F $N
&nbsp;
# add the self-extracting stub to the archive
  /bin/cat unzipsfx.exe $F &gt; $NN
&nbsp;
# fix the sfx stub
  /usr/bin/zip -A $NN
&nbsp;
# move both the exe and zip to the web-docroot to be dl&#039;d directly
  cp -vf $NN /home/askapache/sites/askapache.com/htdocs/
  cp -vf $F /home/askapache/sites/askapache.com/htdocs/
&nbsp;
# sleep for 60 seconds and then rm all the files, so you better download that file fast
  sleep 60 &amp;&amp; rm -rvf $HTTP_X_PAD $F $NN /home/askapache/sites/askapache.com/htdocs/$NN /home/askapache/sites/askapache.com/htdocs/$F
&nbsp;
#suh suh cya
exit 0;</pre>


<h3>Creating SFX Archives</h3>
<p>The best way is 7z, but I couldn't get p7zip's sfx module to work and didn't have time to compile it.  Instead I just used the stub available here:  <code>curl -O -L ftp://ftp.info-zip.org/pub/infozip/win32/unz552xn.exe</code> which works great but no customization like password, icons, etc.. oh well.</p>



<h2>Implementation</h2>
<p>Simple, just create a link to the php file with the url and type parameters.  <code>/cgi-bin/php/scrapeit.php?url=http://www.askapache.com/htaccess/htaccess.html&amp;type=exe</code> or if you integrate into wordpress like I did you can add this to your header or admin_bar and use the <code>get_permalink()</code> for the url arg.</p>

<h2>Lock It Down</h2>
<p>This was used on a private site so what I did was add some code to the scrapeit.php file that just copied the HTTP_COOKIE value sent by the requesting user and sent that as part of the request in the fsockopen request.  That means only logged in users can do this, and furthermore, if a user doesn't have access to a page and tries to use this to circumvent, they can't.  And also htaccess was used to limit the scripts to only allow the ip's running the server to make connections.</p>

<h2>Conclusion</h2>
<p>What can't be done with linux, bash, http, php, and a little server-side finesse?  My clients are very happy, and I had some fun!</p><p><a href="http://www.askapache.com/php/scrape-offline-page-curl.html"></a><a href="http://www.askapache.com/php/scrape-offline-page-curl.html">Creating an Offline Version of Page</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/php/scrape-offline-page-curl.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Advanced Windows Batch File Scripting</title>
		<link>http://www.askapache.com/windows/advanced-batch-scripting.html</link>
		<comments>http://www.askapache.com/windows/advanced-batch-scripting.html#comments</comments>
		<pubDate>Fri, 03 Sep 2010 18:14:02 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=4577</guid>
		<description><![CDATA[<p><a class="IFL" href="http://www.askapache.com/windows/advanced-batch-scripting.html"><img src="http://uploads.askapache.com/2010/09/windows-batch-file-example-116x45.png" alt="Windows Batch Programming Example" title="Windows Batch Programming Example" width="116" height="45" /></a>If for some reason you need to use windows .bat batch file scripting to do some task, or you just want to learn the most universal batch programming language on Windows machines, you lucked out and found the AskApache example.  My expertise is the shell, in this article the shell is Windows <code>cmd.exe</code>.  It has some pretty advanced windows shell usage, including pipes and redirection, but it's the modular linux-like coding approach that earns this script it's "advanced" title.</p>
<pre>:SETPROMPT
set PROMPT=$_[%USERNAME%@%USERDOMAIN%]$S[$P]$_$M$G &#38;&#38; EXIT /B</pre>

<p><a class="IFL" href="http://uploads.askapache.com/2010/09/Untitled-1.png"><img src="http://uploads.askapache.com/2010/09/Untitled-1-116x38.png" alt="Create an AT job to run as system in Notepad++ IDE" title="Create an AT job to run as system in Notepad++ IDE" width="116" height="38" class="size-thumbnail wp-image-4618" /></a>My favorite tool (and I've tried sooo many) for editing most Windows files and especially .bat files is the free and open-source <a href="http://notepad-plus-plus.org/">Notepad++</a>.  Set that up and you will have a color-syntax-highlighted editor for Batch Scripting that works very very well.<br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/windows/advanced-batch-scripting.html"></a><a href="http://www.askapache.com/windows/advanced-batch-scripting.html"><cite>AskApache.com</cite></a></p><p><a href="http://www.askapache.com/windows/advanced-batch-scripting.html/untitled-1/" rel="attachment wp-att-4618"><img src="http://uploads.askapache.com/2010/09/Untitled-1.png" alt="Create an AT job to run as system in Notepad++ IDE" title="Create an AT job to run as system in Notepad++ IDE" width="993" height="326" class="size-full wp-image-4618" /></a></p>
<p><a class="IFL" href="http://uploads.askapache.com/2010/09/windows-batch-file-example.png"><img src="http://uploads.askapache.com/2010/09/windows-batch-file-example-116x45.png" alt="Windows Batch Programming Example" title="Windows Batch Programming Example" width="116" height="45" /></a>First off, this is a single windows <code>.bat</code> file that I have written to do advanced batch scripting the easy way, meaning it's mostly a series of functions you can call from the script or within other functions for extremely modular code.  Before you get all bent out of shape by my choice of words ("easy, modular"), when I say this is advanced I mean for Windows .bat files, one of the worlds worst scripting languages, but it works on all windows versions so it's ideal for things like autorun, autoplay, custom startups, usb drives, etc..  If you are looking for information on how to use and program windows .bat files to do anything cool, this is the right place!  I tried my best to mimic linux shell-scripting, so it's likely different than other batch files you have seen.<br class="C" /></p>



<h2>Batch File IDE and Script Source</h2>
<p><a class="IFL" href="http://uploads.askapache.com/2010/09/Untitled-1.png"><img src="http://uploads.askapache.com/2010/09/Untitled-1-116x38.png" alt="Create an AT job to run as system in Notepad++ IDE" title="Create an AT job to run as system in Notepad++ IDE" width="116" height="38" class="size-thumbnail wp-image-4618" /></a>My favorite tool (and I've tried sooo many) for editing most Windows files and especially .bat files is the free and open-source <a href="http://notepad-plus-plus.org/">Notepad++</a>.  Set that up and you will have a color-syntax-highlighted editor for Batch Scripting that works very very well.<br class="C" /></p>
<p><a class="IFL" href='http://uploads.askapache.com/2010/09/advanced-batch-askapache.txt'><img src="http://uploads.askapache.com/2010/09/windows-batch-file.png" width="46" height="60" title="windows batch file windows" alt="Advanced Windows Batch File Scripting" /></a>The next thing to do is <a href='http://uploads.askapache.com/2010/09/advanced-batch-askapache.txt'>download the source code</a>, which includes comments and formatting I had to remove for this online article.  Then rename from <code>.txt</code> to <code>.bat</code> and open in your IDE/text-editor of choice.<br class="C" /></p>


<h2>Quick Batch File Example</h2>
<p>This is a simple batch file named ping-check.bat that I use when rebooting remote servers.  The reboot is issued from an SSH session and causes the server to go down and then come back up.  When the server goes down the network goes down too so I fire this script up to continually ping the remote server until it responds, at which point I can ssh back in.</p>
<p>One of the first hacks for batch files is line 1, the PUSHD command cd's the scripts working environment to the directory of the script itself.</p>
<pre>@ECHO OFF &amp;&amp; PUSHD "%~dp0" &amp;&amp; SETLOCAL
&nbsp;
CALL :PINGCHECK "%~1"
&nbsp;
nircmd.exe speak text "PING RECEIVED.  HOST BACK ONLINE" 7 60
ENDLOCAL &amp;&amp; POPD &amp;&amp; GOTO :EOF
&nbsp;
:PINGCHECK
ECHO CHECKING %~1
ping.exe -n 1 %~1 -w 5000 | FIND /C "Reply from %~1" | FIND "1" &gt;nul 2&gt;&amp;1
IF ERRORLEVEL 1 CALL :PINGCHECK "%~1" ELSE EXIT /B</pre>


<h2>Super-hero like even</h2>
<p>Just added this as an after thought, moving the main example further down this page.  This is an easier file to understand the scope of.  It effectively creates SSH-encrypted SOCK5 tunnels that stay connected and auto-reconnect if the link goes down.  I wanted to try and write a pure batch method to do that.   I wrote this to run automatically from a USB key so that I could keep my tools with me portably.  The thing of this script that is the most revolutionary is the method it uses to create auto-reconnecting <em>SSH-encrypted SOCKS5 tunnels</em> using the windows SYSTEM account to do it all in the background with plink.exe.  The hack to run it as a system account is by using the built-in <strong>AT</strong> command to run interactively, which lets you interactively do whatever you want as the builtin <code>NT AUTHORITY/SYSTEM</code> account.  The other part I am proud of with this is how lean I got the code, specifically how lean the function is that creates the at job to run every 5 minutes, while still doing connection-testing, all by parsing the cmd.exe processors builtin in DATE and TIME variables.  Do a google search for "windows batch file date and time" and you will appreciate just how lean this sucker is.</p>
<p>Almost forgot, check out the ways to keep a plink.exe (putty.exe for cmd.exe) SOCKS5 tunnel hidden and safe and continuously connected to a remote server in minimal lines od code.  This was a fun one to work on!  Enjoy (and remember this is just the warm-up example to glance at).</p>
<pre>@ECHO OFF &amp;&amp; PUSHD "%~dp0" &amp;&amp; SETLOCAL &amp;&amp; SETLOCAL ENABLEDELAYEDEXPANSION &amp;&amp; SETLOCAL ENABLEEXTENSIONS
&nbsp;
SET _CRYPTDRIVE=%~d0\
SET PATH=%_CRYPTDRIVE%PP;%_CRYPTDRIVE%PP\bin;%PATH%
SET _PUTTYBIN=%_CRYPTDRIVE%P\PP\putty.exe
&nbsp;
SET _PSERVER=solar.power.com
SET _PPORT=22
SET _PSESSION=newclean-tunnel
&nbsp;
SET _ADMINUSER=admin
SET _RUNUSER=life
&nbsp;
REM SAY CHECKING PLINK OUT LOUD
CALL :SPEAK "Checking Putty"
ECHO "CHECKING PUTTY"
&nbsp;
REM
IF NOT EXIST "%_CRYPTDRIVE%" (
  CALL :SPEAK "Crypt Not Mounted"
  AT|FOR /F "tokens=1" %%i IN (&#039;FIND /I "%~f0"&#039;) DO AT %%i /delete /yes &gt;nul 2&gt;&amp;1
  pskill.exe -t putty &gt;nul 2&gt;&amp;1
  pskill.exe -t thunderbird &gt;nul 2&gt;&amp;1
  pskill.exe -t ThunderbirdPortable &gt;nul 2&gt;&amp;1
  pskill.exe -t Firefox &gt;nul 2&gt;&amp;1
  pskill.exe -t FirefoxPortable &gt;nul 2&gt;&amp;1
  pskill.exe -t GC &gt;nul 2&gt;&amp;1
  EXIT
)
&nbsp;
REM CREATE AT JOB TO RUN THIS SCRIPT EVERY 5 MINUTES
CALL :CREATEATJOB
&nbsp;
pslist putty &gt;nul 2&gt;&amp;1
IF ERRORLEVEL 1 psexec.exe -i 0 -e -d -u %_RUNUSER% %_PUTTYBIN% -load %_PSESSION%
&nbsp;
REM KILL MULTIPLE PSEXEC&#039;s
CALL :KILLDUPES "psexec.exe"
&nbsp;
REM KILL MULTIPLE CMD.EXE&#039;s
CALL :KILLDUPES "cmd.exe"
&nbsp;
REM REACHABLE SERVER CHECK
CALL :PINGCHECK %_PSERVER%
&nbsp;
REM CHECK FOR INACTIVE PUTTY
CALL :PUTTYCHECK
&nbsp;
REM CHECK PORT IS LISTENING (FOR SOCKISFIED TUNNEL)
CALL :PORTCHECK %_PPORT%
&nbsp;
REM CALL :SPEAK "OK"
SLEEP 100 &amp;&amp; ECHO "OK" &amp;&amp; SLEEP 1 &amp;&amp; ENDLOCAL &amp;&amp; POPD &amp;&amp; EXIT
&nbsp;
REM =======================================================================================
REM =   SPEAK - Speak text
REM =======================================================================================
:SPEAK
nircmd.exe speak text "%~1" 5 60
ECHO "%~1"
EXIT /B
&nbsp;
REM =======================================================================================
REM =   RESTARTPLINK - Sleeps for %1 number of seconds
REM =======================================================================================
:RESTARTPLINK
CALL :SPEAK "%~1 ReSTARTing Plink"
REM runas /savecred /user:admin "%_PUTTYBIN% -load %_PSESSION%"
psexec.exe -i 0 -e -d -u %_RUNUSER% %_PUTTYBIN% -load %_PSESSION%
EXIT
EXIT /B
&nbsp;
REM =======================================================================================
REM =   PORTCHECK - Check that Port is being used (for tunnels)
REM =======================================================================================
:PORTCHECK
netstat.exe -n -v -a -p TCP | FIND "ESTABLISHED" | FIND ":%~1" &gt;nul 2&gt;&amp;1
IF ERRORLEVEL 1 CALL :RESTARTPLINK "PORT CHECK FAILED"
EXIT /B
&nbsp;
REM =======================================================================================
REM =   INACTIVEPUTTYCHECK - Check for inactive putty windows
REM =======================================================================================
:PUTTYCHECK
tasklist.exe /V /NH /FI "WINDOWTITLE eq PuTTY (inactive)" 2&gt;nul|FIND "INFO: " &gt;nul 2&gt;&amp;1
IF ERRORLEVEL 1 taskkill.exe /T /F /FI "WINDOWTITLE eq PuTTY (inactive)" &gt;nul 2&gt;&amp;1
&nbsp;
:: MAKE SURE ONLY 1 putty is running that is connected to the remote server
netstat.exe -n -a -o -p TCP | FIND ":%_PPORT%" | FIND /C ":%_PPORT%" | FIND "1" &gt;nul 2&gt;&amp;1
IF ERRORLEVEL 1 (
  tasklist.exe /V /FO TABLE /NH /FI "IMAGENAME eq putty.exe" 2&gt;nul | FIND /C "Running" | FIND "1" &gt;nul 2&gt;&amp;1
  IF ERRORLEVEL 1 (
    REM kill all running puttys (owned by system)
    FOR /F "usebackq tokens=2 skip=2" %%p IN (`tasklist.exe /V /FO TABLE /NH /FI "IMAGENAME eq putty.exe"`) DO taskkill.exe /F /PID %%p /T &gt;nul 2&gt;&amp;1
    CALL :RESTARTPLINK "EXTRA PUTTY FOUND"
  )
)
EXIT /B
&nbsp;
REM =======================================================================================
REM =   PINGCHECK - PING address to make sure it is reachable
REM =======================================================================================
:PINGCHECK
PING %~1 -n 1 -w 5000 | FIND "TTL=" &gt;nul 2&gt;&amp;1
IF ERRORLEVEL 1 (
  PING google.com -n 1 -w 500 | FIND "TTL=" &gt;nul 2&gt;&amp;1
  IF ERRORLEVEL 1 ( CALL :SPEAK "CHECK INTERNET CONNECTION" &amp;&amp; SLEEP 60 )
&nbsp;
  PING google.com -n 1 -w 5000 | FIND "TTL=" &gt;nul 2&gt;&amp;1
  IF ERRORLEVEL 1 ( CALL :SPEAK "CHECK INTERNET CONNECTION" &amp;&amp; SLEEP 60 )
&nbsp;
  PING google.com -n 1 -w 5000 | FIND "TTL=" &gt;nul 2&gt;&amp;1
  IF ERRORLEVEL 1 (
    CALL :SPEAK "KILL SOCKS PROGRAMS"
  SLEEP 100
  pskill.exe -t putty &gt;nul 2&gt;&amp;1
  pskill.exe -t thunderbird &gt;nul 2&gt;&amp;1
  pskill.exe -t ThunderbirdPortable &gt;nul 2&gt;&amp;1
  )
)
EXIT /B
&nbsp;
REM =======================================================================================
REM =   KILLDUPES - kills duplicate processes, except for the one with lowest pid
REM =======================================================================================
:KILLDUPES
REM Check that more than 1 process is running
tasklist.exe /V /NH /FI "IMAGENAME eq %~1" /FI "USERNAME eq SYSTEM" 2&gt;nul | FIND /C "K Running" | FIND "1" &gt;nul 2&gt;&amp;1
IF NOT ERRORLEVEL 1 EXIT /B
&nbsp;
REM Create Filename in current dir (of this script)
SET _T=%TIME: =0%&amp;&amp;SET _T=!_T::=-!&amp;&amp;SET _T=%~dp0%!_T:~0,-2!log
&nbsp;
REM Create the file in the same dir as this script named for date and sorted by PID
tasklist.exe /V /NH /FI "IMAGENAME eq %~1" /FI "USERNAME eq SYSTEM" 2&gt;nul | SORT /+29 &gt; "%_T%"
&nbsp;
REM Check that the file was created or exit
IF NOT EXIST "%_T%" ( CALL :SPEAK "FILE CREATION FAILED" &amp;&amp; EXIT /B )
&nbsp;
REM kill all the processes found except for 1, do not kill the process with the lowest pid number
FOR /F "tokens=2 skip=2" %%p IN (%_T%) DO taskkill.exe /F /PID %%p /T
&nbsp;
REM erase the file
REM ERASE /Q "%_T%" &gt;nul 2&gt;&amp;1
&nbsp;
REM check that the file was erased
REM IF EXIST "%_T%" ( CALL :SPEAK "ERASE FILE FAILED" &amp;&amp; EXIT /B )
&nbsp;
EXIT /B
&nbsp;
REM =======================================================================================
REM =   CREATEATJOB - runs job (START this file) every 5 minutes
REM =======================================================================================
:CREATEATJOB
:: delete all putty AT jobs
AT | FIND /C "%~f0" | FIND "1" &gt;nul 2&gt;&amp;1
IF ERRORLEVEL 1 ( AT|FOR /F "tokens=1" %%i IN (&#039;FIND /I "%~f0"&#039;) DO AT %%i /delete /yes &gt;nul 2&gt;&amp;1 )
SET /A H=!TIME:~0,2!&amp;&amp; SET M=!TIME:~3,2!
SET Y=%H%:%M%&amp;&amp; SET /A M+=5
IF !M! GEQ 61 ( SET /A H+=1&amp;&amp;SET /A M-=61 )
IF !H! GEQ 24 SET /A H-=24
SET M=0!M!&amp;&amp; SET H=0!H!
:: create AT job
AT %H:~-2%:%M:~-2% /INTERACTIVE %ComSpec% /E:ON /D /Q /C START /B /MIN %ComSpec% /E:ON /D /Q /C "%~f0" &gt;nul
EXIT /B</pre>







<h2>Advanced Batch File</h2>
<p>This is the main batch file example which you can <a href="http://uploads.askapache.com/2010/09/advanced-batch-askapache.txt">download here</a>.  Other than some minor changes this is the actual script I use at work when I logon to my PC.  The first thing it does is mount an encrypted TrueCrypt Drive where all of my files and settings are located.  It also starts a putty session named "1" that I configured to start a few encrypted tunnels and socks proxies so that my email Thunderbird and Website IDE Dreamweaver and other network apps can communicate 100% encrypted and my real location becomes hidden (thanks socks!).</p>
<p>I might come back later and add comments if I get any kind of response for this article, and because it's such a unique and low-traffic topic, I will try to answer any questions added with the comment form.</p>


<h2>Starting the Script</h2>
<p>The first line is of my own design and is perhaps the coolest hack in the script.  I use this 1 line to start pretty much all of my .bat files.</p>
<pre>@ECHO OFF&amp;&amp; SETLOCAL&amp;&amp; PUSHD "%~dp0"&amp;&amp; SETLOCAL ENABLEDELAYEDEXPANSION&amp;&amp; SETLOCAL ENABLEEXTENSIONS&amp;&amp; SET V=5&amp;&amp; IF NOT "!V!"=="5" (ECHO DelayedExpansion Failed&amp;&amp; GOTO :EOF)</pre>


<h2>SCRIPT VARIABLES</h2>
<p>These are all local to this script thanks to the SETLOCAL above, so they won't exist outside the scripts execution environment.</p>
<pre>REM ** Various vars for output used by functions
SET P1=^^^&gt;^^^&gt;^^^&gt;
SET P2=++
SET P3=::
SET L1=+==============================================================================================================+
SET L2=+--------------------------------------------------------------------------------------------------------------+
&nbsp;
REM ** administrator username, unless changed for more security, its Administrator
SET ADMINUSER=admin
&nbsp;
REM ** runuser is the username you use when running this script
SET RUNUSER=bill
&nbsp;
REM ** Custom COMSPEC for running cmd.exe
SET _SCOM=%COMSPEC% /E:ON /F:ON /D /Q /T:0C /C
&nbsp;
REM ** Custom START command
SET _START=START /WAIT /MIN /B %_SCOM%</pre>




<h2>MAIN PROGRAM EXECUTION</h2>
<p>This is where the main code starts, note how small it is thanks to the use of functions (labels/call/goto).  Read the comments in this area (start with :: or REM ) to see the extent of this script.  The gold is in the functions.</p>
<pre>:: Only allow certain users to run this script or die (prevents global STARTup or service running it)
CALL :CHECKUSERVALID %RUNUSER% %ADMINUSER%
&nbsp;
:: Mount the truecrypt container
CALL :CRYPTMOUNT "L" "%SYSTEMDRIVE%\CRYPT\LEONARDO" "%SYSTEMDRIVE%\CRYPT\LEONARDO_KEY"
&nbsp;
:: Start Mozilla Firefox
CALL :RUNONE "C:\Program Files\Mozilla Firefox\firefox.exe"
&nbsp;
:: Start Thunderbird Portable
CALL :RUNONE "L:\P\PP\putty.exe" "/MIN" -load 1
&nbsp;
:: Start Thunderbird Portable
CALL :RUNONE "L:\P\TB\ThunderbirdPortable.exe" "/MIN"
&nbsp;
:: Start Adobe Dreamweaver CS4
CALL :RUNONE "C:\Program Files\Adobe\Adobe Dreamweaver CS4\Dreamweaver.exe" "/MIN"
&nbsp;
:: Start LightScreen Portable
CALL :RUNONE "L:\P\LP\LightscreenPortable.exe" /B /B
&nbsp;
:: Start Google Chrome Portable ( GREAT to use for pandora/last.fm as its so low mem )
CALL :RUNONE "L:\P\GC\GC.exe" "/NORMAL"
&nbsp;
:: Start Adobe Photoshop CS4
CALL :RUNONE "%ProgramFiles%\Adobe\Adobe Photoshop CS4\Photoshop.exe" "/MAX"</pre>

<h3>Exit Script</h3>
<p>This is the last line executed in the Main, it forces the script to exit cleanly at this point, otherwise the functions below would all get executed.  This is what allows the use of all the functions below.  I end all my scripts MAIN with this.</p>
<pre>REM ** EXIT Script
CALL :MDYE "EOF" &amp;&amp; POPD &amp;&amp; ENDLOCAL &amp;&amp; GOTO :EOF</pre>







<h2>SCRIPT FUNCTIONS</h2>
<p>Now then, onto the MEAT of the script, all the functions.  These functions are designed for global use in other batch files, so that the only modification when you make a new batch is the above variables and main execution..  If you know much about batch files you will realize that creating these functions was a very painful process in some cases.. I freakin hate windows!  Anyway, enjoy!</p>
<h3>CRYPTMOUNT - mounts a truecrypt container and returns to CALLer. On fail, quit</h3>
<pre>REM
REM     CALL :CRYPTMOUNT "%LEONARDO%" "%LEONARDO_FILE%" "%LEONARDO_KEY%"
REM     CALL :CRYPTMOUNT "L" "%SYSTEMDRIVE%\CRYPT\LEONARDO" "%SYSTEMDRIVE%\CRYPT\LEONARDO_KEY"
REM
REM :: print the settings
REM :: CALL :MP 3 "DRIVE: %DRIVE%"&amp;&amp;CALL :MP 3 " FILE: %FILE%"&amp;&amp;CALL :MP 3 "  KEY: %KEY%"&amp;&amp;CALL :MP 3 "  VOL: %VOL%"</pre>
<pre>:CRYPTMOUNT
SET DRIVE=%~1&amp;&amp; SET FILE=%~2&amp;&amp; SET KEY=%~3&amp;&amp; SET VOL=!FILE:~0,3!
CALL :MP 1 "Mounting TrueCrypt on %DRIVE% from %FILE%"
&nbsp;
:: Check for Truecrypt or die
CALL :EXISTORQUIT "%ProgramFiles%\TrueCrypt\TrueCrypt.exe" &amp;&amp; CALL :EXISTORQUIT "%FILE%" &amp;&amp; CALL :EXISTORQUIT "%KEY%"
&nbsp;
:: checks that MOUNTVOL works and the drive containing the truecrypt container file is present or dies
MOUNTVOL %VOL% /L 2&gt;NUL | FIND "\\?\Volume{" &gt;NUL 2&gt;&amp;1
IF ERRORLEVEL 1 CALL :MDYE "%VOL% NOT FOUND"
&nbsp;
REM ** Converts G:\ to its \\?\Volume{234234}\ equivalent for greater portability
FOR /F %%i IN (&#039;MOUNTVOL %VOL% /L&#039;) DO @SET VOL=%%i%FILE:~3%
&nbsp;
:: IF the drive is already mounted then continue, otherwise try to mount
MOUNTVOL %DRIVE%:\ /L &gt;NUL 2&gt;&amp;1
IF NOT ERRORLEVEL 1 (
  CALL :MP 2 "%DRIVE% ALREADY MOUNTED" &amp;&amp; EXIT /B
) ELSE (
  START "Mounting TrueCrypt" /D"%ProgramFiles%\TrueCrypt" /MIN /B TrueCrypt.exe /c n /b /q background /h n /k %KEY% /l %DRIVE% /p /v %VOL% &amp;&amp; SLEEP 10
)
&nbsp;
:: try again in case of bad password and accidental keypress
MOUNTVOL %DRIVE%:\ /L &gt;NUL 2&gt;&amp;1
IF ERRORLEVEL 1 (START "Mounting TrueCrypt" /D"%ProgramFiles%\TrueCrypt" /MIN /B TrueCrypt.exe /c n /b /q background /h n /k %KEY% /l %DRIVE% /p /v %VOL% &amp;&amp; SLEEP 10)
&nbsp;
:: IF it still doesnt exist then quit
MOUNTVOL %DRIVE%:\ /L &gt;NUL 2&gt;&amp;1
IF ERRORLEVEL 1 CALL :MDYE "Failed to mount %FILE% on %DRIVE%"
&nbsp;
CALL :MF &amp;&amp; ENDLOCAL &amp;&amp; EXIT /B
EXIT /B</pre>




<h3>RUNONE - Starts one instance of executable after verifying it exists and is not already running.</h3>
<pre>REM     %~1 is location of executatable
REM     %~2 is optional (unless %~3 is used) START parameters
REM     %~3 is optional parameters for executable
REM
REM     CALL :RUNONE "L:\P\LP\LightscreenPortable.exe" "/MAX" "/HIDE"</pre>
<pre>:RUNONE
SETLOCAL
CALL :MP 1 "Starting %~n1"
&nbsp;
:: SLEEP FOR NICENESS, LOCAL VARS _P2 and _P3
SLEEP 2 &amp;&amp; SETLOCAL
&nbsp;
SET P=%~1
ECHO %P%|FIND " " &gt;NUL 2&gt;&amp;1
IF NOT ERRORLEVEL 1 ( PUSHD "%~dp1" &amp;&amp; SET P=%~nx1 )
&nbsp;
:: SET _P2 TO DEFAULT TO "/MIN" IF EMPTY
SET _P2=/MIN
IF NOT " %~2" == " " SET _P2=%~2
IF NOT " %~3" == " " SET _P3=%~3
IF NOT " %~4" == " " SET _P4=%~4
&nbsp;
:: CHECK THAT EXECUTABLE EXISTS
CALL :EXISTORQUIT "%~1"
&nbsp;
REM ECHO START %_P2% /D"%~dp1" %P% %_P3% %_P4%&amp;&amp; PAUSE&amp;&amp;
:: CHECK FOR EXISTING PROCESSNAME ( %~n1 is file name without ext, %~nx1 is the file name and extension. )
pslist.exe /e %~n1 &gt;NUL 2&gt;&amp;1
IF ERRORLEVEL 1 (START %_P2% /D"%~dp1" %P% %_P3% %_P4% ) ELSE (CALL :MP 2 "%~n1 already running!" )
&nbsp;
ENDLOCAL &amp;&amp; EXIT /B</pre>







<h3>ADMINRUNONE - Runs %1 with admin rights IF neccessary</h3>
<pre>:ADMINRUNONE
CALL :MP 3 "Exec %~1 as %ADMINUSER%"
&nbsp;
:: Check that file exists
CALL :EXISTORQUIT "%~1"
&nbsp;
:: test for rights to the task scheduler
:: %SYSTEMDRIVE%\WINDOWS\system32\cmd.exe /E:ON /D /Q /T:0C /C START /WAIT /MIN /B %SYSTEMDRIVE%\WINDOWS\system32\cmd.exe /E:ON /D /Q /T:0C /C %~1
AT &gt;NUL 2&gt;&amp;1
IF ERRORLEVEL 1 (
  RUNAS /noprofile /user:%USERDOMAIN%\%ADMINUSER% "%~1"
) ELSE (
  %COMSPEC% /E:ON /D /Q /T:0C /C "%~1"
)
SLEEP 2 &amp;&amp; CALL :MF &amp;&amp; EXIT /B</pre>






<h3>CHECKUSERVALID - checks that defined username equals %ADMINUSER% or %RUNUSER%, then returns to CALLer</h3>
<pre>:CHECKUSERVALID
:: EXIT IF USERNAME IS NOT DEFINED, CATCHES SYSTEM ACCOUNTS TRYING TO RUN WHEN IN GLOBAL STARTUP
IF NOT DEFINED USERNAME EXIT
&nbsp;
SETLOCAL
SET UP=no
SET _P1= %~1
SET _P2= %~2
IF NOT "%_P1%" == " " ( IF /I "%~1" == "%USERNAME%" SET UP=yes)
IF NOT "%_P1%" == " " ( IF /I "%~1" == "%USERNAME%" SET UP=yes)
IF NOT "%_P1%" == " " ( IF /I "%~1" == "%USERNAME%" SET UP=yes)
IF /I "bill" == "%USERNAME%" SET UP=yes
IF /I "newbill" == "%USERNAME%" SET UP=yes
IF /I "max" == "%USERNAME%" SET UP=yes
IF /I NOT "%UP%" == "yes" EXIT
ENDLOCAL
EXIT /B</pre>



<h3>SETPROMPT - sets prompt, then returns to CALLer</h3>
<pre>REM =   [user@MACHINE] [C:\DR\PEPPER\SCRIPTS]
REM =   &gt; REG /?</pre>
<pre>:SETPROMPT
set PROMPT=$_[%USERNAME%@%USERDOMAIN%]$S[$P]$_$M$G &amp;&amp; EXIT /B</pre>


<h3>BEEP - beeps once, then returns to CALLer</h3>
<p>The character after the echo is the actual BEL char, so unless you have my source file, you will need to copy a literal BEL char here to make it beep.</p>
<pre>:BEEP
@ECHO # &amp;&amp; EXIT /B</pre>


<h3>MSETCOLOR - SET colors for screen, then returns to CALLer</h3>
<pre>REM
REM     0 = Black       8 = Gray
REM     1 = Blue        9 = Light Blue
REM     2 = Green       A = Light Green
REM     3 = Aqua        B = Light Aqua
REM     4 = Red         C = Light Red
REM     5 = Purple      D = Light Purple
REM     6 = Yellow      E = Light Yellow
REM     7 = White       F = Bright White
REM</pre>
<pre>:MSETCOLOR
COLOR %~1 &amp;&amp; EXIT /B</pre>


<h3>MSETCONSOLE - sets the cols and lines of current screen buffer, then returns to CALLer</h3>
<pre>:MSETCONSOLE
MODE CON COLS=%~1 LINES=%~2 &amp;&amp; EXIT /B</pre>



<h3>PARAMTEST - tests params, then returns to CALLer</h3>
<pre>:PARAMTEST
ECHO. &amp;&amp; CALL :MP 1 "PARAMTEST CALLED WITH: %*" &amp;&amp; ECHO %L1%
SET _P= %~1
IF NOT "%_P%" == " " ( ECHO %%1          = %1 &amp;&amp; ECHO %%~f1        = %~f1 &amp;&amp; ECHO %%~d1        = %~d1 &amp;&amp; ECHO %%~p1        = %~p1
  ECHO %%~n1        = %~n1 &amp;&amp; ECHO %%~x1        = %~x1 &amp;&amp; ECHO %%~s1        = %~s1 &amp;&amp; ECHO %%~dp1       = %~dp1
  ECHO %%~nx1       = %~nx1 &amp;&amp; ECHO %%~$PATH:1   = %~$PATH:1 &amp;&amp; ECHO %%~dp$PATH:1 = %~dp$PATH:1 &amp;&amp; ECHO %L1% )
SET _P= %~2
IF NOT "%_P%" == " " ( ECHO %%2          = %2 &amp;&amp; ECHO %%~f2        = %~f2 &amp;&amp; ECHO %%~d2        = %~d2 &amp;&amp; ECHO %%~p2        = %~p2
  ECHO %%~n2        = %~n2 &amp;&amp; ECHO %%~x2        = %~x2 &amp;&amp; ECHO %%~s2        = %~s2 &amp;&amp; ECHO %%~dp2       = %~dp2
  ECHO %%~nx2       = %~nx2 &amp;&amp; ECHO %%~$PATH:2   = %~$PATH:2 &amp;&amp; ECHO %%~dp$PATH:2 = %~dp$PATH:2 &amp;&amp; ECHO %L1% )
SET _P= %~3
IF NOT "%_P%" == " " ( ECHO %%3          = %3 &amp;&amp; ECHO %%~f3        = %~f3 &amp;&amp; ECHO %%~d3        = %~d3 &amp;&amp; ECHO %%~p3        = %~p3
  ECHO %%~n3        = %~n3 &amp;&amp; ECHO %%~x3        = %~x3 &amp;&amp; ECHO %%~s3        = %~s3 &amp;&amp; ECHO %%~dp3       = %~dp3
  ECHO %%~nx3       = %~nx3 &amp;&amp; ECHO %%~$PATH:3   = %~$PATH:3 &amp;&amp; ECHO %%~dp$PATH:3 = %~dp$PATH:3 &amp;&amp; ECHO %L1% )
SET _P= %~4
IF NOT "%_P%" == " " ( ECHO %%4          = %4 &amp;&amp; ECHO %%~f4        = %~f4 &amp;&amp; ECHO %%~d4        = %~d4 &amp;&amp; ECHO %%~p4        = %~p4
  ECHO %%~n4        = %~n4 &amp;&amp; ECHO %%~x4        = %~x4 &amp;&amp; ECHO %%~s4        = %~s4 &amp;&amp; ECHO %%~dp4       = %~dp4
  ECHO %%~nx4       = %~nx4 &amp;&amp; ECHO %%~$PATH:4   = %~$PATH:4 &amp;&amp; ECHO %%~dp$PATH:4 = %~dp$PATH:4 &amp;&amp; ECHO %L1% )
SET _P= %~5
IF NOT "%_P%" == " " ( ECHO %%5          = %5 &amp;&amp; ECHO %%~f5        = %~f5 &amp;&amp; ECHO %%~d5        = %~d5 &amp;&amp; ECHO %%~p5        = %~p5
  ECHO %%~n5        = %~n5 &amp;&amp; ECHO %%~x5        = %~x5 &amp;&amp; ECHO %%~s5        = %~s5 &amp;&amp; ECHO %%~dp5       = %~dp5
  ECHO %%~nx5       = %~nx5 &amp;&amp; ECHO %%~$PATH:5   = %~$PATH:5 &amp;&amp; ECHO %%~dp$PATH:5 = %~dp$PATH:5 &amp;&amp; ECHO %L1% )
SET _P= %~6
IF NOT "%_P%" == " " ( ECHO %%6          = %6 &amp;&amp; ECHO %%~f6        = %~f6 &amp;&amp; ECHO %%~d6        = %~d6 &amp;&amp; ECHO %%~p6        = %~p6
  ECHO %%~n6        = %~n6 &amp;&amp; ECHO %%~x6        = %~x6 &amp;&amp; ECHO %%~s6        = %~s6 &amp;&amp; ECHO %%~dp6       = %~dp6
  ECHO %%~nx6       = %~nx6 &amp;&amp; ECHO %%~$PATH:6   = %~$PATH:6 &amp;&amp; ECHO %%~dp$PATH:6 = %~dp$PATH:6 &amp;&amp; ECHO %L1% )
SET _P= %~7
IF NOT "%_P%" == " " ( ECHO %%7          = %7 &amp;&amp; ECHO %%~f7        = %~f7 &amp;&amp; ECHO %%~d7        = %~d7 &amp;&amp; ECHO %%~p7        = %~p7
  ECHO %%~n7        = %~n7 &amp;&amp; ECHO %%~x7        = %~x7 &amp;&amp; ECHO %%~s7        = %~s7 &amp;&amp; ECHO %%~dp7       = %~dp7
  ECHO %%~nx7       = %~nx7 &amp;&amp; ECHO %%~$PATH:7   = %~$PATH:7 &amp;&amp; ECHO %%~dp$PATH:7 = %~dp$PATH:7 &amp;&amp; ECHO %L1% )
SLEEP 3
CALL :MF
EXIT /B</pre>




<h3>PARAMTESTHELP - show params help, then returns to CALLer</h3>
<pre>:PARAMTESTHELP
ECHO %%~1 Expands %%1 and removes any surrounding quotation marks
ECHO %%~f1 Expands %%1 to a fully qualified path name.
ECHO %%~d1 Expands %%1 to a drive letter.
ECHO %%~p1 Expands %%1 to a path.
ECHO %%~n1 Expands %%1 to a file name.
ECHO %%~x1 Expands %%1 to a file extension.
ECHO %%~s1 Expanded path contains short names only.
ECHO %%~a1 Expands %%1 to file attributes.
ECHO %%~t1 Expands %%1 to date and time of file.
ECHO %%~z1 Expands %%1 to size of file.
ECHO %%~dp1 Expands %%1 to a drive letter and path.
ECHO %%~nx1 Expands %%1 to a file name and extension.
ECHO %%~ftza1 Expands %%1 to a dir-like output line.
ECHO %%~$PATH:1 Searches the dirs in PATH expanding %%1 to fully qualified name of first found. If var name isn&#039;t defined or the files not found, expands to empty string.
ECHO %%~dp$PATH:1 Searches the directories listed in the PATH environment variable for %%1 and expands to the drive letter and path of the first one found.
CALL :MF
EXIT /B</pre>







<h3>EXAMINEFILE - FINDs useful strings in file, then returns to CALLer</h3>
<pre>:EXAMINEFILE
CALL :MP 1 "Examine File %~1"
CALL :EXISTORQUIT "%~1"
STRINGS "%~1" | FINDSTR /R /C:"[A-Z][A-Z]\="
CALL :MF
EXIT /B</pre>


<h3>ADMINSHELL - sets prompt, then returns to CALLer</h3>
<pre>:ADMINSHELL
CALL :MP 1 "Creating Admin Shell"
CALL :EXISTORQUIT "%SYSTEMROOT%\system32\runas.exe"
START %SYSTEMROOT%\system32\runas.exe /profile /savecred /user:%ADMINUSER% "%COMSPEC% /T:0C /E:ON /F:ON /K cmd.exe /K cd C:\CRYPT\BIN"
CALL :MF
EXIT /B</pre>


<h3>EXISTORQUIT - checks %~1 exists, IF it does returns to CALLer, otherwise, quit</h3>
<pre>:EXISTORQUIT
:: CALL :MP 1 "Checking for %~1"
IF NOT EXIST "%~1" CALL :MDYE "%~1 NOT FOUND"
EXIT /B</pre>


<h3>RR - IF file %1 EXISTs then :MT "Removing %1" then :MF, then ( or IF %1 not EXISTs)  returns to CALLer</h3>
<pre>:RR
CALL :MP 1 "Removing %~1"
IF EXIST "%~1" ERASE /q "%~1"
CALL :MF &amp;&amp; EXIT /B</pre>








<h3>LOCKDOWN  - locks workstation, then returns to CALLer (pointless)</h3>
<pre>:LOCKDOWN
RUNDLL32 USER32.DLL,LockWorkStation &amp;&amp; EXIT /B</pre>



<h3>SHUTDOWNIN - initiates shutdown, then returns to CALLer (pointless)</h3>
<pre>REM shutdown /a aborts</pre>
<pre>:SHUTDOWNIN
SHUTDOWN -r -t "%~1" &amp;&amp; EXIT /B</pre>



<h3>LISTSERVICES - lists services, then returns to CALLer</h3>
<pre>:LISTSERVICES
SC query state= all type= all | FOR /F "tokens=2" %%i IN (&#039;FIND /I "SERVICE_NAME"&#039;) DO @ECHO %%i
SC query | FOR /F "tokens=2" %%i IN (&#039;FIND /I "SERVICE_NAME"&#039;) DO @ECHO %%i
EXIT /B</pre>




<h3>TASKS - Advanced Tasklisting</h3>
<pre>:TASKS
SET _P=%~1
SET _PP= %~1
IF "%_PP%" == " " EXIT /B
&nbsp;
REM SORTABLES
IF /I "%_P%" == "pid" ( tasklist.exe /V /NH | SORT /+29 &amp;&amp; EXIT /B )
IF /I "%_P%" == "size" ( tasklist.exe /V /NH | SORT /+59 &amp;&amp; EXIT /B )
IF /I "%_P%" == "user" ( tasklist.exe /V /NH | SORT /+89 &amp;&amp; EXIT /B )
IF /I "%_P%" == "time" ( tasklist.exe /V /NH | SORT /+138 &amp;&amp; EXIT /B )
IF /I "%_P%" == "window" ( tasklist.exe /V /NH | SORT /+152 &amp;&amp; EXIT /B )
&nbsp;
REM FILTERS
IF /I "%_P%" == "image" ( tasklist.exe /V /NH /FI "IMAGENAME eq %~2" &amp;&amp; EXIT /B )
IF /I "%_P%" == "username" ( tasklist.exe /V /NH /FI "USERNAME eq %~2" &amp;&amp; EXIT /B )
IF /I "%_P%" == "running" ( tasklist.exe /V /NH /FI "STATUS eq Running" &amp;&amp; EXIT /B )
IF /I "%_P%" == "status" ( tasklist.exe /V /NH /FI "STATUS eq %~2" &amp;&amp; EXIT /B )
CALL :MF
EXIT /B</pre>



<h3>SPEAK - Speak text</h3>
<pre>:SPEAK
REM ECHO "%~1"
nircmd.exe speak text "%~1" 5 60 &amp;&amp; EXIT /B</pre>



<h3>MF - SLEEPs for 1 second, then prints out completed message, followed by 2 blank lines, then returns to CALLer</h3>
<pre>:MF
SLEEP 1 &amp;&amp; ECHO  [COMPLETED] &amp;&amp; ECHO. &amp;&amp; ECHO. &amp;&amp; EXIT /B</pre>


<h3>MM - prints blank line, L1, changes title of the interpreter window to %~1, prints >>> %~1..., L2, blank line, then returns to CALLer</h3>
<pre>:MM
SLEEP 1 &amp;&amp; ECHO. &amp;&amp; ECHO %L1% &amp;&amp; title +++ %~1... &amp;&amp; ECHO %P1% %~1... &amp;&amp; ECHO %L2% &amp;&amp; ECHO. &amp;&amp; EXIT /B</pre>


<h3>MT - prints blank line, L1, changes title of the interpreter window to %~1, prints >>> %~1..., L2, blank line, then returns to CALLer</h3>
<pre>:MT
CALL :MM "%~1" &amp;&amp; CALL :SPEAK "%~1" &amp;&amp; EXIT /B</pre>


<h3>MP - Print Output, then returns to CALLer</h3>
<pre>:MP
IF "%~1" == "1" ECHO %P1% %~2 &amp;&amp; EXIT /B
IF "%~1" == "2" ECHO %P2% %~2 &amp;&amp; ECHO. &amp;&amp; EXIT /B
IF "%~1" == "3" ECHO %P3% %~2 &amp;&amp; EXIT /B
EXIT /B</pre>


<h3>MP3 - ECHO %~1, speak %~1 with nircmd.exe, then returns to CALLer</h3>
<pre>:MP3
CALL :MP 1 "%~1" &amp;&amp; CALL :SPEAK "%~1" &amp;&amp; EXIT /B</pre>



<h3>MDYE - exit script with message %~1, then returns to CALLer</h3>
<pre>:MDYE
SETLOCAL
SET _M= %~1
IF NOT "%_M%" == " " SET _M=REASON: %~1
CALL :MP 1 "EXITING SCRIPT...  %_M%" &amp;&amp; ECHO. &amp;&amp; ECHO.
ENDLOCAL &amp;&amp; EXIT /B</pre>



<h3>MKILL - exit cmd processor with message %~1</h3>
<pre>:MKILL
SETLOCAL
SET _M= %~1
IF NOT "%_M%" == " " SET _M=REASON: %~1
ECHO. &amp;&amp; ECHO. &amp;&amp; CALL :MP 1 "EXITING CMD WINDOW IN 3 SECONDS...  %_M%" &amp;&amp; ECHO. &amp;&amp; ECHO. &amp;&amp; SLEEP 3
ENDLOCAL &amp;&amp; EXIT &amp;&amp; EXIT &amp;&amp; EXIT</pre>



<h2>EOF: Thoughts</h2>
<p>So what did you think?  I have around 20 batch scripts that utilize these and other functions to do all sorts of cool things.  One takes a screenshot of my desktop every 10 minutes and saves it for a real-cool archive of my activity.  Another lets me edit a boot.ini file with 1 command.. And another runs when I insert a USB drive to automatically mount a truecrypt volume and create SSH tunnels in the background by using Plink, AT, and the runas.exe command.</p>
<p>If you want to program, please use linux...  If you need to write a Windows batch file, I hope this helps.</p><p><a href="http://www.askapache.com/windows/advanced-batch-scripting.html"></a><a href="http://www.askapache.com/windows/advanced-batch-scripting.html">Advanced Windows Batch File Scripting</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/windows/advanced-batch-scripting.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Mod_Rewrite Variables Cheatsheet</title>
		<link>http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html</link>
		<comments>http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html#comments</comments>
		<pubDate>Tue, 03 Aug 2010 15:05:23 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[cheatsheet]]></category>
		<category><![CDATA[mod_rewrite]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=1280</guid>
		<description><![CDATA[<p><a class="IFL hs hs21" href="http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html" title="mod_rewrite cheatsheet for .htaccess rewrites"></a>We've figured out what <a href="http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html">mod_rewrite variables</a> look like, a cheatsheet of the actual value. <br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html"></a><a href="http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html"><cite>AskApache.com</cite></a></p><p><a class="IFL hs hs21" href="http://uploads.askapache.com/2008/09/warningiconimg.jpg" title="mod_rewrite cheatsheet for .htaccess rewrites"></a>We've figured out what <a href="http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html">mod_rewrite variables</a> look like so we can create rewriterules and condition patterns based on the actual value.  This cheatsheet is where we'll lay them all out for quick reference.  This cheatsheet changed my life, way more than 301 redirect htaccess.<br class="C" /></p>

<h2>mod_rewrite Variable Value Cheat-Sheet</h2>
<p>Jump to: <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#API_VERSION">API_VERSION</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#AUTH_TYPE">AUTH_TYPE</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#CONTENT_LENGTH">CONTENT_LENGTH</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#CONTENT_TYPE">CONTENT_TYPE</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#DOCUMENT_ROOT">DOCUMENT_ROOT</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#GATEWAY_INTERFACE">GATEWAY_INTERFACE</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTPS">HTTPS</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_ACCEPT">HTTP_ACCEPT</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_ACCEPT_CHARSET">HTTP_ACCEPT_CHARSET</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_ACCEPT_ENCODING">HTTP_ACCEPT_ENCODING</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_ACCEPT_LANGUAGE">HTTP_ACCEPT_LANGUAGE</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_CACHE_CONTROL">HTTP_CACHE_CONTROL</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_CONNECTION">HTTP_CONNECTION</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_COOKIE">HTTP_COOKIE</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_FORWARDED">HTTP_FORWARDED</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_HOST">HTTP_HOST</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_KEEP_ALIVE">HTTP_KEEP_ALIVE</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_PROXY_CONNECTION">HTTP_PROXY_CONNECTION</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_REFERER">HTTP_REFERER</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_USER_AGENT">HTTP_USER_AGENT</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#IS_SUBREQ">IS_SUBREQ</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#ORIG_PATH_INFO">ORIG_PATH_INFO</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#ORIG_PATH_TRANSLATED">ORIG_PATH_TRANSLATED</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#ORIG_SCRIPT_FILENAME">ORIG_SCRIPT_FILENAME</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#ORIG_SCRIPT_NAME">ORIG_SCRIPT_NAME</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#PATH">PATH</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#PATH_INFO">PATH_INFO</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#PHP_SELF">PHP_SELF</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#QUERY_STRING">QUERY_STRING</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REDIRECT_QUERY_STRING">REDIRECT_QUERY_STRING</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REDIRECT_REMOTE_USER">REDIRECT_REMOTE_USER</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REDIRECT_STATUS">REDIRECT_STATUS</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REDIRECT_URL">REDIRECT_URL</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REMOTE_ADDR">REMOTE_ADDR</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REMOTE_HOST">REMOTE_HOST</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REMOTE_IDENT">REMOTE_IDENT</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REMOTE_PORT">REMOTE_PORT</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REMOTE_USER">REMOTE_USER</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REQUEST_FILENAME">REQUEST_FILENAME</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REQUEST_METHOD">REQUEST_METHOD</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REQUEST_TIME">REQUEST_TIME</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REQUEST_URI">REQUEST_URI</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SCRIPT_FILENAME">SCRIPT_FILENAME</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SCRIPT_GROUP">SCRIPT_GROUP</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SCRIPT_NAME">SCRIPT_NAME</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SCRIPT_URI">SCRIPT_URI</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SCRIPT_URL">SCRIPT_URL</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SCRIPT_USER">SCRIPT_USER</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SERVER_ADDR">SERVER_ADDR</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SERVER_ADMIN">SERVER_ADMIN</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SERVER_NAME">SERVER_NAME</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SERVER_PORT">SERVER_PORT</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SERVER_PROTOCOL">SERVER_PROTOCOL</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SERVER_SIGNATURE">SERVER_SIGNATURE</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SERVER_SOFTWARE">SERVER_SOFTWARE</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_CIPHER">SSL_CIPHER</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_CIPHER_ALGKEYSIZE">SSL_CIPHER_ALGKEYSIZE</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_CIPHER_EXPORT">SSL_CIPHER_EXPORT</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_CIPHER_USEKEYSIZE">SSL_CIPHER_USEKEYSIZE</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_CLIENT_VERIFY">SSL_CLIENT_VERIFY</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_PROTOCOL">SSL_PROTOCOL</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_A_KEY">SSL_SERVER_A_KEY</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_A_SIG">SSL_SERVER_A_SIG</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_CERT">SSL_SERVER_CERT</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_I_DN">SSL_SERVER_I_DN</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_I_DN_C">SSL_SERVER_I_DN_C</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_I_DN_CN">SSL_SERVER_I_DN_CN</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_I_DN_L">SSL_SERVER_I_DN_L</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_I_DN_O">SSL_SERVER_I_DN_O</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_I_DN_OU">SSL_SERVER_I_DN_OU</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_I_DN_ST">SSL_SERVER_I_DN_ST</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_M_SERIAL">SSL_SERVER_M_SERIAL</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_M_VERSION">SSL_SERVER_M_VERSION</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_S_DN">SSL_SERVER_S_DN</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_S_DN_CN">SSL_SERVER_S_DN_CN</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_S_DN_O">SSL_SERVER_S_DN_O</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_S_DN_OU">SSL_SERVER_S_DN_OU</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_V_END">SSL_SERVER_V_END</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_V_START">SSL_SERVER_V_START</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SESSION_ID">SSL_SESSION_ID</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_VERSION_INTERFACE">SSL_VERSION_INTERFACE</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_VERSION_LIBRARY">SSL_VERSION_LIBRARY</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#THE_REQUEST">THE_REQUEST</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#TIME">TIME</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#TIME_DAY">TIME_DAY</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#TIME_HOUR">TIME_HOUR</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#TIME_MIN">TIME_MIN</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#TIME_MON">TIME_MON</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#TIME_SEC">TIME_SEC</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#TIME_WDAY">TIME_WDAY</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#TIME_YEAR">TIME_YEAR</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#TZ">TZ</a>, <a href="/htaccess/mod_rewrite-variables-cheatsheet.html#UNIQUE_ID">UNIQUE_ID</a></p>
<dl class="dl1">
<dt><a id="API_VERSION"></a><br />API_VERSION</a>: <code>20020903:12</code></dt>
<dd><pre>RewriteCond %{API_VERSION} ^(.*)$
RewriteRule .* http://www.askapache.com?API_VERSION=%1 [R=307,L]
</pre></dd>
<dt><a id="AUTH_TYPE"></a><br />AUTH_TYPE</a>: <code>Digest</code></dt>
<dd><pre>RewriteRule .* - [E=IN_AUTH_TYPE:%{AUTH_TYPE}]
RequestHeader set AUTH_TYPE "%{IN_AUTH_TYPE}e"</pre></dd>
<dt><a id="CACHE_CONTROL"></a><br />CACHE_CONTROL</a>: <code>max-age=0</code></dt>
<dd><pre>RewriteCond %{ENV:CACHE_CONTROL} no-cache [NC]
RewriteRule . %{REQUEST_URI}?nocache [L]</pre></dd>
<dt><a id="CONNECTION"></a><br />CONNECTION</a>: <code>keep-alive</code></dt><dd></dd>
<dt><a id="CONTENT_LENGTH"></a><br />CONTENT_LENGTH</a>: <code>(null)</code></dt>
<dd><pre>RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP:Content-Length}%{CONTENT_LENGTH} ^$
RewriteRule .* - [F,NS,L]</pre></dd>
<dt><a id="CONTENT_TYPE"></a><br />CONTENT_TYPE</a>: <code>(null)</code></dt><dd></dd>
<dt><a id="DOCUMENT_ROOT"></a><br />DOCUMENT_ROOT</a>: <code>/home/webroot/askapache.com</code></dt>
<dd><pre>RewriteCond %{DOCUMENT_ROOT}/cache%{REQUEST_URI}/index.html -f
RewriteRule . /cache%{REQUEST_URI}/index.html</pre></dd>
<dt><a id="HOST"></a><br />HOST</a>: <code>www.askapache.com</code></dt>
<dd><pre>RewriteCond %{HTTP_HOST} !^www\.askapache\.com$ [NC]
RewriteRule . http://www.askapache.com%{REQUEST_URI} [R=301,L]</pre></dd>
<dt><a id="HTTP"></a><br />HTTP</a>:</dt>
<dd><pre>RewriteCond %{HTTP:Accept-Encoding} gzip [NC]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.gz -f
RewriteRule . %{REQUEST_URI}.gz [L]</pre></dd>
<dt><a id="HTTPS"></a><br />HTTPS</a>: <code>off</code></dt>
<dd><pre>RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]</pre></dd>
<dt><a id="HTTP_ACCEPT"></a><br />HTTP_ACCEPT</a>: <code>text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8</code></dt><dd></dd>
<dt><a id="HTTP_COOKIE"></a><br />HTTP_COOKIE</a>: <code>__qca=1176541205adf28-5553185; ASKAPACHEID=fdadfa4f33e62a878468; __utmc=1df3893</code></dt>
<dd><pre>RewriteCond %{HTTP_COOKIE} ^.*autostart=on.*$
RewriteRule ^(.*)\.swf$ /$1\?autostart=true [NE,L]</pre></dd>
<dt><a id="HTTP_HOST"></a><br />HTTP_HOST</a>: <code>www.askapache.com</code></dt><dd></dd>
<dt><a id="HTTP_REFERER"></a><br />HTTP_REFERER</a>: <code>http://www.askapache.com/pro/mod_rewrite/catch.php?k=i</code></dt>
<dd><pre>RewriteCond %{HTTP_REFERER} badhost [NC]
RewriteRule . - [F]</pre></dd>
<dt><a id="HTTP_USER_AGENT"></a><br />HTTP_USER_AGENT</a>: <code>Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Firefox/3.0.1</code></dt>
<dd><pre>RewriteCond %{HTTP_USER_AGENT} ^.*(Android|2.0\ MMP|240x320|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|hiptop|IEMobile|iPhone).*$ [NC]
RewriteRule ^(.+)$ /mobile/$1 [L]</pre></dd>
<dt><a id="IS_SUBREQ"></a><br />IS_SUBREQ</a>: <code>false</code></dt><dd></dd>
<dt><a id="KEEP_ALIVE"></a><br />KEEP_ALIVE</a>: <code>300</code></dt><dd></dd>
<dt><a id="PATH"></a><br />PATH</a>: <code>/bin:/usr/bin:/sbin:/usr/sbin</code></dt><dd></dd>
<dt><a id="QUERY_STRING"></a><br />QUERY_STRING</a>: <code>k=i</code></dt>
<dd><pre>RewriteCond %{QUERY_STRING} showtime [NC]
RewriteCond T:%{TIME}_TY:%{TIME_YEAR}_TMO:%{TIME_MON}_TWD:%{TIME_WDAY}_TD:%{TIME_DAY}_TH:%{TIME_HOUR}_TMI:%{TIME_MIN}_TS:%{TIME_SEC} ^(.*)$
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI}?time=%1 [R,L]</pre></dd>
<dt><a id="REMOTE_ADDR"></a><br />REMOTE_ADDR</a>: <code>22.162.134.211</code></dt>
<dd><pre>RewriteCond %{REMOTE_ADDR} !^22\.162\.134\.211$
RewriteRule . http://www.askapache.com/maintenance-in-progress.html [R=307,L]</pre></dd>
<dt><a id="REMOTE_HOST"></a><br />REMOTE_HOST</a>: <code>22.162.134.211</code></dt><dd></dd>
<dt><a id="REMOTE_PORT"></a><br />REMOTE_PORT</a>: <code>4220</code></dt><dd></dd>
<dt><a id="REMOTE_USER"></a><br />REMOTE_USER</a>: <code>askapache</code></dt>
<dd><pre>RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]</pre></dd>
<dt><a id="REQUEST_FILENAME"></a><br />REQUEST_FILENAME</a>: <code>/home/webroot/askapache.com/pro/mod_rewrite/index.php</code></dt><dd></dd>
<dt><a id="REQUEST_METHOD"></a><br />REQUEST_METHOD</a>: <code>GET</code></dt>
<dd><pre>RewriteCond %{REQUEST_METHOD} !^(POST|GET|HEAD|PROPFIND|OPTIONS)$
RewriteRule .* - [F,L]</pre></dd>
<dt><a id="REQUEST_PROTOCOL"></a><br />REQUEST_PROTOCOL</a>: <code>HTTP/1.1</code></dt>
<dd><pre>RewriteCond %{REQUEST_PROTOCOL} !^HTTP/(0\.9|1\.[01])$
RewriteRule . [F,L]</pre></dd>
<dt><a id="REQUEST_URI"></a><br />REQUEST_URI</a>: <code>/pro/mod_rewrite/index.php</code></dt>
<dd><pre>RewriteCond %{REQUEST_URI} ^(robots\.txt|favicon\|ico)$ [NC]
RewriteRule . - [S=1]
RewriteCond %{HTTP_HOST} ^www
RewriteRule .* http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]</pre></dd>
<dt><a id="SCRIPT_FILENAME"></a><br />SCRIPT_FILENAME</a>: <code>/home/webroot/askapache.com/pro/mod_rewrite/index.php</code></dt><dd></dd>
<dt><a id="SCRIPT_GROUP"></a><br />SCRIPT_GROUP</a>: <code>daemong</code></dt><dd></dd>
<dt><a id="SCRIPT_URI"></a><br />SCRIPT_URI</a>: <code>http://www.askapache.com/pro/mod_rewrite/index.php</code></dt><dd></dd>
<dt><a id="SCRIPT_URL"></a><br />SCRIPT_URL</a>: <code>/pro/mod_rewrite/index.php</code></dt><dd></dd>
<dt><a id="SCRIPT_USER"></a><br />SCRIPT_USER</a>: <code>askapache</code></dt><dd></dd>
<dt><a id="SERVER_ADDR"></a><br />SERVER_ADDR</a>: <code>208.113.134.190</code></dt><dd></dd>
<dt><a id="SERVER_ADMIN"></a><br />SERVER_ADMIN</a>: <code>webmaster@askapache.com</code></dt><dd></dd>
<dt><a id="SERVER_NAME"></a><br />SERVER_NAME</a>: <code>www.askapache.com</code></dt><dd></dd>
<dt><a id="SERVER_PORT"></a><br />SERVER_PORT</a>: <code>80</code></dt><dd></dd>
<dt><a id="SERVER_PROTOCOL"></a><br />SERVER_PROTOCOL</a>: <code>HTTP/1.1</code></dt><dd></dd>
<dt><a id="SERVER_SOFTWARE"></a><br />SERVER_SOFTWARE</a>: <code>Apache/2.0.61 (Unix) PHP/5.5 OpenSSL/0.9.7e</code></dt><dd></dd>
<dt><a id="SSL_CIPHER"></a><br />SSL_CIPHER</a>: <code>DHE-RSA-AES256-SHA</code></dt><dd></dd>
<dt><a id="SSL_CIPHER_ALGKEYSIZE"></a><br />SSL_CIPHER_ALGKEYSIZE</a>: <code>256</code></dt><dd></dd>
<dt><a id="SSL_CIPHER_EXPORT"></a><br />SSL_CIPHER_EXPORT</a>: <code>false</code></dt><dd></dd>
<dt><a id="SSL_CIPHER_USEKEYSIZE"></a><br />SSL_CIPHER_USEKEYSIZE</a>: <code>256</code></dt><dd></dd>
<dt><a id="SSL_CLIENT_VERIFY"></a><br />SSL_CLIENT_VERIFY</a>: <code>NONE</code></dt><dd></dd>
<dt><a id="SSL_PROTOCOL"></a><br />SSL_PROTOCOL</a>: <code>TLSv1</code></dt><dd></dd>
<dt><a id="SSL_SERVER_A_KEY"></a><br />SSL_SERVER_A_KEY</a>: <code>rsaEncryption</code></dt><dd></dd>
<dt><a id="SSL_SERVER_A_SIG"></a><br />SSL_SERVER_A_SIG</a>: <code>sha1WithRSAEncryption</code></dt><dd></dd>
<dt><a id="SSL_SERVER_CERT"></a><br />SSL_SERVER_CERT</a>: <code>-----BEGIN CERTIFICATE----- ... MIIFkTC ... -----END CERTIFICATE-----</code></dt><dd></dd>
<dt><a id="SSL_SERVER_I_DN"></a><br />SSL_SERVER_I_DN</a>: <code>/C=US/ST=Arizona/L=Scottsdale/O=Starfield Technologies, Inc./OU=http://certificates.starfieldtech.com/repository/CN=Starfield Secure Certification Authority/serialNumber=10688435</code></dt><dd></dd>
<dt><a id="SSL_SERVER_I_DN_C"></a><br />SSL_SERVER_I_DN_C</a>: <code>US</code></dt><dd></dd>
<dt><a id="SSL_SERVER_I_DN_CN"></a><br />SSL_SERVER_I_DN_CN</a>: <code>Starfield Secure Certification Authority</code></dt><dd></dd>
<dt><a id="SSL_SERVER_I_DN_L"></a><br />SSL_SERVER_I_DN_L</a>: <code>Scottsdale</code></dt><dd></dd>
<dt><a id="SSL_SERVER_I_DN_O"></a><br />SSL_SERVER_I_DN_O</a>: <code>Starfield Technologies, Inc.</code></dt><dd></dd>
<dt><a id="SSL_SERVER_I_DN_OU"></a><br />SSL_SERVER_I_DN_OU</a>: <code>http://certificates.starfieldtech.com/repository</code></dt><dd></dd>
<dt><a id="SSL_SERVER_I_DN_ST"></a><br />SSL_SERVER_I_DN_ST</a>: <code>Arizona</code></dt><dd></dd>
<dt><a id="SSL_SERVER_M_SERIAL"></a><br />SSL_SERVER_M_SERIAL</a>: <code>042840B88A2352</code></dt><dd></dd>
<dt><a id="SSL_SERVER_M_VERSION"></a><br />SSL_SERVER_M_VERSION</a>: <code>3</code></dt><dd></dd>
<dt><a id="SSL_SERVER_S_DN"></a><br />SSL_SERVER_S_DN</a>: <code>/O=www.askapache.com/OU=Domain Control Validated/CN=www.askapache.com</code></dt><dd></dd>
<dt><a id="SSL_SERVER_S_DN_CN"></a><br />SSL_SERVER_S_DN_CN</a>: <code>www.askapache.com</code></dt><dd></dd>
<dt><a id="SSL_SERVER_S_DN_O"></a><br />SSL_SERVER_S_DN_O</a>: <code>www.askapache.com</code></dt><dd></dd>
<dt><a id="SSL_SERVER_S_DN_OU"></a><br />SSL_SERVER_S_DN_OU</a>: <code>Domain Control Validated</code></dt><dd></dd>
<dt><a id="SSL_SERVER_V_END"></a><br />SSL_SERVER_V_END</a>: <code>Jul 14 16:53:43 2012 GMT</code></dt><dd></dd>
<dt><a id="SSL_SERVER_V_START"></a><br />SSL_SERVER_V_START</a>: <code>Jul 14 20:25:17 2010 GMT</code></dt><dd></dd>
<dt><a id="SSL_SESSION_ID"></a><br />SSL_SESSION_ID</a>: <code>4184083DD1C74547553018174950D88987BD7ED03CE54EBB6638539C34814376</code></dt><dd></dd>
<dt><a id="SSL_VERSION_INTERFACE"></a><br />SSL_VERSION_INTERFACE</a>: <code>mod_ssl/2.2.16</code></dt><dd></dd>
<dt><a id="SSL_VERSION_LIBRARY"></a><br />SSL_VERSION_LIBRARY</a>: <code>OpenSSL/0.9.8e-fips-rhel5</code></dt><dd></dd>
<dt><a id="THE_REQUEST"></a><br />THE_REQUEST</a>: <code>GET /pro/mod_rewrite/index.php?k=i HTTP/1.1</code></dt>
<dd><pre>RewriteCond %{THE_REQUEST} ^(GET|POST)\ /.*\?(s|search)=(.+)\ HTTP/ [NC]
RewriteRule .* http://www.askapache.com/search/%3/? [R=302,L,NE]</pre></dd>
<dt><a id="TIME"></a><br />TIME</a>: <code>20080915152142</code></dt>
<dd><pre>RewriteCond %{QUERY_STRING} showtime [NC]
RewriteCond T:%{TIME}_TY:%{TIME_YEAR}_TMO:%{TIME_MON}_TWD:%{TIME_WDAY}_TD:%{TIME_DAY}_TH:%{TIME_HOUR}_TMI:%{TIME_MIN}_TS:%{TIME_SEC} ^(.*)$
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI}?time=%1 [R,L]</pre></dd>
<dt><a id="TIME_DAY"></a><br />TIME_DAY</a>: <code>15</code></dt><dd></dd>
<dt><a id="TIME_HOUR"></a><br />TIME_HOUR</a>: <code>15</code></dt><dd></dd>
<dt><a id="TIME_MIN"></a><br />TIME_MIN</a>: <code>21</code></dt><dd></dd>
<dt><a id="TIME_MON"></a><br />TIME_MON</a>: <code>09</code></dt><dd></dd>
<dt><a id="TIME_SEC"></a><br />TIME_SEC</a>: <code>42</code></dt><dd></dd>
<dt><a id="TIME_WDAY"></a><br />TIME_WDAY</a>: <code>1</code></dt><dd></dd>
<dt><a id="TIME_YEAR"></a><br />TIME_YEAR</a>: <code>2008</code></dt><dd></dd>
<dt><a id="UNIQUE_ID"></a><br />UNIQUE_ID</a>: <code>qOr5tEBvcm8AAE-VoiUAAAAQ</code></dt><dd></dd>
</dl>

<p>This article is meant to prepare us for the advanced mod_rewrite examples that are soon to be published.  The upcoming article is going to be examples using <a href="http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html">mod_rewrite</a> to achieve some crazy stuff...  Here the focus is on identifying mod_rewrite variables and defining the limits of the module by checking the <a href='http://www.askapache.com/servers/mod_rewrite.c.html'>mod_rewrite source code</a>.<br class="C" /></p>


<p class="cnote">For a broader mod_rewrite cheat sheet, check this <a href="http://www.addedbytes.com/apache/mod_rewrite-cheat-sheet/">printable</a> cheat sheet.</p>


<h2>Directives in Mod_Rewrite</h2>
<dl>
<dt>RewriteEngine</dt>
<dd><pre>RewriteEngine on|off</pre> On or Off to enable or disable (default) the whole rewriting engine</dd>
<dt>RewriteOptions</dt>
<dd><pre>RewriteOptions Options</pre> List of option strings to set</dd>

<dt>RewriteBase</dt>
<dd><pre>RewriteBase URL-path</pre> the base URL of the per-directory context
<dt>RewriteCond</dt>
<dd><pre>RewriteCond TestString CondPattern</pre> an input string and a to be applied regexp-pattern
<dt>RewriteRule</dt>
<dd><pre>RewriteRule Pattern Substitution [flags]</pre> an URL-applied regexp-pattern and a substitution URL
<dt>RewriteMap</dt>
<dd><pre>RewriteMap MapName MapType:MapSource</pre> a mapname and a filename
<dt>RewriteLock</dt>
<dd><pre>RewriteLock file-path</pre> the filename of a lockfile used for inter-process synchronization
<dt>RewriteLog</dt>
<dd><pre>RewriteLog file-path</pre> the filename of the rewriting logfile
<dt>RewriteLogLevel</dt>
<dd><pre>RewriteLogLevel Level</pre> the level of the rewriting logfile verbosity (0=none, 1=std, .., 9=max)
</dl>



<h2>RewriteRule Flags</h2>
<dl>
<dt><abbr title="Chain">C</abbr></dt>
<dd>Using the [Chain], or [C] flag, allows you to indicate that several rules should be chained together as a single logical transation. This is usually used when a transformation is sufficiently complicated to warrant breaking into several smaller steps.</dd>
<dt><abbr title="Cookie">CO</abbr></dt>
<dd><pre>cookie|CO=Name:Value:Domain[:Lifetime[:Path]]</pre><br />
This sets a cookie on the client's browser. The cookie's name is specified by NAME and the value is VAL. The domain field is the domain of the cookie, such as '.apache.org',the optional lifetime is the lifetime of the cookie in minutes, and the optional path is the path of the cookie.</dd>
<dt><abbr title="Env">E</abbr></dt>
<dd><pre>&#039;env|E=VAR:VAL&#039; (set environment variable)</pre><br />
RewriteRule (root|cmd)\.exe - [E=worm:nimda]
</dd>
<dt><abbr title="Forbidden">F</abbr></dt>
<dd><pre>&#039;forbidden|F&#039; (force URL to be forbidden)</pre><br /></dd>
<dt><abbr title="Gone">G</abbr></dt>
<dd><pre>&#039;gone|G&#039; (force URL to be gone)</pre><br /></dd>
<dt><abbr title="Handler">H</abbr></dt>
<dd><pre>&#039;handler|H=Content-handler&#039; (force Content handler)</pre><br /></dd>
<dt><abbr title="Last">L</abbr></dt>
<dd><pre>&#039;last|L&#039; (last rule)</pre><br /></dd>
<dt><abbr title="Next">N</abbr></dt>
<dd><pre>&#039;next|N&#039; (next round)</pre><br /></dd>
<dt><abbr title="No Case">NC</abbr></dt>
<dd><pre>&#039;nocase|NC&#039; (no case)</pre><br /></dd>
<dt><abbr title="No Escape">NE</abbr></dt>
<dd><pre>&#039;noescape|NE&#039; (no URI escaping of output)</pre><br /></dd>
<dt><abbr title="No Subrequest">NS</abbr></dt>
<dd><pre>&#039;nosubreq|NS&#039; (not for internal sub-requests)</pre><br /></dd>
<dt><abbr title="Proxy">P</abbr></dt>
<dd><pre>&#039;proxy|P&#039; (force proxy)</pre><br /></dd>
<dt><abbr title="pass through">PT</abbr></dt>
<dd><pre>&#039;passthrough|PT&#039; (pass through to next handler)</pre><br /></dd>
<dt><abbr title="Query String Append">QSA</abbr></dt>
<dd><pre>&#039;qsappend|QSA&#039; (query string append)</pre><br /></dd>
<dt><abbr title="Redirect">R</abbr></dt>
<dd><pre>&#039;redirect|R  [=code]&#039; (force redirect)</pre><br /></dd>
<dt><abbr title="Skip">S</abbr></dt>
<dd><pre>&#039;skip|S=num&#039; (skip next rule(s))</pre><br />

This flag forces the rewriting engine to skip the next num rules in sequence, if the current rule matches. Use this to make pseudo if-then-else constructs: The last rule of the then-clause becomes skip=N, where N is the number of rules in the else-clause. (This is not the same as the 'chain|C' flag!)</dd>
<dt><abbr title="Type">T</abbr></dt>
<dd><pre>&#039;type|T=MIME-type&#039; (force MIME type)</pre><br />
Force the MIME-type of the target file to be MIME-type. This can be used to set up the content-type based on some conditions. For example, the following snippet allows .php files to be displayed by mod_php if they are called with the .phps extension:
</dd>
</dl>


<h2>Rules and Conditions Processing Order</h2>
<ol>
<li>The Pattern of the RewriteRule (^/.*$) is checked first.</li>
<li>If the pattern matches, then the RewriteCond's are checked.</li>
<li>If the RewriteConditions also match, the RewriteRule is applied.</li>
</ol>



<h2>RewriteRule Special Variables</h2>
<ol>
<li><strong>ENV_</strong></li>
<li><strong>SSL_</strong></li>
<li><strong>HTTP_</strong></li>
<li><strong>LA-U_</strong></li>
<li><strong>LA-F_</strong></li>
</ol>


<h2>RewriteCond Tests</h2>
<ul>
<li><strong>f</strong> - FILE_EXISTS</li>
<li><strong>s</strong> - FILE_SIZE</li>
<li><strong>l</strong> - FILE_LINK</li>
<li><strong>d</strong> - FILE_DIR</li>
<li><strong>x</strong> - FILE_XBIT</li>
<li><strong>U</strong> - LU_URL</li>
<li><strong>F</strong> - LU_FILE</li>
<li><strong>&gt;</strong> - STR_GT</li>
<li><strong>&lt;</strong> - STR_LT</li>
<li><strong>=</strong> - STR_EQ</li>
</ul>



<h2>Special Rewrite Redirects</h2>
<ol>
<li>"permanent" - HTTP_MOVED_PERMANENTLY</li>
<li>"temp" - HTTP_MOVED_TEMPORARILY</li>
<li>"seeother" - HTTP_SEE_OTHER</li>
<li>digit</li>
</ol>


<h2>Recognized by Mod_Rewrite</h2>
<ol>
<li>ajp://</li>
<li>balancer://</li>
<li>ftp://</li>
<li>gopher://</li>
<li>http://</li>
<li>https://</li>
<li>ldap://</li>
<li>mailto:</li>
<li>news:</li>
<li>nntp://</li>
</ol>



<h2>Mod_Rewrite Variables, from Source</h2>
<ul>
<li>TIME - <code>%04d%02d%02d%02d%02d%02d</code></li>
<li>HTTPS - <code>flag ? "on" : "off"</code></li>
<li>TIME_DAY</li>
<li>TIME_SEC</li>
<li>TIME_MIN</li>
<li>TIME_HOUR</li>
<li>TIME_MON</li>
<li>TIME_WDAY</li>
<li>TIME_YEAR</li>
<li>IS_SUBREQ - <code> (main ? "true" : "false");</code></li>
<li>PATH_INFO - <code> path_info;</code></li>
<li>AUTH_TYPE - <code> ap_auth_type;</code></li>
<li>HTTP_HOST - <code> lookup_header("Host", ctx);</code></li>
<li>SERVER_NAME - <code> ap_get_server_name(r);</code></li>
<li>REMOTE_ADDR - <code> connection-&gt;remote_ip;</code></li>
<li>SERVER_ADDR - <code> connection-&gt;local_ip;</code></li>
<li>HTTP_ACCEPT - <code> lookup_header("Accept", ctx);</code></li>
<li>THE_REQUEST - <code> the_request;</code></li>
<li>API_VERSION - <code> "%d:%d",MODULE_MAGIC_NUMBER_MAJOR,MODULE_MAGIC_NUMBER_MINOR);</code></li>
<li>HTTP_COOKIE - <code> lookup_header("Cookie", ctx);</code></li>
<li>SERVER_PORT - <code> ap_get_server_port(r);</code></li>
<li>REMOTE_HOST</li>
<li>REMOTE_NAME, NULL);</code></li>
<li>REMOTE_PORT - <code> r-&gt;connection-&gt;remote_addr-&gt;port</code></li>
<li>REMOTE_USER - <code> user;</code></li>
<li>SCRIPT_USER - <code> "&lt;unknown&gt;";</code></li>
<li>APR_FINFO_USER</li>
<li>REQUEST_URI - <code> uri;</code></li>
<li>SCRIPT_GROUP - <code> "&lt;unknown&gt;";</code></li>
<li>REMOTE_IDENT - <code> ap_get_remote_logname(r);</code></li>
<li>HTTP_REFERER - <code> lookup_header("Referer", ctx);</code></li>
<li>QUERY_STRING - <code> args;</code></li>
<li>SERVER_ADMIN - <code> server-&gt;server_admin;</code></li>
<li>DOCUMENT_ROOT - <code> ap_document_root(r);</code></li>
<li>HTTP_FORWARDED - <code>lookup_header("Forwarded", ctx);</code></li>
<li>REQUEST_METHOD - <code>method;</code></li>
<li>HTTP_USER_AGENT - <code>lookup_header("User-Agent", ctx);</code></li>
<li>SCRIPT_FILENAME - <code> same as request_filename </code></li>
<li>REQUEST_FILENAME - <code> same as script_filename </code></li>
<li>SERVER_PROTOCOL - <code>protocol</code></li>
<li>SERVER_SOFTWARE - <code>ap_get_server_banner();</code></li>
<li>HTTP_PROXY_CONNECTION - <code>lookup_header("Proxy-Connection", ctx);</code></li>
</ul>


<h2>REGEX Rewrite Guides</h2>
<ul>
<li><a href="http://www.rankinglabs.com/Mod_Rewrite">Mod_Rewrite: Flags, Rules, Conditions, Tutorial and Variables</a></li>
<li><a href="http://etext.lib.virginia.edu/services/helpsheets/unix/regex.html" title="Stephen Ramsay - Electronic Text Center - University of Virginia ">Using Regular Expressions</a></li>
<li><a href="http://check-these.info/mod_rewrite-basic.html">RewriteRule (mod_rewrite) guide</a></li>
</ul>


<h2>Mod_Rewrite Terms and Definitions</h2>
<dl>
<dt>pattern</dt><dd>the RegExp pattern string</dd>
<dt>regexp<dt><dd>the RegExp pattern compilation</dd>
<dt>flags</dt>
<dd>Flags which control the substitution</dd>
<dt>forced_mimetype</dt>
<dd>forced MIME type of substitution</dd>
<dt>forced_handler</dt>
<dd>forced content handler of subst.</dd>
<dt>forced_responsecode</dt>
<dd>forced HTTP response status</dd>
<dt>env</dt>
<dd>added environment variables</dd>
<dt>cookie</dt>
<dd>added cookies</dd>
<dt>skip</dt>
<dd>number of next rules to skip</dd>
<dt>state</dt>
<dd>the RewriteEngine state</dd>
<dt>options</dt>
<dd>the RewriteOption state</dd>
<dt>rewritelogfile</dt>
<dd>the RewriteLog filename</dd>
<dt>rewritelogfp</dt>
<dd>the RewriteLog open filepointer</dd>
<dt>rewritelog:  level</dt>
<dd>the RewriteLog level of verbosity</dd>
<dt>rewritemaps</dt>
<dd>the RewriteMap entries</dd>
<dt>rewriteconds</dt>
<dd>the RewriteCond entries (temp.)</dd>
<dt>rewriterules</dt>
<dd>the RewriteRule entries</dd>
<dt>directory</dt>
<dd>the directory where it applies</dd>
<dt>baseurl</dt>
<dd>the base-URL  where it applies</dd>
</dl>


<h2>Mod_Rewrite Errors</h2>
<ul style="font-size:10px;">
<li><code>Options FollowSymLinks or SymLinksIfOwnerMatch is off  which implies that RewriteRule directive is forbidden:  %s</code></li>
<li><code>RewriteCond: bad argument line </code></li>
<li><code>RewriteCond: NoCase option for non-regex pattern %s  is not supported and will be ignored.</code></li>
<li><code>RewriteCond: cannot compile regular  expression </code></li>
<li><code>RewriteRule: invalid HTTP  response code %s for  flag R</code></li>
<li><code>RewriteRule: unknown flag </code></li>
<li><code>RewriteRule: cannot compile regular expression </code></li>
<li><code>RewriteOptions: MaxRedirects option has been  removed in favor of the global  LimitInternalRecursion directive and will be  ignored.</code></li>
<li><code>RewriteOptions: unknown option </code></li>
<li><code>RewriteMap: bad path to txt map: </code></li>
<li><code>RewriteMap: bad path to rnd map: </code></li>
<li><code>RewriteMap: bad map:</code></li>
<li><code>RewriteMap: bad path to dbm map: </code></li>
<li><code>RewriteMap: dbm type </code></li>
<li><code>RewriteMap: bad path to prg map: </code></li>
<li><code>RewriteMap: internal map not found:</code></li>
<li><code>RewriteMap: bad path to txt map: </code></li>
<li><code>RewriteMap: file for map not found:</code></li>
<li><code>Invalid RewriteLock path</code></li>
<li><code>RewriteBase: only valid in per-directory config files</code></li>
<li><code>RewriteBase: empty URL not allowed</code></li>
<li><code>RewriteBase: argument is not a valid URL</code></li>
<li><code>RewriteCond: bad flag delimiters</code></li>
<li><code>RewriteCond: unknown flag</code></li>
<li><code>RewriteLog and RewriteLogLevel are not supported by this build of mod_rewrite because it was compiled using the -DREWRITELOG_DISABLED compiler option. You have to recompile mod_rewrite WITHOUT this option in order to use the rewrite log.</code></li>
<li><code>mod_rewrite: Invalid RewriteLog  path %s</code></li>
<li><code>mod_rewrite: could not open reliable pipe  to RewriteLog filter %s</code></li>
<li><code>mod_rewrite: Invalid RewriteLog  path %s</code></li>
<li><code>mod_rewrite: could not open RewriteLog  file %s</code></li>
<li><code>mod_rewrite: Running external rewrite maps  without defining a RewriteLock is DANGEROUS!</code></li>
<li><code>mod_rewrite: could not start RewriteMap  program %s</code></li>
<li><code>mod_rewrite: cant access text RewriteMap file %s</code></li>
<li><code>mod_rewrite: cant access DBM RewriteMap file %s</code></li>
<li><code>mod_rewrite: Parent could not create RewriteLock  file %s</code></li>
<li><code>mod_rewrite: Parent could not set permissions  on RewriteLock check User and Group directives</code></li>
<li><code>mod_rewrite: could not create rewrite_log_lock</code></li>
<li><code>mod_rewrite: Could not set permissions on  rewrite_log_lock check User and Group directives</code></li>
<li><code>mod_rewrite: could not init rewrite_mapr_lock_acquire  in child</code></li>
<li><code>mod_rewrite: could not init rewrite log lock in child</code></li>
<li><code>mod_rewrite: could not init map cache in child</code></li>
<li><code>split uri=%s -&gt; uri=%s, args=%s</code></li>
<li><code>reduce %s -&gt; %s</code></li>
<li><code>strip matching prefix: %s -&gt; %s</code></li>
<li><code>add subst prefix: %s -&gt; %s</code></li>
<li><code>cant open RewriteMap file, see error log</code></li>
<li><code>cache lookup FAILED, forcing new map lookup</code></li>
<li><code>map lookup FAILED: map=%s[txt] key=%s</code></li>
<li><code>map lookup OK: map=%s[txt] key=%s -&gt; val=%s</code></li>
<li><code>cache lookup OK: map=%s[txt] key=%s -&gt; val=%s</code></li>
<li><code>randomly chosen the subvalue `%s</code></li>
<li><code>cant open DBM RewriteMap file, see error log</code></li>
<li><code>cache lookup FAILED, forcing new map lookup</code></li>
<li><code>map lookup FAILED: map=%s[dbm] key=%s</code></li>
<li><code>map lookup OK: map=%s[dbm] key=%s -&gt;  val=%s</code></li>
<li><code>cache lookup OK: map=%s[dbm] key=%s -&gt; val=%s</code></li>
<li><code>map lookup FAILED: map=%s key=%s</code></li>
<li><code>map lookup OK: map=%s key=%s -&gt; val=%s</code></li>
<li><code>map lookup FAILED: map=%s key=%s</code></li>
<li><code>map lookup OK: map=%s key=%s -&gt; val=%s</code></li>
<li><code>lookahead: path=%s var=%s  -&gt; val=%s</code></li>
<li><code>lookahead: path=%s var=%s  -&gt; val=%s</code></li>
<li><code>RESULT=%s</code></li>
<li><code>escaping backreference %s to %s</code></li>
<li><code>setting env variable %s to %s</code></li>
<li><code>setting cookie %s, cookie</code></li>
<li><code>skipping already set cookie %s</code></li>
<li><code>RewriteCond URI (-U) check:  path=%s -&gt; status=%d</code></li>
<li><code>RewriteCond file (-F) check: path=%s  -&gt; file=%s status=%d</code></li>
<li><code>RewriteCond: input=%s pattern=%s%s%s%s  =&gt; %s</code></li>
<li><code>remember %s to have MIME-type  %s</code></li>
<li><code>remember %s to have  Content-handler %s</code></li>
<li><code>add path info postfix: %s -&gt; %s%s</code></li>
<li><code>strip per-dir prefix: %s -&gt; %s</code></li>
<li><code>applying pattern %s to uri %s</code></li>
<li><code>rewrite %s -&gt; %s, ctx-&gt;uri</code></li>
<li><code>forcing responsecode %d for %s</code></li>
<li><code>add per-dir prefix: %s -&gt; %s%s</code></li>
<li><code>forcing proxy-throughput with %s</code></li>
<li><code>explicitly forcing redirect with %s</code></li>
<li><code>implicitly forcing redirect (rc=%d)  with %s</code></li>
<li><code>forcing %s to get passed through  to next API URI-to-filename handler</code></li>
<li><code>init rewrite engine with requested uri %s</code></li>
<li><code>go-ahead with proxy request  %s [OK]</code></li>
<li><code>dconf-&gt;directory,trying to replace prefix %s with %s</code></li>
<li><code>escaping %s for redirect</code></li>
<li><code>redirect to %s [REDIRECT/%d]</code></li>
<li><code>initial URL equal rewritten  URL: %s [IGNORING REWRITE]</code></li>
<li><code>dconf-&gt;directory, trying to replace prefix  %s with %s</code></li>
<li><code>strip document_root  prefix: %s -&gt; %s</code></li>
<li><code>internal redirect with %s  [INTERNAL REDIRECT]</code></li>
<li><code>pass through %s</code></li>
<li><code>force filename %s to have MIME-type %s</code></li>
<li><code>force filename %s to have the  Content-handler %s,</code></li>
<li><code>init rewrite engine with requested uri %s</code></li>
<li><code>init rewrite engine with passed filename  %s. Original uri = %s</code></li>
<li><code>uri already rewritten. Status %s, Uri %s,   %s</code></li>
<li><code>attempt to make remote request from mod_rewrite  without proxy enabled: %s</code></li>
<li><code>go-ahead with proxy request %s [OK]</code></li>
<li><code>escaping %s for redirect</code></li>
<li><code>redirect to %s [REDIRECT/%d]</code></li>
<li><code>local path result: %s</code></li>
<li><code>prefixing with document_root of %s  FAILED</code></li>
<li><code>prefixed with document_root to %s</code></li>
<li><code>go-ahead with %s [OK]</code></li>
<li><code>pass through %s</code></li>
</ul>



<h2>URL Rewriting Module</h2>
<blockquote cite="http://apache.askapache.com/httpd/httpd-2.2.8/modules/mappers/mod_rewrite.c">
<p>This module uses a rule-based rewriting engine (based on a regular-expression parser) to rewrite requested URLs on the fly.</p>
<p>It supports an unlimited number of additional rule conditions (which can operate on a lot of variables, even on HTTP headers) for granular matching and even external database lookups (either via plain text tables, DBM hash files or even external processes) for advanced URL substitution.</p>
<p>It operates on the full URLs (including the PATH_INFO part) both in per-server context (httpd.conf) and per-dir context (.htaccess) and even  can generate QUERY_STRING parts on result.  The rewriting result finally can lead to internal subprocessing, external request redirection or even to internal proxy throughput.</p>
<p>This module was originally written in April 1996 and gifted exclusively to the The Apache Software Foundation in July 1997 by</p>
<address class="vcard">
<a class="fn url" href="http://engelschall.com/" title="Ralf S. Engelschall">Ralf S. Engelschall</a>
<a class="fn email" href="http://engelschall.com/contact.php">rse [at] engenschall.com</a>
</address>
</blockquote>
<p><a href="http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html"></a><a href="http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html">Mod_Rewrite Variables Cheatsheet</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Actual Htaccess Files from My Server</title>
		<link>http://www.askapache.com/htaccess/real-world-htaccess-files.html</link>
		<comments>http://www.askapache.com/htaccess/real-world-htaccess-files.html#comments</comments>
		<pubDate>Sat, 17 Apr 2010 15:06:22 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Htaccess]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=4357</guid>
		<description><![CDATA[<pre>#### No https except to wp-admin -
# If the request is empty ( implies fopen or normal file access by a php script )
RewriteCond %{THE_REQUEST} ^$ [OR]
&#160;
# OR if the request if for wp-admin or wp-login.php
RewriteCond %{REQUEST_URI} ^/(wp-admin&#124;wp-login\.php).*$ [NC,OR]
&#160;
# OR if the Referer is https
RewriteCond %{HTTP_REFERER} ^https://www.askapache.com/.*$ [NC]
&#160;
# THEN skip the following rule, basically all this does is force https or badhost to be redirected
# BUT because of the above 3 rewritecond&#039;s, this won&#039;t break poorly written admin scripts
RewriteRule .* - [S=1]
&#160;
RewriteCond %{HTTPS} =on [OR]
RewriteCond %{HTTP_HOST} !^www\.askapache\.com$ [NC]
RewriteRule .* http://www.askapache.com%{REQUEST_URI} [R=301,L]
&#160;
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(wp-admin/.*&#124;wp-login\.php.*)\ HTTP/ [NC]
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]</pre>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/htaccess/real-world-htaccess-files.html"></a><a href="http://www.askapache.com/htaccess/real-world-htaccess-files.html"><cite>AskApache.com</cite></a></p><p>I was going through some backups from years ago, and ran:</p>
<pre>locate .htaccess | xargs -I&#039;{}&#039; cat &#039;{}&#039; &gt;&gt; master-htaccesser.txt</pre>
<p>My site is named after reading source code because that is what helps me the most when I'm trying to learn something unusually difficult.   Just like functions and aliases, it is very helpful to have cheatsheets for common commands.. not much is better than real-world examples.  Unfortunately because this was compiled from hundreds of htaccess files on multiple hosts and platforms, and due to the concatenation, it's not organized.</p>

<p>Normally I would not publish something like this, who knows how much unreleased tricks I forgot about..  but in order to say thanks to all those working for open-source, the FSF, and to all those who don't steal content, and to all the incredible authors who shared with me (I twitter most of what I find, and follow my favs), here ya go..</p>


<p class="cnote"><strong>ATTN:</strong> Please let me know if this is total junk or not, this is around 1/500th of my master-htaccesser.txt file.. and I'd be happy to post more if it helps..</p>

<h2>Checking for Cookie</h2>
<p>Used this to stop mp3-scrapers.. checks for a cookie ending in MP3P=02357</p>
<pre>Options -Indexes
RewriteEngine On
RewriteCond %{HTTP_COOKIE} !^.*MP3P=([0-9]+).* [NC]
RewriteRule .* - [F,L]</pre>

<h2>Setting Environment Var if Proxied</h2>
<pre>RewriteEngine On
RewriteRule "\.(gif|png|jpg)$" "-" [ENV=proxied_image:1]
RewriteCond "%{ENV:proxied_image}" "!1"
RewriteRule "^" "-" [ENV=proxied_other:1]</pre>

<h2>nokeepalive for ErrorDocs and Abusers</h2>
<pre>Options SymLinksIfOwnerMatch IncludesNOEXEC
AddOutputFilter Includes html
SetEnv nokeepalive
Order Allow,Deny
Allow from all
# 1 YEAR
&lt;filesMatch "\.(js|css)$"&gt;
Header unset Pragma
FileETag None
Header set Cache-Control "public"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
Header unset Last-Modified
Header unset Last-Modified
Header unset ETag
&nbsp;
SetOutputFilter DEFLATE
Header set Cache-Control "public"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
&lt;/filesMatch&gt;
SecFilterEngine Off
&nbsp;
# 1 YEAR
&lt;filesMatch "\.(js|css)$"&gt;
Header unset Pragma
FileETag None
Header set Cache-Control "public"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
Header unset Last-Modified
Header unset Last-Modified
Header unset ETag
&nbsp;
SetOutputFilter DEFLATE
Header set Cache-Control "public"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
&lt;/filesMatch&gt;</pre>








<h2>Unreleased Tests for AskApache Password Protection</h2>
<pre># +ASKAPACHE PASSPRO 4.6.6
#######################################################
#               __                          __
#   ____ ______/ /______ _____  ____ ______/ /_  ___
#  / __ `/ ___/ //_/ __ `/ __ \/ __ `/ ___/ __ \/ _ \
# / /_/ (__  ) ,&lt; / /_/ / /_/ / /_/ / /__/ / / /  __/
# \__,_/____/_/|_|\__,_/ .___/\__,_/\___/_/ /_/\___/
#                     /_/
# - - - - - - - - - - - - - - - - - - - - - - - - - - -
# +APRO SIDS
# +SID 21030002
Order Deny,Allow
Deny from All
Satisfy Any
AuthType Digest
AuthName "Protected By AskApache"
AuthDigestDomain / http://www.askapache.com/
AuthDigestFile /home/.greer/askapache/sites/askapache.com/.htpasswda3
Require valid-user
&lt;filesMatch "\.(ico|pdf|flv|jpg|jpeg|mp3|mpg|mp4|mov|wav|wmv|png|gif|swf|css|js)$"&gt;
Allow from All
&lt;/filesMatch&gt;
&lt;filesMatch "(async-upload|admin-ajax)\.php$"&gt;
&lt;ifModule mod_security.c&gt;
SecFilterEngine Off
&lt;/ifModule&gt;
Allow from All
&lt;/filesMatch&gt;
# -SID 21030002
# -APRO SIDS
# - - - - - - - - - - - - - - - - - - - - - - - - - - -
#               __                          __
#   ____ ______/ /______ _____  ____ ______/ /_  ___
#  / __ `/ ___/ //_/ __ `/ __ \/ __ `/ ___/ __ \/ _ \
# / /_/ (__  ) ,&lt; / /_/ / /_/ / /_/ / /__/ / / /  __/
# \__,_/____/_/|_|\__,_/ .___/\__,_/\___/_/ /_/\___/
#                     /_/
#######################################################
# -ASKAPACHE PASSPRO 4.6.6
&nbsp;
# +ASKAPACHE PASSPRO 4.6.6
#######################################################
#               __                          __
#   ____ ______/ /______ _____  ____ ______/ /_  ___
#  / __ `/ ___/ //_/ __ `/ __ \/ __ `/ ___/ __ \/ _ \
# / /_/ (__  ) ,&lt; / /_/ / /_/ / /_/ / /__/ / / /  __/
# \__,_/____/_/|_|\__,_/ .___/\__,_/\___/_/ /_/\___/
#                     /_/
# - - - - - - - - - - - - - - - - - - - - - - - - - - -
# +APRO SIDS
# +SID Test
ErrorDocument 401 /wp-content/askapache/test.gif
ErrorDocument 403 /wp-content/askapache/test.gif
ErrorDocument 404 /wp-content/askapache/test.gif
ErrorDocument 500 /wp-content/askapache/test.gif
ServerSignature On
&lt;ifModule mod_alias.c&gt;
RedirectMatch 305 ^.*modaliastest$ http://www.askapache.com
&lt;/ifModule&gt;
&lt;ifModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} modrewritetest [NC]
RewriteRule .* http://www.askapache.com [R=307,L]
&lt;/ifModule&gt;
&lt;files modsec_check.gif&gt;
&lt;ifModule mod_security.c&gt;
SetEnv MODSEC_ENABLE On
SecFilterEngine On
SecFilterDefaultAction "nolog,noauditlog,pass"
SecAuditEngine Off
SecFilterInheritance Off
SecFilter modsecuritytest "deny,nolog,noauditlog,status:503"
Deny from All
&lt;/ifModule&gt;
&lt;/files&gt;
&lt;files basic_auth_test.gif&gt;
AuthType Basic
AuthName "askapache test"
AuthUserFile /home/.greer/askapache/sites/askapache.com/htdocs/wp-content/askapache/.htpasswd-basic
Require valid-user
&lt;/files&gt;
&lt;files digest_check.gif&gt;
AuthType Digest
AuthName "askapache test"
AuthDigestDomain /wp-content/askapache/ http://www.askapache.com/wp-content/askapache/
AuthUserFile /home/.greer/askapache/sites/askapache.com/htdocs/wp-content/askapache/.htpasswd-digest
Require none
&lt;/files&gt;
&lt;files authuserfile_test.gif&gt;
AuthType Digest
AuthName "askapache test"
AuthDigestDomain /wp-content/askapache/ http://www.askapache.com/wp-content/askapache/
AuthUserFile /home/.greer/askapache/sites/askapache.com/htdocs/wp-content/askapache/.htpasswd-digest
Require valid-user
&lt;/files&gt;
&lt;files authdigestfile_test.gif&gt;
AuthType Digest
AuthName "askapache test"
AuthDigestDomain /wp-content/askapache/ http://www.askapache.com/wp-content/askapache/
AuthDigestFile /home/.greer/askapache/sites/askapache.com/htdocs/wp-content/askapache/.htpasswd-digest
Require valid-user
&lt;/files&gt;
# -SID Test
# -APRO SIDS
# - - - - - - - - - - - - - - - - - - - - - - - - - - -
#               __                          __
#   ____ ______/ /______ _____  ____ ______/ /_  ___
#  / __ `/ ___/ //_/ __ `/ __ \/ __ `/ ___/ __ \/ _ \
# / /_/ (__  ) ,&lt; / /_/ / /_/ / /_/ / /__/ / / /  __/
# \__,_/____/_/|_|\__,_/ .___/\__,_/\___/_/ /_/\___/
#                     /_/
#######################################################
# -ASKAPACHE PASSPRO 4.6.6</pre>
















<h2>Warming up to the really advanced tests</h2>
<pre>Options +ExecCGI
Order Deny,Allow
Deny from All
Allow from 208.113.134.190 64.111.114.111 208.113.134.203 208.113.152.201 env=REDIRECT_STATUS
Satisfy Any
Options +FollowSymLinks
AddHandler application/x-httpd-php .php
&nbsp;
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} !^tyy+$ [NC]
RewriteCond %{REMOTE_USER} ^(.+)$
RewriteRule ^(.*)$ $1/-%1 [R=302,L]
Options +ExecCGI +FollowSymLinks
DirectoryIndex index.php
ErrorDocument 404 /cgi-bin/pro/index.php
&nbsp;
AuthType Digest
AuthName "AskApache Pro"
AuthDigestFile /home/askapache/sites/askapache.com/.htpasswd-pro
AuthDigestDomain /cgi-bin/pro/ http://www.askapache.com/cgi-bin/pro/ https://www.askapache.com/cgi-bin/pro/
Require user askapacheDirectoryIndex p.php
ErrorDocument 403 /cgi-bin/p/p.php
ErrorDocument 401 /cgi-bin/p/p.php
ErrorDocument 500 /cgi-bin/p/p.php
ErrorDocument 503 /cgi-bin/p/p.php
&nbsp;
RewriteEngine On
RewriteBase /
RewriteRule .* - [E=INFO_API_VERSION:%{API_VERSION}]
RewriteRule .* - [E=INFO_AUTH_TYPE:%{AUTH_TYPE}]
RewriteRule .* - [E=INFO_CONTENT_LENGTH:%{CONTENT_LENGTH}]
RewriteRule .* - [E=INFO_CONTENT_TYPE:%{CONTENT_TYPE}]
RewriteRule .* - [E=INFO_DOCUMENT_ROOT:%{DOCUMENT_ROOT}]
RewriteRule .* - [E=INFO_GATEWAY_INTERFACE:%{GATEWAY_INTERFACE}]
RewriteRule .* - [E=INFO_HTTPS:%{HTTPS}]
RewriteRule .* - [E=INFO_HTTP_ACCEPT:%{HTTP:Accept}]
RewriteRule .* - [E=INFO_HTTP_ACCEPT_LANGUAGE:%{HTTP:Accept-Language}]
RewriteRule .* - [E=INFO_HTTP_ACCEPT_ENCODING:%{HTTP:Accept-Encoding}]
RewriteRule .* - [E=INFO_HTTP_ACCEPT_CHARSET:%{HTTP:Accept-Charset}]
RewriteRule .* - [E=INFO_HTTP_CACHE_CONTROL:%{HTTP:Cache-Control}]
RewriteRule .* - [E=INFO_HTTP_CONNECTION:%{HTTP:Connection}]
RewriteRule .* - [E=INFO_HTTP_COOKIE:%{HTTP_COOKIE}]
RewriteRule .* - [E=INFO_HTTP_FORWARDED:%{HTTP_FORWARDED}]
RewriteRule .* - [E=INFO_HTTP_HOST:%{HTTP_HOST}]
RewriteRule .* - [E=INFO_HTTP_KEEP_ALIVE:%{HTTP_KEEP_ALIVE}]
RewriteRule .* - [E=INFO_HTTP_PROXY_CONNECTION:%{HTTP_PROXY_CONNECTION}]
RewriteRule .* - [E=INFO_HTTP_REFERER:%{HTTP:Referer}]
RewriteRule .* - [E=INFO_HTTP_USER_AGENT:%{HTTP_USER_AGENT}]
RewriteRule .* - [E=INFO_IS_SUBREQ:%{IS_SUBREQ}]
RewriteRule .* - [E=INFO_ORIG_PATH_INFO:%{ORIG_PATH_INFO}]
RewriteRule .* - [E=INFO_ORIG_PATH_TRANSLATED:%{ORIG_PATH_TRANSLATED}]
RewriteRule .* - [E=INFO_ORIG_SCRIPT_FILENAME:%{ORIG_SCRIPT_FILENAME}]
RewriteRule .* - [E=INFO_ORIG_SCRIPT_NAME:%{ORIG_SCRIPT_NAME}]
RewriteRule .* - [E=INFO_PATH:%{PATH}]
RewriteRule .* - [E=INFO_PATH_INFO:%{PATH_INFO}]
RewriteRule .* - [E=INFO_QUERY_STRING:%{QUERY_STRING}]
RewriteRule .* - [E=INFO_REDIRECT_QUERY_STRING:%{REDIRECT_QUERY_STRING}]
RewriteRule .* - [E=INFO_REDIRECT_REMOTE_USER:%{REDIRECT_REMOTE_USER}]
RewriteRule .* - [E=INFO_REDIRECT_STATUS:%{REDIRECT_STATUS}]
RewriteRule .* - [E=INFO_REDIRECT_URL:%{REDIRECT_URL}]
RewriteRule .* - [E=INFO_REMOTE_ADDR:%{REMOTE_ADDR}]
RewriteRule .* - [E=INFO_REMOTE_HOST:%{REMOTE_HOST}]
RewriteRule .* - [E=INFO_REMOTE_IDENT:%{REMOTE_IDENT}]
RewriteRule .* - [E=INFO_REMOTE_PORT:%{REMOTE_PORT}]
RewriteRule .* - [E=INFO_REMOTE_USER:%{REMOTE_USER}]
RewriteRule .* - [E=INFO_REQUEST_FILENAME:%{REQUEST_FILENAME}]
RewriteRule .* - [E=INFO_REQUEST_METHOD:%{REQUEST_METHOD}]
RewriteRule .* - [E=INFO_REQUEST_URI:%{REQUEST_URI}]
RewriteRule .* - [E=INFO_REDIRECT_REQUEST_URI:%{REDIRECT_REQUEST_URI}]
RewriteRule .* - [E=INFO_SCRIPT_FILENAME:%{SCRIPT_FILENAME}]
RewriteRule .* - [E=INFO_SCRIPT_GROUP:%{SCRIPT_GROUP}]
RewriteRule .* - [E=INFO_SCRIPT_NAME:%{SCRIPT_NAME}]
RewriteRule .* - [E=INFO_SCRIPT_URI:%{SCRIPT_URI}]
RewriteRule .* - [E=INFO_SCRIPT_URL:%{SCRIPT_URL}]
RewriteRule .* - [E=INFO_SCRIPT_USER:%{SCRIPT_USER}]
RewriteRule .* - [E=INFO_SERVER_ADDR:%{SERVER_ADDR}]
RewriteRule .* - [E=INFO_SERVER_ADMIN:%{SERVER_ADMIN}]
RewriteRule .* - [E=INFO_SERVER_NAME:%{SERVER_NAME}]
RewriteRule .* - [E=INFO_SERVER_PORT:%{SERVER_PORT}]
RewriteRule .* - [E=INFO_SERVER_PROTOCOL:%{SERVER_PROTOCOL}]
RewriteRule .* - [E=INFO_SERVER_SIGNATURE:%{SERVER_SIGNATURE}]
RewriteRule .* - [E=INFO_SERVER_SOFTWARE:%{SERVER_SOFTWARE}]
RewriteRule .* - [E=INFO_THE_REQUEST:%{THE_REQUEST}]
RewriteRule .* - [E=INFO_TIME:%{TIME}]
RewriteRule .* - [E=INFO_TIME_DAY:%{TIME_DAY}]
RewriteRule .* - [E=INFO_TIME_HOUR:%{TIME_HOUR}]
RewriteRule .* - [E=INFO_TIME_MIN:%{TIME_MIN}]
RewriteRule .* - [E=INFO_TIME_MON:%{TIME_MON}]
RewriteRule .* - [E=INFO_TIME_SEC:%{TIME_SEC}]
RewriteRule .* - [E=INFO_TIME_WDAY:%{TIME_WDAY}]
RewriteRule .* - [E=INFO_TIME_YEAR:%{TIME_YEAR}]
RewriteRule .* - [E=INFO_TZ:%{TZ}]
RewriteRule .* - [E=INFO_UNIQUE_ID:%{UNIQUE_ID}]
&nbsp;
RequestHeader set INFO_API_VERSION "%{INFO_API_VERSION}e"
RequestHeader set INFO_AUTH_TYPE "%{INFO_AUTH_TYPE}e"
RequestHeader set INFO_CONTENT_LENGTH "%{INFO_CONTENT_LENGTH}e"
RequestHeader set INFO_CONTENT_TYPE "%{INFO_CONTENT_TYPE}e"
RequestHeader set INFO_DOCUMENT_ROOT "%{INFO_DOCUMENT_ROOT}e"
RequestHeader set INFO_GATEWAY_INTERFACE "%{INFO_GATEWAY_INTERFACE}e"
RequestHeader set INFO_HTTPS "%{INFO_HTTPS}e"
RequestHeader set INFO_HTTP_ACCEPT "%{INFO_HTTP_ACCEPT}e"
RequestHeader set INFO_HTTP_ACCEPT_LANGUAGE "%{INFO_HTTP_ACCEPT_LANGUAGE}e"
RequestHeader set INFO_HTTP_ACCEPT_ENCODING "%{INFO_HTTP_ACCEPT_ENCODING}e"
RequestHeader set INFO_HTTP_ACCEPT_CHARSET "%{INFO_HTTP_ACCEPT_CHARSET}e"
RequestHeader set INFO_HTTP_CACHE_CONTROL "%{INFO_HTTP_CACHE_CONTROL}e"
RequestHeader set INFO_HTTP_CONNECTION "%{INFO_HTTP_CONNECTION}e"
RequestHeader set INFO_HTTP_COOKIE "%{INFO_HTTP_COOKIE}e"
RequestHeader set INFO_HTTP_FORWARDED "%{INFO_HTTP_FORWARDED}e"
RequestHeader set INFO_HTTP_HOST "%{INFO_HTTP_HOST}e"
RequestHeader set INFO_HTTP_KEEP_ALIVE "%{INFO_HTTP_KEEP_ALIVE}e"
RequestHeader set INFO_HTTP_PROXY_CONNECTION "%{INFO_HTTP_PROXY_CONNECTION}e"
RequestHeader set INFO_HTTP_REFERER "%{INFO_HTTP_REFERER}e"
RequestHeader set INFO_HTTP_USER_AGENT "%{INFO_HTTP_USER_AGENT}e"
RequestHeader set INFO_IS_SUBREQ "%{INFO_IS_SUBREQ}e"
RequestHeader set INFO_ORIG_PATH_INFO "%{INFO_ORIG_PATH_INFO}e"
RequestHeader set INFO_ORIG_PATH_TRANSLATED "%{INFO_ORIG_PATH_TRANSLATED}e"
RequestHeader set INFO_ORIG_SCRIPT_FILENAME "%{INFO_ORIG_SCRIPT_FILENAME}e"
RequestHeader set INFO_ORIG_SCRIPT_NAME "%{INFO_ORIG_SCRIPT_NAME}e"
RequestHeader set INFO_PATH "%{INFO_PATH}e"
RequestHeader set INFO_PATH_INFO "%{INFO_PATH_INFO}e"
RequestHeader set INFO_QUERY_STRING "%{INFO_QUERY_STRING}e"
RequestHeader set INFO_REDIRECT_QUERY_STRING "%{INFO_REDIRECT_QUERY_STRING}e"
RequestHeader set INFO_REDIRECT_REMOTE_USER "%{INFO_REDIRECT_REMOTE_USER}e"
RequestHeader set INFO_REDIRECT_STATUS "%{INFO_REDIRECT_STATUS}e"
RequestHeader set INFO_REDIRECT_URL "%{INFO_REDIRECT_URL}e"
RequestHeader set INFO_REMOTE_ADDR "%{INFO_REMOTE_ADDR}e"
RequestHeader set INFO_REMOTE_HOST "%{INFO_REMOTE_HOST}e"
RequestHeader set INFO_REMOTE_IDENT "%{INFO_REMOTE_IDENT}e"
RequestHeader set INFO_REMOTE_PORT "%{INFO_REMOTE_PORT}e"
RequestHeader set INFO_REMOTE_USER "%{INFO_REMOTE_USER}e"
RequestHeader set INFO_REQUEST_FILENAME "%{INFO_REQUEST_FILENAME}e"
RequestHeader set INFO_REQUEST_METHOD "%{INFO_REQUEST_METHOD}e"
RequestHeader set INFO_REQUEST_URI "%{INFO_REQUEST_URI}e"
RequestHeader set INFO_REQUEST_URI "%{INFO_REQUEST_URI}e"
RequestHeader set INFO_SCRIPT_FILENAME "%{INFO_SCRIPT_FILENAME}e"
RequestHeader set INFO_SCRIPT_GROUP "%{INFO_SCRIPT_GROUP}e"
RequestHeader set INFO_SCRIPT_NAME "%{INFO_SCRIPT_NAME}e"
RequestHeader set INFO_SCRIPT_URI "%{INFO_SCRIPT_URI}e"
RequestHeader set INFO_SCRIPT_URL "%{INFO_SCRIPT_URL}e"
RequestHeader set INFO_SCRIPT_USER "%{INFO_SCRIPT_USER}e"
RequestHeader set INFO_SERVER_ADDR "%{INFO_SERVER_ADDR}e"
RequestHeader set INFO_SERVER_ADMIN "%{INFO_SERVER_ADMIN}e"
RequestHeader set INFO_SERVER_NAME "%{INFO_SERVER_NAME}e"
RequestHeader set INFO_SERVER_PORT "%{INFO_SERVER_PORT}e"
RequestHeader set INFO_SERVER_PROTOCOL "%{INFO_SERVER_PROTOCOL}e"
RequestHeader set INFO_SERVER_SIGNATURE "%{INFO_SERVER_SIGNATURE}e"
RequestHeader set INFO_SERVER_SOFTWARE "%{INFO_SERVER_SOFTWARE}e"
RequestHeader set INFO_THE_REQUEST "%{INFO_THE_REQUEST}e"
RequestHeader set INFO_TIME "%{INFO_TIME}e"
RequestHeader set INFO_TIME_DAY "%{INFO_TIME_DAY}e"
RequestHeader set INFO_TIME_HOUR "%{INFO_TIME_HOUR}e"
RequestHeader set INFO_TIME_MIN "%{INFO_TIME_MIN}e"
RequestHeader set INFO_TIME_MON "%{INFO_TIME_MON}e"
RequestHeader set INFO_TIME_SEC "%{INFO_TIME_SEC}e"
RequestHeader set INFO_TIME_WDAY "%{INFO_TIME_WDAY}e"
RequestHeader set INFO_TIME_YEAR "%{INFO_TIME_YEAR}e"
RequestHeader set INFO_TZ "%{INFO_TZ}e"
RequestHeader set INFO_UNIQUE_ID "%{INFO_UNIQUE_ID}e"
&nbsp;
Options +FollowSymLinks +ExecCGI
DirectoryIndex /cgi-bin/rewrite-test/index.php
&nbsp;
Header echo ^.*
&nbsp;
AuthType Digest
AuthName "AskApache Pro"
AuthDigestFile /home/askapache/sites/askapache.com/.htpasswd-pro
AuthDigestDomain / http://www.askapache.com/cgi-bin/rewrite-test/ https://www.askapache.com/cgi-bin/rewrite-test/
Require user askapache
&nbsp;
SetEnv MODSEC_ENABLE=On
&nbsp;
SetEnvIfNoCase ^WWW-Auth "(.+)" HTTP_WWW_AUTHORIZATION=$1
SetEnvIfNoCase ^If "(.+)" HTTP_IF_MODIFIED_SINCE=$1
SetEnvIfNoCase ^If-None-Match$ "(.+)" HTTP_IF_NONE_MATCH=$1
SetEnvIfNoCase ^Cache-Control$ "(.+)" HTTP_CACHE_CONTROL=$1
SetEnvIfNoCase ^Connection$ "(.+)" HTTP_CONNECTION=$1
SetEnvIfNoCase ^Keep-Alive$ "(.+)" HTTP_KEEP_ALIVE=$1
SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
SetEnvIfNoCase ^Authorization$ ".+username=\"(.+)\".+" HTTP_REMOTE_USER=$1
SetEnvIfNoCase ^Content-Type$ "(.+)" HTTP_CONTENT_TYPE=$1
SetEnvIfNoCase ^Content-Length$ "(.+)" HTTP_CONTENT_LENGTH=$1
SetEnvIfNoCase Server_Addr "(.+)" SERVER_ADDR=$1
SetEnvIfNoCase Request_Method "(.+)" REQUEST_METHOD=$1
SetEnvIfNoCase Request_Protocol "(.+)" REQUEST_PROTOCOL=$1
SetEnvIfNoCase Request_URI "(.+)" REQUEST_URI=$1
&nbsp;
ErrorDocument 100 /cgi-bin/rewrite-test/index.php?g=100
ErrorDocument 101 /cgi-bin/rewrite-test/index.php?g=101
ErrorDocument 102 /cgi-bin/rewrite-test/index.php?g=102
ErrorDocument 200 /cgi-bin/rewrite-test/index.php?g=200
ErrorDocument 201 /cgi-bin/rewrite-test/index.php?g=201
ErrorDocument 202 /cgi-bin/rewrite-test/index.php?g=202
ErrorDocument 203 /cgi-bin/rewrite-test/index.php?g=203
ErrorDocument 204 /cgi-bin/rewrite-test/index.php?g=204
ErrorDocument 205 /cgi-bin/rewrite-test/index.php?g=205
ErrorDocument 206 /cgi-bin/rewrite-test/index.php?g=206
ErrorDocument 207 /cgi-bin/rewrite-test/index.php?g=207
ErrorDocument 300 /cgi-bin/rewrite-test/index.php?g=300
ErrorDocument 301 /cgi-bin/rewrite-test/index.php?g=301
ErrorDocument 302 /cgi-bin/rewrite-test/index.php?g=302
ErrorDocument 303 /cgi-bin/rewrite-test/index.php?g=303
ErrorDocument 304 /cgi-bin/rewrite-test/index.php?g=304
ErrorDocument 305 /cgi-bin/rewrite-test/index.php?g=305
ErrorDocument 306 /cgi-bin/rewrite-test/index.php?g=306
ErrorDocument 307 /cgi-bin/rewrite-test/index.php?g=307
ErrorDocument 400 /cgi-bin/rewrite-test/index.php?g=400
ErrorDocument 401 /cgi-bin/rewrite-test/index.php?g=401
ErrorDocument 402 /cgi-bin/rewrite-test/index.php?g=402
ErrorDocument 403 /cgi-bin/rewrite-test/index.php?g=403
ErrorDocument 404 /cgi-bin/rewrite-test/index.php?g=404
ErrorDocument 405 /cgi-bin/rewrite-test/index.php?g=405
ErrorDocument 406 /cgi-bin/rewrite-test/index.php?g=406
ErrorDocument 407 /cgi-bin/rewrite-test/index.php?g=407
ErrorDocument 408 /cgi-bin/rewrite-test/index.php?g=408
ErrorDocument 409 /cgi-bin/rewrite-test/index.php?g=409
ErrorDocument 410 /cgi-bin/rewrite-test/index.php?g=410
ErrorDocument 411 /cgi-bin/rewrite-test/index.php?g=411
ErrorDocument 412 /cgi-bin/rewrite-test/index.php?g=412
ErrorDocument 413 /cgi-bin/rewrite-test/index.php?g=413
ErrorDocument 414 /cgi-bin/rewrite-test/index.php?g=414
ErrorDocument 415 /cgi-bin/rewrite-test/index.php?g=415
ErrorDocument 416 /cgi-bin/rewrite-test/index.php?g=416
ErrorDocument 417 /cgi-bin/rewrite-test/index.php?g=417
ErrorDocument 418 /cgi-bin/rewrite-test/index.php?g=418
ErrorDocument 419 /cgi-bin/rewrite-test/index.php?g=419
ErrorDocument 420 /cgi-bin/rewrite-test/index.php?g=420
ErrorDocument 421 /cgi-bin/rewrite-test/index.php?g=421
ErrorDocument 422 /cgi-bin/rewrite-test/index.php?g=422
ErrorDocument 423 /cgi-bin/rewrite-test/index.php?g=423
ErrorDocument 424 /cgi-bin/rewrite-test/index.php?g=424
ErrorDocument 425 /cgi-bin/rewrite-test/index.php?g=425
ErrorDocument 426 /cgi-bin/rewrite-test/index.php?g=426
ErrorDocument 500 /cgi-bin/rewrite-test/index.php?g=500
ErrorDocument 501 /cgi-bin/rewrite-test/index.php?g=501
ErrorDocument 502 /cgi-bin/rewrite-test/index.php?g=502
ErrorDocument 503 /cgi-bin/rewrite-test/index.php?g=503
ErrorDocument 504 /cgi-bin/rewrite-test/index.php?g=504
ErrorDocument 505 /cgi-bin/rewrite-test/index.php?g=505
ErrorDocument 506 /cgi-bin/rewrite-test/index.php?g=506
ErrorDocument 507 /cgi-bin/rewrite-test/index.php?g=507
ErrorDocument 508 /cgi-bin/rewrite-test/index.php?g=508
ErrorDocument 509 /cgi-bin/rewrite-test/index.php?g=509
ErrorDocument 510 /cgi-bin/rewrite-test/index.php?g=510
&nbsp;
RewriteEngine On
RewriteBase /
&nbsp;
RewriteRule .* - [E=IN_AUTH_TYPE:%{AUTH_TYPE}]
RewriteRule .* - [E=IN_CONTENT_LENGTH:%{CONTENT_LENGTH}]
RewriteRule .* - [E=IN_CONTENT_TYPE:%{CONTENT_TYPE}]
RewriteRule .* - [E=IN_DATE_GMT:%{DATE_GMT}]
RewriteRule .* - [E=IN_DATE_LOCAL:%{DATE_LOCAL}]
RewriteRule .* - [E=IN_DOCUMENT_NAME:%{DOCUMENT_NAME}]
RewriteRule .* - [E=IN_DOCUMENT_PATH_INFO:%{DOCUMENT_PATH_INFO}]
RewriteRule .* - [E=IN_DOCUMENT_ROOT:%{DOCUMENT_ROOT}]
RewriteRule .* - [E=IN_DOCUMENT_URI:%{DOCUMENT_URI}]
RewriteRule .* - [E=IN_GATEWAY_INTERFACE:%{GATEWAY_INTERFACE}]
RewriteRule .* - [E=IN_LAST_MODIFIED:%{LAST_MODIFIED}]
RewriteRule .* - [E=IN_PATH_INFO:%{PATH_INFO}]
RewriteRule .* - [E=IN_PATH_TRANSLATED:%{PATH_TRANSLATED}]
RewriteRule .* - [E=IN_QUERY_STRING:%{QUERY_STRING}]
RewriteRule .* - [E=IN_QUERY_STRING_UNESCAPED:%{QUERY_STRING_UNESCAPED}]
RewriteRule .* - [E=IN_REMOTE_ADDR:%{REMOTE_ADDR}]
RewriteRule .* - [E=IN_REMOTE_HOST:%{REMOTE_HOST}]
RewriteRule .* - [E=IN_REMOTE_IDENT:%{REMOTE_IDENT}]
RewriteRule .* - [E=IN_REMOTE_PORT:%{REMOTE_PORT}]
RewriteRule .* - [E=IN_REMOTE_USER:%{REMOTE_USER}]
RewriteRule .* - [E=IN_REDIRECT_HANDLER:%{REDIRECT_HANDLER}]
RewriteRule .* - [E=IN_REDIRECT_QUERY_STRING:%{REDIRECT_QUERY_STRING}]
RewriteRule .* - [E=IN_REDIRECT_REMOTE_USER:%{REDIRECT_REMOTE_USER}]
RewriteRule .* - [E=IN_REDIRECT_STATUS:%{REDIRECT_STATUS}]
RewriteRule .* - [E=IN_REDIRECT_URL:%{REDIRECT_URL}]
RewriteRule .* - [E=IN_REQUEST_METHOD:%{REQUEST_METHOD}]
RewriteRule .* - [E=IN_REQUEST_URI:%{REQUEST_URI}]
RewriteRule .* - [E=IN_SCRIPT_FILENAME:%{SCRIPT_FILENAME}]
RewriteRule .* - [E=IN_SCRIPT_NAME:%{SCRIPT_NAME}]
RewriteRule .* - [E=IN_SERVER_ADMIN:%{SERVER_ADMIN}]
RewriteRule .* - [E=IN_SERVER_NAME:%{SERVER_NAME}]
RewriteRule .* - [E=IN_SERVER_ADDR:%{SERVER_ADDR}]
RewriteRule .* - [E=IN_SERVER_PORT:%{SERVER_PORT}]
RewriteRule .* - [E=IN_SERVER_PROTOCOL:%{SERVER_PROTOCOL}]
RewriteRule .* - [E=IN_SERVER_SIGNATURE:%{SERVER_SIGNATURE}]
RewriteRule .* - [E=IN_SERVER_SOFTWARE:%{SERVER_SOFTWARE}]
RewriteRule .* - [E=IN_USER_NAME:%{USER_NAME}]
RewriteRule .* - [E=IN_TZ:%{TZ}]
RewriteRule .* - [E=IN_API_VERSION:%{API_VERSION}]
RewriteRule .* - [E=IN_HTTPS:%{HTTPS}]
RewriteRule .* - [E=IN_HTTP_ACCEPT:%{HTTP_ACCEPT}]
RewriteRule .* - [E=IN_HTTP_ACCEPT_CHARSET:%{HTTP_ACCEPT_CHARSET}]
RewriteRule .* - [E=IN_HTTP_ACCEPT_ENCODING:%{HTTP_ACCEPT_ENCODING}]
RewriteRule .* - [E=IN_HTTP_ACCEPT_LANGUAGE:%{HTTP_ACCEPT_LANGUAGE}]
RewriteRule .* - [E=IN_HTTP_CACHE_CONTROL:%{HTTP_CACHE_CONTROL}]
RewriteRule .* - [E=IN_HTTP_CONNECTION:%{HTTP_CONNECTION}]
RewriteRule .* - [E=IN_HTTP_COOKIE:%{HTTP_COOKIE}]
RewriteRule .* - [E=IN_HTTP_FORWARDED:%{HTTP_FORWARDED}]
RewriteRule .* - [E=IN_HTTP_HOST:%{HTTP_HOST}]
RewriteRule .* - [E=IN_HTTP_KEEP_ALIVE:%{HTTP_KEEP_ALIVE}]
RewriteRule .* - [E=IN_HTTP_PROXY_CONNECTION:%{HTTP_PROXY_CONNECTION}]
RewriteRule .* - [E=IN_HTTP_REFERER:%{HTTP_REFERER}]
RewriteRule .* - [E=IN_HTTP_USER_AGENT:%{HTTP_USER_AGENT}]
RewriteRule .* - [E=IN_IS_SUBREQ:%{IS_SUBREQ}]
RewriteRule .* - [E=IN_ORIG_PATH_INFO:%{ORIG_PATH_INFO}]
RewriteRule .* - [E=IN_ORIG_PATH_TRANSLATED:%{ORIG_PATH_TRANSLATED}]
RewriteRule .* - [E=IN_ORIG_SCRIPT_FILENAME:%{ORIG_SCRIPT_FILENAME}]
RewriteRule .* - [E=IN_ORIG_SCRIPT_NAME:%{ORIG_SCRIPT_NAME}]
RewriteRule .* - [E=IN_PATH:%{PATH}]
RewriteRule .* - [E=IN_PHP_SELF:%{PHP_SELF}]
RewriteRule .* - [E=IN_REQUEST_FILENAME:%{REQUEST_FILENAME}]
RewriteRule .* - [E=IN_REQUEST_TIME:%{REQUEST_TIME}]
RewriteRule .* - [E=IN_SCRIPT_GROUP:%{SCRIPT_GROUP}]
RewriteRule .* - [E=IN_SCRIPT_USER:%{SCRIPT_USER}]
RewriteRule .* - [E=IN_THE_REQUEST:%{THE_REQUEST}]
RewriteRule .* - [E=IN_TIME:%{TIME}]
RewriteRule .* - [E=IN_TIME_DAY:%{TIME_DAY}]
RewriteRule .* - [E=IN_TIME_HOUR:%{TIME_HOUR}]
RewriteRule .* - [E=IN_TIME_MIN:%{TIME_MIN}]
RewriteRule .* - [E=IN_TIME_MON:%{TIME_MON}]
RewriteRule .* - [E=IN_TIME_SEC:%{TIME_SEC}]
RewriteRule .* - [E=IN_TIME_WDAY:%{TIME_WDAY}]
RewriteRule .* - [E=IN_TIME_YEAR:%{TIME_YEAR}]
RewriteRule .* - [E=IN_PATH:%{PATH}]
RewriteRule .* - [E=IN_SCRIPT_URI:%{SCRIPT_URI}]
RewriteRule .* - [E=IN_SCRIPT_URL:%{SCRIPT_URL}]
RewriteRule .* - [E=IN_UNIQUE_ID:%{UNIQUE_ID}]
&nbsp;
RewriteRule .* - [E=ENV_PATH:%{ENV:PATH}]
RewriteRule .* - [E=ENV_SCRIPT_URI:%{ENV:SCRIPT_URI}]
RewriteRule .* - [E=ENV_SCRIPT_URL:%{ENV:SCRIPT_URL}]
RewriteRule .* - [E=ENV_UNIQUE_ID:%{ENV:UNIQUE_ID}]
&nbsp;
RequestHeader set AUTH_TYPE "%{IN_AUTH_TYPE}e"
RequestHeader set CONTENT_LENGTH "%{IN_CONTENT_LENGTH}e"
RequestHeader set CONTENT_TYPE "%{IN_CONTENT_TYPE}e"
RequestHeader set DATE_GMT "%{IN_DATE_GMT}e"
RequestHeader set DATE_LOCAL "%{IN_DATE_LOCAL}e"
RequestHeader set DOCUMENT_NAME "%{IN_DOCUMENT_NAME}e"
RequestHeader set DOCUMENT_PATH_INFO "%{IN_DOCUMENT_PATH_INFO}e"
RequestHeader set DOCUMENT_ROOT "%{IN_DOCUMENT_ROOT}e"
RequestHeader set DOCUMENT_URI "%{IN_DOCUMENT_URI}e"
RequestHeader set GATEWAY_INTERFACE "%{IN_GATEWAY_INTERFACE}e"
RequestHeader set LAST_MODIFIED "%{IN_LAST_MODIFIED}e"
RequestHeader set PATH_INFO "%{IN_PATH_INFO}e"
RequestHeader set PATH_TRANSLATED "%{IN_PATH_TRANSLATED}e"
RequestHeader set QUERY_STRING "%{IN_QUERY_STRING}e"
RequestHeader set QUERY_STRING_UNESCAPED "%{IN_QUERY_STRING_UNESCAPED}e"
RequestHeader set REMOTE_ADDR "%{IN_REMOTE_ADDR}e"
RequestHeader set REMOTE_HOST "%{IN_REMOTE_HOST}e"
RequestHeader set REMOTE_IDENT "%{IN_REMOTE_IDENT}e"
RequestHeader set REMOTE_PORT "%{IN_REMOTE_PORT}e"
RequestHeader set REMOTE_USER "%{IN_REMOTE_USER}e"
RequestHeader set REDIRECT_HANDLER "%{IN_REDIRECT_HANDLER}e"
RequestHeader set REDIRECT_QUERY_STRING "%{IN_REDIRECT_QUERY_STRING}e"
RequestHeader set REDIRECT_REMOTE_USER "%{IN_REDIRECT_REMOTE_USER}e"
RequestHeader set REDIRECT_STATUS "%{IN_REDIRECT_STATUS}e"
RequestHeader set REDIRECT_URL "%{IN_REDIRECT_URL}e"
RequestHeader set REQUEST_METHOD "%{IN_REQUEST_METHOD}e"
RequestHeader set REQUEST_URI "%{IN_REQUEST_URI}e"
RequestHeader set SCRIPT_FILENAME "%{IN_SCRIPT_FILENAME}e"
RequestHeader set SCRIPT_NAME "%{IN_SCRIPT_NAME}e"
RequestHeader set SCRIPT_URI "%{IN_SCRIPT_URI}e"
RequestHeader set SCRIPT_URL "%{IN_SCRIPT_URL}e"
RequestHeader set SERVER_ADMIN "%{IN_SERVER_ADMIN}e"
RequestHeader set SERVER_NAME "%{IN_SERVER_NAME}e"
RequestHeader set SERVER_ADDR "%{IN_SERVER_ADDR}e"
RequestHeader set SERVER_PORT "%{IN_SERVER_PORT}e"
RequestHeader set SERVER_PROTOCOL "%{IN_SERVER_PROTOCOL}e"
RequestHeader set SERVER_SIGNATURE "%{IN_SERVER_SIGNATURE}e"
RequestHeader set SERVER_SOFTWARE "%{IN_SERVER_SOFTWARE}e"
RequestHeader set UNIQUE_ID "%{IN_UNIQUE_ID}e"
RequestHeader set USER_NAME "%{IN_USER_NAME}e"
RequestHeader set TZ "%{IN_TZ}e"
RequestHeader set API_VERSION "%{IN_API_VERSION}e"
RequestHeader set HTTPS "%{IN_HTTPS}e"
RequestHeader set HTTP_ACCEPT "%{IN_HTTP_ACCEPT}e"
RequestHeader set HTTP_ACCEPT_CHARSET "%{IN_HTTP_ACCEPT_CHARSET}e"
RequestHeader set HTTP_ACCEPT_ENCODING "%{IN_HTTP_ACCEPT_ENCODING}e"
RequestHeader set HTTP_ACCEPT_LANGUAGE "%{IN_HTTP_ACCEPT_LANGUAGE}e"
RequestHeader set HTTP_CACHE_CONTROL "%{IN_HTTP_CACHE_CONTROL}e"
RequestHeader set HTTP_CONNECTION "%{IN_HTTP_CONNECTION}e"
RequestHeader set HTTP_COOKIE "%{IN_HTTP_COOKIE}e"
RequestHeader set HTTP_FORWARDED "%{IN_HTTP_FORWARDED}e"
RequestHeader set HTTP_HOST "%{IN_HTTP_HOST}e"
RequestHeader set HTTP_KEEP_ALIVE "%{IN_HTTP_KEEP_ALIVE}e"
RequestHeader set HTTP_PROXY_CONNECTION "%{IN_HTTP_PROXY_CONNECTION}e"
RequestHeader set HTTP_REFERER "%{IN_HTTP_REFERER}e"
RequestHeader set HTTP_USER_AGENT "%{IN_HTTP_USER_AGENT}e"
RequestHeader set IS_SUBREQ "%{IN_IS_SUBREQ}e"
RequestHeader set ORIG_PATH_INFO "%{IN_ORIG_PATH_INFO}e"
RequestHeader set ORIG_PATH_TRANSLATED "%{IN_ORIG_PATH_TRANSLATED}e"
RequestHeader set ORIG_SCRIPT_FILENAME "%{IN_ORIG_SCRIPT_FILENAME}e"
RequestHeader set ORIG_SCRIPT_NAME "%{IN_ORIG_SCRIPT_NAME}e"
RequestHeader set PATH "%{IN_PATH}e"
RequestHeader set PHP_SELF "%{IN_PHP_SELF}e"
RequestHeader set REQUEST_FILENAME "%{IN_REQUEST_FILENAME}e"
RequestHeader set REQUEST_TIME "%{IN_REQUEST_TIME}e"
RequestHeader set SCRIPT_GROUP "%{IN_SCRIPT_GROUP}e"
RequestHeader set SCRIPT_USER "%{IN_SCRIPT_USER}e"
RequestHeader set THE_REQUEST "%{IN_THE_REQUEST}e"
RequestHeader set TIME "%{IN_TIME}e"
RequestHeader set TIME_DAY "%{IN_TIME_DAY}e"
RequestHeader set TIME_HOUR "%{IN_TIME_HOUR}e"
RequestHeader set TIME_MIN "%{IN_TIME_MIN}e"
RequestHeader set TIME_MON "%{IN_TIME_MON}e"
RequestHeader set TIME_SEC "%{IN_TIME_SEC}e"
RequestHeader set TIME_WDAY "%{IN_TIME_WDAY}e"
RequestHeader set TIME_YEAR "%{IN_TIME_YEAR}e"
&nbsp;
SetEnvIfNoCase ^WWW-Auth "(.+)" HTTP_WWW_AUTHORIZATION=$1
SetEnvIfNoCase ^If "(.+)" HTTP_IF_MODIFIED_SINCE=$1
SetEnvIfNoCase ^If-None-Match$ "(.+)" HTTP_IF_NONE_MATCH=$1
SetEnvIfNoCase ^Cache-Control$ "(.+)" HTTP_CACHE_CONTROL=$1
SetEnvIfNoCase ^Connection$ "(.+)" HTTP_CONNECTION=$1
SetEnvIfNoCase ^Keep-Alive$ "(.+)" HTTP_KEEP_ALIVE=$1
SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
SetEnvIfNoCase ^Content-Type$ "(.+)" HTTP_CONTENT_TYPE=$1
SetEnvIfNoCase ^Content-Length$ "(.+)" HTTP_CONTENT_LENGTH=$1
SetEnvIfNoCase ^Authorization$ ".+username=\"([a-zA-Z0-9]+)\".+" REMOTE_USER=$1
SetEnvIfNoCase Server_Addr "(.+)" SERVER_ADDR=$1
SetEnvIfNoCase Request_Method "(.+)" REQUEST_METHOD=$1
SetEnvIfNoCase Request_Protocol "(.+)" REQUEST_PROTOCOL=$1
SetEnvIfNoCase Request_URI "(.+)" REQUEST_URI=$1
&nbsp;
RequestHeader set IF_MODIFIED_SINCE "%{HTTP_IF_MODIFIED_SINCE}e"
RequestHeader set IF_NONE_MATCH "%{HTTP_IF_NONE_MATCH}e"
RequestHeader set CACHE_CONTROL "%{HTTP_CACHE_CONTROL}e"
RequestHeader set CONNECTION "%{HTTP_CONNECTION}e"
RequestHeader set KEEP_ALIVE "%{HTTP_KEEP_ALIVE}e"
RequestHeader set AUTHORIZATION "%{HTTP_AUTHORIZATION}e"
RequestHeader set REMOTE_USER "%{REMOTE_USER}e"
RequestHeader set CONTENT_TYPE "%{HTTP_CONTENT_TYPE}e"
RequestHeader set CONTENT_LENGTH "%{HTTP_CONTENT_LENGTH}e"
RequestHeader set SERVER_ADDR "%{SERVER_ADDR}e"
RequestHeader set REQUEST_METHOD "%{REQUEST_METHOD}e"
RequestHeader set REQUEST_PROTOCOL "%{REQUEST_PROTOCOL}e"
RequestHeader set REQUEST_URI "%{REQUEST_URI}e"
&nbsp;
RequestHeader set UNIQUE_ID "%{ENV_UNIQUE_ID}e"
RequestHeader set SCRIPT_URL "%{ENV_SCRIPT_URL}e"
RequestHeader set SCRIPT_URI "%{ENV_SCRIPT_URI}e"
RequestHeader set PATH "%{ENV_PATH}e"
&nbsp;
Options +ExecCGI +FollowSymLinks
&nbsp;
Order Deny,Allow
Deny from All
Allow from 208.113.134.190  64.111.114.111 208.113.134.203 208.113.152.201 env=REDIRECT_STATUS
Satisfy Any
&nbsp;
SecFilterEngine Off</pre>



<h2>More Mod_Security (1)</h2>
<pre>#
# Order Deny,Allow
# First, all Allow directives are evaluated; at least one must match, or the request is rejected.
# Next, all Deny directives are evaluated. If any matches, the request is rejected.
# Last, any requests which do not match an Allow or a Deny directive are denied by default.
#
Order Allow,Deny
Allow from all
Deny from 217.219.
&nbsp;
#Order Deny,Allow
# First, all Deny directives are evaluated; if any match, the request is denied unless it also matches an Allow directive.
# Any requests which do not match any Allow or Deny directives are permitted.
&nbsp;
#SetEnvIf content-type (multipart/form-data)(.*) NEW_CONTENT_TYPE=application/x-www-form-urlencoded$2 OLD_CONTENT_TYPE=$1$2
#RequestHeader set content-type %{NEW_CONTENT_TYPE}e env=NEW_CONTENT_TYPE
SetEnvIfNoCase Content-Type "^multipart/form-data" !MODSEC_NOPOSTBUFFERING
SetEnvIfNoCase Content-Type "^application/x-www-form-urlencoded" !MODSEC_NOPOSTBUFFERING
SetEnv suppress-error-charset
SetEnvIfNoCase Content-Type "^multipart/form-data" !MODSEC_NOPOSTBUFFERING
&nbsp;
SetEnvIf Request_URI "^/(cgi-bin/search\.php|cgi-bin/java\.cgi|wp-admin/.*)" MODSEC_ENABLE=Off
SetEnvIf Request_URI "^/(online-tools/js-compress.*)" "MODSEC_NOPOSTBUFFERING=Do not buffer file uploads"
SetEnvIfNoCase Remote_Addr ^208\.113\.134\.190$ MODSEC_ENABLE=Off
SetEnvIfNoCase Remote_Addr ^64\.111\.114\.111$ MODSEC_ENABLE=Off
&nbsp;
### Section 1: Global Environment
#
# The directives in this section affect the overall operation of Apache,
# such as the number of concurrent requests it can handle or where it
# can find its configuration files.
#
#
# TZ: Your address, where problems with the server should be
# e-mailed.  This address appears on some server-generated pages, such
# as error documents.  e.g. admin@your-domain.com
#
SetEnv TZ America/Indianapolis
&nbsp;
#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed.  This address appears on some server-generated pages, such
# as error documents.  e.g. admin@your-domain.com
#
SetEnv SERVER_ADMIN webmaster@askapache.com
&nbsp;
#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
# Set to one of:  On | Off | EMail
#
ServerSignature Off
&nbsp;
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs/2.0/mod/core.html#options
# for more information.
#
Options -Indexes -Includes -ExecCGI -MultiViews
&nbsp;
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
DirectoryIndex index.php
&nbsp;
#
# Action lets you define media types that will execute a script whenever
# a matching file is called. This eliminates the need for repeated URL
# pathnames for oft-used CGI file processors.
# Format: Action media/type /cgi-script/location
# Format: Action handler-name /cgi-script/location
#
Action php5-cgi /bin/php.cgi
&nbsp;
#
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
AddHandler php5-cgi .php .inc
&nbsp;
#
# Commonly used filename extensions to character sets. You probably
# want to avoid clashes with the language extensions, unless you
# are good at carefully testing your setup after each change.
# See http://www.iana.org/assignments/character-sets for the
# official list of charset names and their respective RFCs.
#
AddDefaultCharset UTF-8
&nbsp;
#
# AddType allows you to add to or override the MIME configuration
# file mime.types for specific file types.
#
#
AddType &#039;application/rdf+xml; charset=UTF-8&#039; .rdf
AddType &#039;application/xhtml+xml; charset=UTF-8&#039; .xhtml
AddType &#039;application/xhtml+xml; charset=UTF-8&#039; .xhtml.gz
AddType &#039;text/html; charset=UTF-8&#039; .html
AddType &#039;text/html; charset=UTF-8&#039; .html.gz
AddType application/octet-stream .rar .chm .bz2 .tgz .msi .pdf .exe
AddType application/vnd.ms-excel .csv
AddType application/x-httpd-php-source .phps
AddType application/x-pilot .prc .pdb
AddType application/x-shockwave-flash .swf
AddType application/xrds+xml .xrdf
AddType text/plain .ini .sh .bsh .bash .awk .nawk .gawk .csh .var .c .in .h .asc .md5 .sha .sha1
AddType video/x-flv .flv
&nbsp;
#
# AddEncoding allows you to have certain browsers uncompress
# information on the fly. Note: Not all browsers support this.
# Despite the name similarity, the following Add* directives have nothing
# to do with the FancyIndexing customization directives above.
#
AddEncoding x-compress .Z
AddEncoding x-gzip .gz .tgz
&nbsp;
#
# DefaultType: the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain" is
# a good value.  If most of your content is binary, such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
DefaultType text/html</pre>




<h2>Error Documents</h2>
<pre>#
# Customizable error responses come in three flavors:
# 1) plain text 2) local redirects 3) external redirects
#
#100 Continue
#101 Switching Protocols
#102 Processing
#200 OK
#201 Created
#202 Accepted
#203 Non-Authoritative Information
#204 No Content
#205 Reset Content
#206 Partial Content
#207 Multi-Status
#300 Multiple Choices
#301 Moved Permanently
#302 Found
#303 See Other
#304 Not Modified
#305 Use Proxy
#306 unused
#307 Temporary Redirect
#400 Bad Request
#401 Authorization Required
#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
#416 Requested Range Not Satisfiable
#417 Expectation Failed
#418 unused
#419 unused
#420 unused
#421 unused
#422 Unprocessable Entity
#423 Locked
#424 Failed Dependency
#425 No code
#426 Upgrade Required
#500 Internal Server Error
#501 Method Not Implemented
#502 Bad Gateway
#503 Service Temporarily Unavailable
#504 Gateway Time-out
#505 HTTP Version Not Supported
#506 Variant Also Negotiates
#507 Insufficient Storage
#508 unused
#509 unused
#510 Not Extended
&nbsp;
#ErrorDocument 100 /e/100_CONTINUE.html
#ErrorDocument 101 /e/101_SWITCHING_PROTOCOLS.html
#ErrorDocument 102 /e/102_PROCESSING.html
&nbsp;
#ErrorDocument 200 /e/200_OK.html
#ErrorDocument 201 /e/201_CREATED.html
#ErrorDocument 202 /e/202_ACCEPTED.html
#ErrorDocument 203 /e/203_NON_AUTHORITATIVE.html
#ErrorDocument 204 /e/204_NO_CONTENT.html
#ErrorDocument 205 /e/205_RESET_CONTENT.html
#ErrorDocument 206 /e/206_PARTIAL_CONTENT.html
#ErrorDocument 207 /e/207_MULTI_STATUS.html
&nbsp;
#ErrorDocument 300 /e/300_MULTIPLE_CHOICES.html
#ErrorDocument 301 /e/301_MOVED_PERMANENTLY.html
#ErrorDocument 302 /e/302_MOVED_TEMPORARILY.html
#ErrorDocument 303 /e/303_SEE_OTHER.html
#ErrorDocument 304 /e/304_NOT_MODIFIED.html
#ErrorDocument 305 /e/305_USE_PROXY.html
#ErrorDocument 307 /e/307_TEMPORARY_REDIRECT.html
&nbsp;
ErrorDocument 400 /e/400_BAD_REQUEST.html
ErrorDocument 401 /e/401_UNAUTHORIZED.html
ErrorDocument 402 /e/402_PAYMENT_REQUIRED.html
ErrorDocument 403 /e/403_FORBIDDEN.html
#ErrorDocument 404 /e/404_NOT_FOUND.html
ErrorDocument 404 /index.php?error=404
ErrorDocument 405 /e/405_METHOD_NOT_ALLOWED.html
ErrorDocument 406 /e/406_NOT_ACCEPTABLE.html
ErrorDocument 407 /e/407_PROXY_AUTHENTICATION_REQUIRED.html
ErrorDocument 408 /e/408_REQUEST_TIME_OUT.html
ErrorDocument 409 /e/409_CONFLICT.html
ErrorDocument 410 /e/410_GONE.html
ErrorDocument 411 /e/411_LENGTH_REQUIRED.html
ErrorDocument 412 /e/412_PRECONDITION_FAILED.html
ErrorDocument 413 /e/413_REQUEST_ENTITY_TOO_LARGE.html
ErrorDocument 414 /e/414_REQUEST_URI_TOO_LARGE.html
ErrorDocument 415 /e/415_UNSUPPORTED_MEDIA_TYPE.html
ErrorDocument 416 /e/416_RANGE_NOT_SATISFIABLE.html
ErrorDocument 417 /e/417_EXPECTATION_FAILED.html
ErrorDocument 422 /e/422_UNPROCESSABLE_ENTITY.html
ErrorDocument 423 /e/423_LOCKED.html
ErrorDocument 424 /e/424_FAILED_DEPENDENCY.html
ErrorDocument 426 /e/426_UPGRADE_REQUIRED.html
ErrorDocument 500 /e/500_INTERNAL_SERVER_ERROR.html
ErrorDocument 501 /e/501_NOT_IMPLEMENTED.html
ErrorDocument 502 /e/502_BAD_GATEWAY.html
ErrorDocument 503 /e/503_SERVICE_UNAVAILABLE.html
ErrorDocument 504 /e/504_GATEWAY_TIME_OUT.html
ErrorDocument 505 /e/505_VERSION_NOT_SUPPORTED.html
ErrorDocument 506 /e/506_VARIANT_ALSO_VARIES.html
ErrorDocument 507 /e/507_INSUFFICIENT_STORAGE.html
ErrorDocument 510 /e/510_NOT_EXTENDED.html</pre>



<h2>Caching</h2>
<pre>#
#  HEADERS and CACHING
#
Header unset Pragma
FileETag None
Header unset ETag
&nbsp;
# 1 YEAR
&lt;filesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$"&gt;
Header unset P3P
Header unset Pragma
FileETag None
Header unset ETag
Header set Cache-Control "public,max-age=29030400"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
Header unset Last-Modified
&lt;/filesMatch&gt;
&nbsp;
# 2 HOURS
&lt;filesMatch "\.(html|htm|xml|txt|xsl|rdf|rss)$"&gt;
&lt;ifModule mod_expires.c&gt;
ExpiresActive On
ExpiresDefault A3600
&lt;/ifModule&gt;
&lt;/filesMatch&gt;</pre>



<h2>Redirect Hack</h2>
<pre>#Redirect 400 /e/400
#Redirect 401 /e/401
#Redirect 402 /e/402
#Redirect 403 /e/403
Redirect 404 /index.php?error=404
#Redirect 405 /e/405
#Redirect 406 /e/406
#Redirect 407 /e/407
#Redirect 408 /e/408
#Redirect 409 /e/409
#Redirect 410 /e/410
#Redirect 411 /e/411
#Redirect 412 /e/412
#Redirect 413 /e/413
#Redirect 414 /e/414
#Redirect 415 /e/415
#Redirect 416 /e/416
#Redirect 417 /e/417
#Redirect 418 /e/418
#Redirect 419 /e/419
#Redirect 420 /e/420
#Redirect 421 /e/421
#Redirect 422 /e/422
#Redirect 423 /e/423
#Redirect 424 /e/424
#Redirect 425 /e/425
#Redirect 426 /e/426
#Redirect 500 /e/500
#Redirect 501 /e/501
#Redirect 502 /e/502
#Redirect 503 /e/503
#Redirect 504 /e/504
#Redirect 505 /e/505
#Redirect 506 /e/506
#Redirect 507 /e/507
#Redirect 508 /e/508
#Redirect 509 /e/509
#Redirect 510 /e/510</pre>

<h2>301 PERMANENT REDIRECTS</h2>
<pre>#
# Redirect allows you to tell clients about documents which used to exist in
# your server&#039;s namespace, but do not anymore. This allows you to tell the
# clients where to look for the relocated document.
#
Redirect 301 /12-lessons-for-those-afraid-of-css.html http://www.askapache.com/css/12-lessons-for-those-afraid-of-css.html
Redirect 301 /2006/htaccess/htaccesselite-ultimate-htaccess-article.html http://www.askapache.com/htaccess/apache-htaccess.html
Redirect 301 /2007/phpbb/sending-post-form-data-with-php-curl.html http://www.askapache.com/htaccess/sending-post-form-data-with-php-curl.html
Redirect 301 /2007/webmaster/custom-phpini-with-fastcgi-on-dreamhost.html http://www.askapache.com/dreamhost/custom-phpini-with-fastcgi-on-dreamhost.html
Redirect 301 /2007/webmaster/custom-phpini-with-fastcgi-on-dreamhost.html http://www.askapache.com/dreamhost/custom-phpini-with-fastcgi-on-dreamhost.html
Redirect 301 /2007/webmaster/php-and-ajax-shell-console.html http://www.askapache.com/tools/php-and-ajax-shell-console.html
Redirect 301 /27-request-methods-for-use-with-apache-and-rewritecond-and-htaccess.html http://www.askapache.com/htaccess/27-request-methods-for-use-with-apache-and-rewritecond-and-htaccess.html
Redirect 301 /404-google-wordpress-plugin.html http://www.askapache.com/seo/404-google-wordpress-plugin.html
Redirect 301 /503-service-temporarily-unavailable.html http://www.askapache.com/htaccess/503-service-temporarily-unavailable.html
Redirect 301 /Overview-about.rdf http://www.askapache.com/askapache-home.rdf
Redirect 301 /abbr-acronym.html http://www.askapache.com/xhtml/abbr-acronym.html
Redirect 301 /adsense-robots.html http://www.askapache.com/google/adsense-robots.html
Redirect 301 /alexa-toolbar-firefox.html http://www.askapache.com/tools/alexa-toolbar-firefox.html
Redirect 301 /allowing-access-from-1-static-ip-and-deny-the-rest.html http://www.askapache.com/htaccess/apache-htaccess.html
Redirect 301 /anti-virus-spyware-rootkit.html http://www.askapache.com/security/anti-virus-spyware-rootkit.html
Redirect 301 /apache-ssl-in-htaccess-examples.html http://www.askapache.com/htaccess/apache-ssl-in-htaccess-examples.html
Redirect 301 /awk-tutorial.html http://www.askapache.com/awk/awk-tutorial.html
Redirect 301 /best-adsense-optimization.html http://www.askapache.com/wordpress/best-adsense-optimization.html
Redirect 301 /commonly-used-htaccess-code-examples.html http://www.askapache.com/htaccess/commonly-used-htaccess-code-examples.html
Redirect 301 /css-background-image-sprite.html http://www.askapache.com/css/css-background-image-sprite.html
Redirect 301 /css-browser-screenshots.html http://www.askapache.com/tools/css-browser-screenshots.html
Redirect 301 /css-class-example.html http://www.askapache.com/css/css-class-example.html
Redirect 301 /curl-multi-downloads.html http://www.askapache.com/php/curl-multi-downloads.html
Redirect 301 /custom-boot-menu-in-windows-xp.html http://www.askapache.com/windows/custom-boot-menu-in-windows-xp.html
Redirect 301 /donate http://www.dreamhost.com/donate.cgi?id=8261
Redirect 301 /donate/ http://www.dreamhost.com/donate.cgi?id=8261
Redirect 301 /htaccess.txt http://z.askapache.com/p/htaccess.txt
Redirect 301 /htaccess/404-errorpages.html http://www.askapache.com/seo/google-ajax-search-seo-tips.html
Redirect 301 /htaccess/feedsmith http://www.askapache.com/htaccess/feedsmith-htaccess.html
Redirect 301 /htaccess/http-status-codes.html http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html
Redirect 301 /htaccess/instruct-search-engines-to-come-back-to-site-after-you-finish-working-on-it.html http://www.askapache.com/htaccess/503-service-temporarily-unavailable.html
Redirect 301 /htaccess/speed-up-the-apache-web-server-with-configuration-hacks.html http://www.askapache.com/htaccess/apache-web-server-speed-configuration-hacks.html
Redirect 301 /instruct-search-engines-to-come-back-to-site-after-you-finish-working-on-it.html http://www.askapache.com/htaccess/503-service-temporarily-unavailable.html
Redirect 301 /security/bypassing-vlan.html http://www.askapache.com/security/hacking-vlan-switched-networks.html
Redirect 301 /security/bypassing-vlanbypassing-vlan.html http://www.askapache.com/security/hacking-vlan-switched-networks.html
Redirect 301 /security/rigging-the-dreamhost-site-of-the-month-contest.html http://www.askapache.com/dreamhost/rigging-the-dreamhost-site-of-the-month-contest.html
Redirect 301 /seo/tailrankcom-robot.html http://www.askapache.com/seo/tailrank-robot.html
Redirect 301 /webmaster/caching-tutorial-for-webmasters.html http://www.askapache.com/htaccess/caching-tutorial-for-webmasters.html
Redirect 301 /webmaster/lft-traceroute-tool.html http://www.askapache.com/tools/lft-traceroute-tool.html</pre>



<h2>301 PERMANENT REDIRECTMATCH</h2>
<pre>#
#  PERMANENT REDIRECTMATCH
#
#RedirectMatch 301 ^/&amp;(.*)$ http://www.askapache.com/
RedirectMatch 301 ^/(.+)\.html/$ http://www.askapache.com/$1.html
RedirectMatch 301 ^/&amp;amp(.*)$ http://www.askapache.com/
RedirectMatch 301 ^/.*feed\.gif$ http://z.askapache.com/feed.gif
RedirectMatch 301 ^/([^/]+)//$ http://www.askapache.com/$1/
RedirectMatch 301 ^/(.+)/htaccesselite-ultimate-htaccess-article.html(.*) http://www.askapache.com/htaccess/apache-htaccess.html
RedirectMatch 301 ^/(.+)\.html/([a-z][a-z])/$ http://www.askapache.com/$1.html
RedirectMatch 301 ^/([\(]+)(.*)$ http://www.askapache.com/
RedirectMatch 301 ^/([^9]*)9O1X.3y(.*)/(.*)$ http://www.askapache.com/$2
RedirectMatch 301 ^/.3y(.*)$ http://www.askapache.com/
RedirectMatch 301 ^/200([0-9])/([0-9])(.*)$ http://www.askapache.com/top-100/
RedirectMatch 301 ^/200([0-9])/([^01])(.*)$ http://www.askapache.com/$2$3
RedirectMatch 301 ^/about/glossary(.*)$ http://www.askapache.com/glossary$1
RedirectMatch 301 ^/apache-speed(.*)$ http://www.askapache.com/htaccess/apache-speed$1
RedirectMatch 301 ^/category/(.+)$ http://www.askapache.com/$1
RedirectMatch 301 ^/docs/(.*)$ http://askapache.info/$1
RedirectMatch 301 ^/htaccess/feedsmith-htaccess(.*) http://www.askapache.com/htaccess/redirecting-wordpress-feeds-to-feedburner.html
RedirectMatch 301 ^/robots-txt(.*)$ http://www.askapache.com/robots.txt
RedirectMatch 301 ^/hosting/?$ http://www.askapache.com/hosting/
RedirectMatch 301 ^/.+favicon.ico$ http://www.askapache.com/favicon.ico
#RedirectMatch 301 ^/wp-content/uploads/(.*)$ http://z.askapache.com/uploads/$1
#RedirectMatch 301 ^/z/(.+)$ http://z.askapache.com/$1
#RedirectMatch 301 ^/(z|t|i|j|c|p)/(.*)$ http://z.askapache.com/$1/$2
&nbsp;
#
#  TEMPORARY REDIRECTMATCH
#
RedirectMatch 307 ^/getflash/?$ http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash
RedirectMatch 307 ^/dream/?$ http://www.askapache.com/dreamhost/
RedirectMatch 307 ^/(cse|apachecse|apachecsetest|apachesearch)/?$ http://www.google.com/coop/cse?cx=002660089121042511758%3Akk7rwc2gx0i
RedirectMatch 307 ^/search/lr-lang(.*)$ http://feeds.askapache.com/apache/htaccess
&nbsp;
#
#  PERMANENT GONE
#
RedirectMatch 410 ^/funny(.*)</pre>






<h2>My Favorite modsec_v1 stuff</h2>
<pre># Pass: Allows request to continue, further filters could still halt request.
# Allow: Allows matching requests through, will not be tested against other filters.
# Deny: Stops the request outright, returns a HTTP 500 error code by default.
# Status: Used to specify an alternate HTTP error code.
# Redirect: Matching requests are redirected to the provided URL.
# Exec: Allows execution of a local system binary or script.
# Log: Logs request only.
# Nolog: Does not log request.
# Chain: Allows you to create list of filters for more granulated security. All filters must be cleared before action is taken with the final filter.
&nbsp;
SecFilterEngine On
SecFilterCheckURLEncoding On
SecFilterCheckUnicodeEncoding Off
SecFilterScanPOST On
&nbsp;
#SecUploadKeepFiles On
#SecUploadDir /home/askapache/sites/askapache.com/logs/sec-upload
#SecUploadApproveScript /home/askapache/sites/askapache.com/htdocs/cgi-bin/check.sh
&nbsp;
#SecRuleEngine On
#SecAuditEngine On
#SecAuditEngine Off
SecAuditEngine RelevantOnly
SecAuditLog /home/askapache/sites/askapache.com/logs/modsec_audit.log
SecFilterDebugLog /home/askapache/sites/askapache.com/logs/modsec_debug.log
SecFilterDebugLevel 1
#SecAuditLogRelevantStatus "^(?:1|2(?!00)|5|4(?!04))"
SecAuditLogRelevantStatus "^(1|2(?!00)|4([0-9](0|1|2|5|6|7|8|9))|5)"
SecFilterForceByteRange 1 255
&nbsp;
#SecFilterInheritance Off
# 0 EMERGENCY - system is unusable
# 1 ALERT - action must be taken immediately
# 2 CRITICAL - critical conditions
# 3 ERROR - error conditions
# 4 WARNING - warning conditions
# 5 NOTICE - normal but significant conditions
# 6 INFO - informational
# 7 DEBUG - debug-level messages
&nbsp;
SecFilterDefaultAction "deny,severity:6,status:403"
&nbsp;
#SecFilterSelective REQUEST_METHOD "POST" "pass,auditlog,severity:6"
SecFilterSelective REQUEST_URI "^/(xmlrpc|wp-comments-post)\.php" "pass,log,auditlog,severity:6"
#SecFilterSelective REMOTE_ADDR ^$ "pass,log,auditlog,severity:6"
#SecFilterSelective REMOTE_ADDR ^203\.221\.91\.20$ "pass,log,auditlog,severity:6"
&nbsp;
#SecFilterSelective REQUEST_URI "^/htaccess.*" "pass,log,auditlog"
#SecFilterSelective REQUEST_URI "^/feed.*" "pass,log,auditlog"
#SecFilterSelective REQUEST_URI "^/.*trackback.*" "pass,log,auditlog"
#SecFilterSelective REQUEST_URI "^/valid.*" "pass,log,auditlog"
&nbsp;
#Enforce proper HTTP requests
SecFilterSelective SERVER_PROTOCOL "!^HTTP/(0\.9|1\.0|1\.1)$" "id:340000,rev:1,severity:6,msg:&#039;Bad HTTP Protocol&#039;"
&nbsp;
# Only accept request encodings we know how to handle
SecFilterSelective REQUEST_METHOD "!^(GET|HEAD|POST)$" "chain,id:340001,rev:1,severity:6,msg:&#039;Restricted HTTP function,status:405&#039;"
SecFilterSelective HTTP_Content-Type "!(^$|^application/x-www-form-urlencoded$|^multipart/form-data)"
&nbsp;
# Require Content-Length to be provided with every POST request
SecFilterSelective REQUEST_METHOD "^POST$" "chain,id:340003,rev:1,severity:6,msg:&#039;Content Length not provided with POST&#039;,status:411"
SecFilterSelective HTTP_Content-Length "^$"
&nbsp;
# Don&#039;t accept transfer encodings we know we don&#039;t handle
# (and you don&#039;t need it anyway)
SecFilterSelective HTTP_Transfer-Encoding "!^$" "id:340004,rev:1,severity:6,msg:&#039;Dis-allowed Transfer Encoding&#039;"
&nbsp;
#Generic rule for allowed characters, adjust for your site before activating
##SecFilterSelective REQUEST_URI "!^[a-zA-Z0-9\.\+\_\/\-\?\=\&amp;\%\#]+$" "chain,id:390002,rev:1,severity:4,msg:&#039;Restricted HTTP character set&#039;"
##SecFilterSelective REQUEST_URI "!^/(openid|wp-admin|wp-includes|wp-content|wp-login.php)"
&nbsp;
#HTTP response splitting generic sigs
#SecFilter "Content-Length\:.*Content-Type\:.*Content-Type\:" "id:340005,rev:1,severity:4,msg:&#039;HTTP response splitting&#039;"
&nbsp;
#HTTP response splitting generic sigs
#SecFilter "Content-Length\:" "chain,id:340006,rev:1,severity:4,msg:&#039;HTTP response splitting&#039;"
#SecFilter "Content-Type\:"
&nbsp;
#catch smuggling attacks
#SecFilter "^(GET|POST).*Host:.*^(GET|POST)"  "id:300012,rev:1,severity:4,msg:&#039;catch smuggling attacks&#039;"
&nbsp;
#XSS insertion into Content-Type
#SecFilterSelective THE_REQUEST "Content-Type\:.*(&lt;[[:space:]]*(script|about|applet|activex|chrome)*&gt;.*(script|about|applet|activex|chrome)[[:space:]]*&gt;|onmouseover=|javascript\:)" "id:300002,rev:1,severity:4,msg:&#039;XSS attack in Content-type header&#039;"
&nbsp;
#Code injection via content length
#SecFilterSelective HTTP_Content-Length|HTTP_USER_AGENT "\;(system|passthru|exec)\(" "id:330003,rev:1,severity:4,msg:&#039;Code Injection in Content-Length header&#039;"
&nbsp;
#Don&#039;t accept chunked encodings modsecurity can not look at these, so this is a hole that can bypass your rules, the rule before this one should cover this, but hey paranoia is cheap
#SecFilterSelective HTTP_Transfer-Encoding "chunked" "id:300003,rev:1,severity:4,msg:&#039;Chunked Transfer Encoding denied&#039;"
&nbsp;
##generic recursion signatures
#SecFilterSelective REQUEST_URI "\.\./\.\./" "id:300004,rev:2,severity:4,msg:&#039;Generic Path Recursion1 denied&#039;"
#SecFilterSelective THE_REQUEST "\.\|\./\.\|\./\.\|" "id:300005,rev:1,severity:4,msg:&#039;Generic Path Recursion2 denied&#039;"
#SecFilterSelective THE_REQUEST "\.\.\./" "id:300006,rev:1,severity:4,msg:&#039;Bogus Path denied&#039;"
&nbsp;
#Generic PHP exploit signatures
#SecFilterSelective REQUEST_URI "&lt;\?php (chr|fwrite|fopen|system|echr|passthru|popen|proc_open|shell_exec|exec|proc_nice|proc_terminate|proc_get_status|proc_close|pfsockopen|leak|apache_child_terminate|posix_kill|posix_mkfifo|posix_setpgid|posix_setsid|posix_setuid|phpinfo)\(.*\)\;" "id:330002,rev:1,severity:4,msg:&#039;Generic PHP exploit pattern denied&#039;"
&nbsp;
#Prevent SQL injection in cookies
##SecFilterSelective COOKIE_VALUES "((select|grant|delete|insert|drop|alter|replace|truncate|update|create|rename|describe)[[:space:]]+[A-Z|a-z|0-9|\*| |\,]+[[:space:]]+(from|into|table|database|index|view)[[:space:]]+[A-Z|a-z|0-9|\*| |\,]|UNION SELECT.*\&#039;.*\&#039;.*,[0-9].*INTO.*FROM)" "id:300011,rev:1,severity:4,msg:&#039;Generic SQL injection in cookie&#039;"
&nbsp;
#Prevent SQL injection in UA
##SecFilterSelective HTTP_USER_AGENT "((select|grant|delete|insert|drop|alter|replace|truncate|update|create|rename|describe)[[:space:]]+[A-Z|a-z|0-9|\*| |\,]+[[:space:]]+(from|into|table|database|index|view)[[:space:]]+[A-Z|a-z|0-9|\*| |\,]|UNION SELECT.*\&#039;.*\&#039;.*,[0-9].*INTO.*FROM)" "id:300012,rev:1,severity:4,msg:&#039;Generic SQL injection in User Agent header&#039;"
&nbsp;
# Generic filter to prevent SQL injection attacks
# Understand that all SQL filters are very limited and are very difficult to prevent false postives and negatives.
# Please report false positives/negatives to mike@gotroot.com
#SecFilter "((select|grant|delete|insert|drop|alter|replace|truncate|update|create|rename|describe)[[:space:]]+[A-Z|a-z|0-9|\*| |\,]+[[:space:]]+(from|into|table|database|index|view)[[:space:]]+[A-Z|a-z|0-9|\*| |\,]|UNION SELECT.*\&#039;.*\&#039;.*,[0-9].*INTO.*FROM)" "id:300013,rev:1,severity:4,msg:&#039;Generic SQL injection protection&#039;"
&nbsp;
#generic XSS PHP attack types
##SecFilterSelective REQUEST_URI "\.php\?" "chain,id:300010,rev:1,severity:4,msg:&#039;Generic PHP XSS exploit pattern denied&#039;"
#SecFilter "(javascript\:/(.*new\x20ActiveXObject.*Sh\.regwrite|.*window\.opener\.document\.body.\innerHTML=window\.opener\.document\.body\.innerHTML\.replace)|onmouseover=\&#039;javascript)"
&nbsp;
#Generic XSS filter
#please report false positives
##SecFilterSelective REQUEST_URI "!/mt\.cgi" "chain,msg:&#039;XSS2&#039;"
#SecFilter "&lt;[[:space:]]*(script|about|applet|activex|chrome)*&gt;.*(script|about|applet|activex|chrome)[[:space:]]*&gt;"
&nbsp;
#XSS in referrer and UA headers
##SecFilterSelective HTTP_REFERER|HTTP_USER_AGENT "&lt;[[:space:]]*(script|about|applet|activex|chrome)*&gt;.*(script|about|applet|activex|chrome)[[:space:]]*&gt;" "msg:&#039;XSS3&#039;"
&nbsp;
#HTTP header PHP code injection attacks
##SecFilterSelective HTTP_CLIENT_IP|HTTP_USER_AGENT|HTTP_Referer "(&lt;\?php|&lt;[[:space:]]?\?[[:space:]]?php|&lt;\? php)" "msg:&#039;PHP1&#039;"
&nbsp;
#Generic PHP remote file injection
##SecFilterSelective REQUEST_URI "!(/do_command)" "chain,msg:&#039;PHP2&#039;"
##SecFilterSelective REQUEST_URI "\.php\?.*=(https?|ftp)\:/.*(cmd|command)="
&nbsp;
#script, perl, etc. code in HTTP_Referer string
##SecFilterSelective HTTP_Referer "\#\!.*/" "msg:&#039;perl script1&#039;"
&nbsp;
#remote file inclusion generic attack signature
#SecFilterSelective THE_REQUEST  "\.(dat|gif|jpg|png|bmp|txt|vir|dot)\?" "chain,msg:&#039;remote 1&#039;"
#SecFilter "((name|pm_path|pagina|path|include_location|root|page|open)=(http|https|ftp)|(cmd|command|inc)=)"
&nbsp;
#remote file inclusion generic attack signature
#SecFilterSelective THE_REQUEST  "\.(dat|gif|jpg|png|bmp|txt|vir|dot)\?\&amp;(cmd|command|inc|name)=" "msg:&#039;remote2&#039;"
&nbsp;
#remote file inclusion generic attack signature
#SecFilterSelective ARGS  "\.(dat|gif|jpg|png|bmp|txt|vir|dot)" "chain,msg:&#039;file inclusion1&#039;"
#SecFilter "\?\&amp;(cmd|inc|name)="
&nbsp;
#remote file inclusion generic attack signature
#SecFilterSelective ARGS  "\.(dat|gif|jpg|png|bmp|txt|vir|dot)\?\&amp;(cmd|inc|name)=" "msg:&#039;file inclusion2&#039;"
&nbsp;
#remote file inclusion generic attack signature
#SecFilterSelective REQUEST_URI  "\.php\?.*=(http|https|ftp)\:/.*\?&amp;cmd=" "msg:&#039;file inclusion3&#039;"
&nbsp;
#Bogus file extensions generic signature
#SecFilterSelective THE_REQUEST  "[A-Za-z0-9]\.(gif|jpg|png|bmp)\.txt" "msg:&#039;file extension&#039;"
&nbsp;
#PHP remote path attach generic signature
#SecFilterSelective REQUEST_URI  "\.ph(p(3|4)?).*path=(http|https|ftp)\:/" "msg:&#039;remote path1&#039;"
#SecFilterSelective REQUEST_URI  "\.php.*path=(http|https|ftp)\:/" "msg:&#039;remote path2&#039;"
&nbsp;
#generic php attack sigs
#SecFilterSelective REQUEST_URI "(&amp;(cmd|command)=(id|uname)\x20|cmd\?(cmd|command)=|(spy|cmd|cmd_out|sh)\.(gif|jpg|png|bmp|txt)\?&amp;(cmd|command)=|\.php\?&amp;(cmd|command)=)" "msg:&#039;php attack1&#039;"
&nbsp;
# WEB-MISC apache directory disclosure attempt
#SecFilterSelective THE_REQUEST "////" "msg:&#039;apache directory disclosure&#039;"
&nbsp;
#PHP defenses
##SecFilterSelective ARG_PHPSESSID "!^$" "msg:&#039;something in phpsessid&#039;"
##SecFilterSelective COOKIE_PHPSESSID "!^$" "msg:&#039;something in cookie phpsessid&#039;"
&nbsp;
#PHP defenses
##SecFilterSelective COOKIE_ASKAPACHEID "!^[0-9a-z]*$" "msg:&#039;bad value for cookie&#039;"
&nbsp;
#cross site scripting attempt TYPE + JAVASCRIPT
##SecFilterSelective THE_REQUEST "TYPE\s*=\s*[\&#039;\"]text\/javascript" "msg:&#039;cross-site1&#039;"
&nbsp;
#cross site scripting attempt STYLE + JAVASCRIPT
##SecFilterSelective THE_REQUEST "TYPE\s*=\s*[\&#039;\"]application\/x-javascript" "msg:&#039;cross-site1&#039;"
&nbsp;
#cross site scripting attempt STYLE + JSCRIPT
##SecFilterSelective THE_REQUEST "TYPE\s*=\s*[\&#039;\"]text\/jscript" "msg:&#039;cross-site1&#039;"
&nbsp;
# cross site scripting attempt STYLE + VBSCRIPT
##SecFilterSelective THE_REQUEST "TYPE\s*=\s*[\&#039;\"]text\/vbscript" "msg:&#039;cross-site1&#039;"
&nbsp;
#cross site scripting attempt STYLE + VBSCRIPT
##SecFilterSelective THE_REQUEST "TYPE\s*=\s*[\&#039;\"]application\/x-vbscript" "msg:&#039;cross-site1&#039;"
&nbsp;
#cross site scripting attempt STYLE + ECMACRIPT
##SecFilterSelective THE_REQUEST "TYPE\s*=\s*[\&#039;\"]text\/ecmascript" "msg:&#039;cross-site1&#039;"
&nbsp;
# cross site scripting attempt STYLE + EXPRESSION
##SecFilterSelective THE_REQUEST "STYLE[\s]*=[\s]*[^&gt;]expression[\s]*\(" "msg:&#039;cross-site1&#039;"
&nbsp;
#cross site scripting attempt STYLE + EXPRESSION
##SecFilterSelective THE_REQUEST "[\s]*expression[\s]*\([^}]}[\s]*&lt;\/STYLE&gt;" "msg:&#039;cross-site1&#039;"
&nbsp;
# cross site scripting attempt using XML
##SecFilterSelective THE_REQUEST "&lt;!\[CDATA\[&lt;\]\]&gt;SCRIPT" "msg:&#039;cross-site1&#039;"
&nbsp;
#cross site scripting attempt executing hidden Javascript
##SecFilterSelective THE_REQUEST "eval[\s]*\([\s]*[^\.]\.innerHTML[\s]*\)" "msg:&#039;cross-site1&#039;"
&nbsp;
#cross site scripting attempt executing hidden Javascript
##SecFilterSelective THE_REQUEST "window\.execScript[\s]*\(" "msg:&#039;cross-site1&#039;"
&nbsp;
#cross site scripting attempt to execute Javascript code
###SecFilterSelective THE_REQUEST "/(((URL|SRC|HREF|LOWSRC)[\s]*=)|(url[\s]*[\(]))[\s]*[\&#039;\"]*javascript[\:]" "msg:&#039;cross-site1&#039;"
&nbsp;
#cross site scripting HTML Image tag set to javascript attempt
#SecFilterSelective THE_REQUEST "img src=javascript" "msg:&#039;cross-site1&#039;"
&nbsp;
#Fake image file shell attacvk
#SecFilterSelective HTTP_Content-Type "image/.*" "msg:&#039;image shell 1&#039;"
#SecFilterSelective POST_PAYLOAD "chr\(" "msg:&#039;image shell2&#039;"
&nbsp;
#bogus graphics file
#SecFilterSelective HTTP_Content-Disposition "\.php"  "chain,msg:&#039;bogus graphics&#039;"
#SecFilterSelective HTTP_Content-Type "(image/gif|image/jpg|image/png|image/bmp)"
&nbsp;
# Allow only letters, digits, underscore, and square brackets (for arrays)
# in variable names#
#SecFilterSelective ARGS_NAMES "!^[][a-zA-Z0-9_]+$"
&nbsp;
#---------------------------------------------
# reject keywords that appear in POST or GET
#=============================================
SecFilterSignatureAction "nolog,auditlog,deny,severity:6,status:403"
&nbsp;
SecFilterSelective REQUEST_URI  "^/.*/wp-comments-post\.php" "id:50200,msg:&#039;WORDPRESS SPAM bad wp-comments-post location&#039;"
&nbsp;
&lt;files wp-comments-post.php&gt;
# fail for empty comment fields
SecFilterSelective "ARG_comment_post_ID|ARG_submit" "^$" "id:50300,msg:&#039;WORDPRESS SPAM MISSING comment_post_ID&#039;"
SecFilterSelective "ARG_comment_post_ID" "!^[0-9]{1,6}$" "id:50301,msg:&#039;WORDPRESS SPAM BAD comment_post_ID&#039;"
SecFilterSelective "HTTP_Cookie" "^$" "id:50302,msg:&#039;WORDPRESS SPAM No cookie&#039;"
&nbsp;
##SecFilterSelective "comment_post_DI" "^$" "id:50310,msg:&#039;WORDPRESS SPAM MISSING comment_post_DI&#039;"
##SecFilterSelective "comment_post_DI" "!^[0-9]{1,2}$" "id:50311,msg:&#039;WORDPRESS SPAM MISSING comment_post_DI&#039;"
&lt;/files&gt;
&lt;pre&gt;
&nbsp;
&lt;h2&gt;MODSEC Continued.. Custom Anti-Spam (WordPress) I made&lt;/h2&gt;
&lt;pre&gt;
SecFilterSignatureAction "nolog,noauditlog,deny,severity:6,redirect:http://www.askapache.com/feed/"
SecFilterSelective ARGS|THE_REQUEST "00bp\.com|360\.yahoo|987mb\.com|Ambien|American airline" "id:50010,msg:&#039;SPAM 10&#039;
SecFilterSelective ARGS|THE_REQUEST "Ativan|Caresoprodol|Darvocet|Ephedra|Ephedrine" "id:50011,msg:&#039;SPAM 11&#039;
SecFilterSelective ARGS|THE_REQUEST "Gambling|Lexapro|Tramadol|Venlafaxine" "id:50012,msg:&#039;SPAM 12&#039;
SecFilterSelective ARGS|THE_REQUEST "\[URL=|abgood|acura|acyclovir|adderall" "id:50013,msg:&#039;SPAM 13&#039;
SecFilterSelective ARGS|THE_REQUEST "adipex|alcohol|alprazolam|amateur|amrit" "id:50014,msg:&#039;SPAM 14&#039;
SecFilterSelective ARGS|THE_REQUEST "anal sex|analfinder|angelina jolie|asshole|axspace\.com" "id:50015,msg:&#039;SPAM 15&#039;
SecFilterSelective ARGS|THE_REQUEST "baccarat|bankrupt|bikini|biotic|black jack|blowjob" "id:50016,msg:&#039;SPAM 16&#039;
SecFilterSelective ARGS|THE_REQUEST "blackjack|blog\.360|brutality|buddhism|butalbital" "id:50017,msg:&#039;SPAM 17&#039;
SecFilterSelective ARGS|THE_REQUEST "cadillac|canalis|card credit|card stud|carisoprodol" "id:50018,msg:&#039;SPAM 18&#039;
SecFilterSelective ARGS|THE_REQUEST "carmen|cash advance|cash credit|casino|catch\.com" "id:50019,msg:&#039;SPAM 19&#039;
SecFilterSelective ARGS|THE_REQUEST "celebrex|celexa|cellulite|cheap|cheerleader" "id:50020,msg:&#039;SPAM 20&#039;
SecFilterSelective ARGS|THE_REQUEST "chevrolet|child abuse|cialis|cigarette|cipro" "id:50021,msg:&#039;SPAM 21&#039;
SecFilterSelective ARGS|THE_REQUEST "citroen|claritin|cleavage|clomid|codeine" "id:50022,msg:&#039;SPAM 22&#039;
SecFilterSelective ARGS|THE_REQUEST "consulting23|craps online|credit card|credit debt|crestor" "id:50023,msg:&#039;SPAM 23&#039;
SecFilterSelective ARGS|THE_REQUEST "dealership|debt free|desnudas|diazepam|dick" "id:50024,msg:&#039;SPAM 24&#039;
SecFilterSelective ARGS|THE_REQUEST "dildo|drugstore|earrings|endometrioma|endowment" "id:50025,msg:&#039;SPAM 25&#039;
SecFilterSelective ARGS|THE_REQUEST "erotic|estrogen|fioricet|francaise|freehost\.com" "id:50026,msg:&#039;SPAM 26&#039;
SecFilterSelective ARGS|THE_REQUEST "freehostia|freemb\.com|fuck|geocities\.com|hacking myspace" "id:50027,msg:&#039;SPAM 27&#039;
SecFilterSelective ARGS|THE_REQUEST "holdem|honda|hotels|hydrocodone|hypnotic" "id:50028,msg:&#039;SPAM 28&#039;
SecFilterSelective ARGS|THE_REQUEST "hyundai|implants|incest|instant approval|insurance" "id:50029,msg:&#039;SPAM 29&#039;
SecFilterSelective ARGS|THE_REQUEST "interracial|jaguar|jenny movie|johanson|kasino" "id:50030,msg:&#039;SPAM 30&#039;
SecFilterSelective ARGS|THE_REQUEST "lesbian|levitra|lipitor|loan|lolita" "id:50031,msg:&#039;SPAM 31&#039;
SecFilterSelective ARGS|THE_REQUEST "lorazepam|lorcet|lyrics|madamic|majorette" "id:50032,msg:&#039;SPAM 32&#039;
SecFilterSelective ARGS|THE_REQUEST "malaria|mastercar|masturbate|masturbation|maturewomen" "id:50033,msg:&#039;SPAM 33&#039;
SecFilterSelective ARGS|THE_REQUEST "mazda|medication|medicine|megsfree5\.com|mercedes" "id:50034,msg:&#039;SPAM 34&#039;
SecFilterSelective ARGS|THE_REQUEST "meridia|metformin|mitsubishi|mortgage|myspace profile" "id:50035,msg:&#039;SPAM 35&#039;
SecFilterSelective ARGS|THE_REQUEST "naked|neocool|nexium|nimire\.com|nissan" "id:50036,msg:&#039;SPAM 36&#039;
SecFilterSelective ARGS|THE_REQUEST "nokia|nude|nudism|nymph|open toe" "id:50037,msg:&#039;SPAM 37&#039;
SecFilterSelective ARGS|THE_REQUEST "oprodol|orgasm|oxycodone|oxycontin|packages" "id:50038,msg:&#039;SPAM 38&#039;
SecFilterSelective ARGS|THE_REQUEST "painrelief|pantyhose|paxil|payday|penis" "id:50039,msg:&#039;SPAM 39&#039;
SecFilterSelective ARGS|THE_REQUEST "percocet|pharmacy|phentermine|phetermine|phpbb_root" "id:50040,msg:&#039;SPAM 40&#039;
SecFilterSelective ARGS|THE_REQUEST "pictaboo|pictorial|pills|pissing|play craps" "id:50041,msg:&#039;SPAM 41&#039;
SecFilterSelective ARGS|THE_REQUEST "playgirl|pocker web|poker|pontiac|poquer" "id:50042,msg:&#039;SPAM 42&#039;
SecFilterSelective ARGS|THE_REQUEST "porn|pounder|prescription|preteen|prevacid" "id:50043,msg:&#039;SPAM 43&#039;
SecFilterSelective ARGS|THE_REQUEST "price1|prilosec|propecia|proza|prozac" "id:50044,msg:&#039;SPAM 44&#039;
SecFilterSelective ARGS|THE_REQUEST "puddled|pussy|refinance|rentals|replica" "id:50045,msg:&#039;SPAM 45&#039;
SecFilterSelective ARGS|THE_REQUEST "ringtones|roulette|screensaver|seduced|sexual" "id:50046,msg:&#039;SPAM 46&#039;
SecFilterSelective ARGS|THE_REQUEST "sexy|shemale|shiloh|singulair|site-host" "id:50047,msg:&#039;SPAM 47&#039;
SecFilterSelective ARGS|THE_REQUEST "slot machine|slot maschine|slots machine|solpip\.com|soma" "id:50048,msg:&#039;SPAM 48&#039;
SecFilterSelective ARGS|THE_REQUEST "sperm|starlets|supplier|suzuki|tadalafil" "id:50049,msg:&#039;SPAM 49&#039;
SecFilterSelective ARGS|THE_REQUEST "toyota|tylenol|ultram|valium|viagra" "id:50050,msg:&#039;SPAM 50&#039;
SecFilterSelective ARGS|THE_REQUEST "vigora|vioxx|wallpaper|warez|webcam" "id:50051,msg:&#039;SPAM 51&#039;
SecFilterSelective ARGS|THE_REQUEST "webpages\.com|wellbutrin|whitesluts|wholesale|whore" "id:50052,msg:&#039;SPAM 52&#039;
SecFilterSelective ARGS|THE_REQUEST "windshield|xanax|xenical|y lohan|yourgirls" "id:50053,msg:&#039;SPAM 53&#039;
SecFilterSelective ARGS|THE_REQUEST "youtube\.com|zantac|sex offenders|hotgay|Zoloft|celtic women" "id:50054,msg:&#039;SPAM 54&#039;
SecFilterSelective ARGS|THE_REQUEST "dollhouse|freehot|kardashian|oralsex" "id:50055,msg:&#039;SPAM 55&#039;
SecFilterSelective ARGS|THE_REQUEST "freeimghost" "id:50056,msg:&#039;SPAM 56&#039;</pre>





<h2>Unreleased AskApache Lightning code - caching plugin for WordPress</h2>
<pre>RewriteEngine On
RewriteBase /
&nbsp;
RewriteCond %{REQUEST_URI} ^/(stats/|missing\.html|failed_auth\.html|test/).* [NC,OR]
RewriteCond %{ENV:REDIRECT_STATUS} =200
RewriteRule .* - [L]
&nbsp;
RewriteCond %{HTTP_HOST} !=www.askapache.com
RewriteCond %{HTTP_HOST} !=z.askapache.com
RewriteRule .? http://www.askapache.com%{REQUEST_URI}%{QUERY_STRING} [R=301,L]
&nbsp;
#RewriteCond %{HTTPS} =on
#RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ /(wp-login.php|wp-admin)(.*)\ HTTP/ [NC]
#RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)\ HTTP/ [NC]
#RewriteRule .* http://www.askapache.com/$1 [R=301,L]
&nbsp;
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.+)%20(.+)\ HTTP/ [NC]
RewriteRule .* http://www.askapache.com/%1-%2 [R=301,L]
&nbsp;
RewriteCond %{THE_REQUEST} ^GET\ /valid-html/.*\ HTTP/ [NC]
RewriteCond %{HTTP_REFERER} ^https?://www.askapache.com(.+).*$ [NC]
RewriteRule .* http://validator.w3.org/check?uri=http://www.askapache.com%1;ss=1;outline=1;debug [R=307,L,NE]
&nbsp;
RewriteCond %{THE_REQUEST} ^GET\ /valid-css/.*\ HTTP/ [NC]
RewriteRule .* http://jigsaw.w3.org/css-validator/validator?uri=z.askapache.com/z/c/apache-10.css [R=301,L]
&nbsp;
RewriteCond %{THE_REQUEST} ^GET\ /search/.*\ HTTP/ [NC]
RewriteCond %{QUERY_STRING} ^s=(.+)$ [NC]
RewriteRule .* http://www.askapache.com/search/%1? [R=302,L]
&nbsp;
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/X%{REQUEST_URI}index.html -f
RewriteRule ^(.*)$ /X%{REQUEST_URI}index.html [L]
&nbsp;
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/X%{REQUEST_URI} -f
RewriteRule ^(.*)$ /X%{REQUEST_URI} [L]</pre>



<h2>Passing Parameters to CGI through HTTP Headers</h2>
<p>This deserves a note.. this trick lets you bypass so many hosting environment restrictions it's not even funny... like you can run bash as your webserver instead of apache!  (kinda...)</p>
<pre>RewriteCond %{REQUEST_URI} ^/cgi-bin/(hash|java)\.cgi$ [NC]
RewriteCond %{HTTP:P3P} ^(([^:]+):(.+))$ [NC]
RewriteRule .* - [E=HTTP_JS:%{HTTP:P3P},E=HTTP_US:%2,E=HTTP_PA:%3]</pre>



<h2>Redirect to FeedBurner</h2>
<p>Yes.. I was the first to do this (parse the real rewrites internally in wordpress for no bypassing possibilities)... </p>
<pre>#RewriteCond %{REQUEST_URI} ^/feed/.*?$ [NC,OR]
#RewriteCond %{HTTP_REFERER} ^https?://www.askapache.com/wp-admin(.+).*$ [NC]
RewriteCond %{HTTP_USER_AGENT} FeedBurner [NC]
RewriteRule .* - [S=1]
&nbsp;
RewriteCond %{REQUEST_URI} ^/(feed|rdf|rss|rss2|atom).* [NC,OR]
RewriteCond %{REQUEST_URI} ^/wp-(feed|rdf|rss|rss2|atom).* [NC,OR]
RewriteCond %{REQUEST_FILENAME} ^.*/(wp-atom|wp-feed|wp-rdf|wp-rss|wp-rss2)\.php$ [NC,OR]
RewriteCond %{REQUEST_FILENAME} ^.*/wp-includes/feed[^\.]*\.php$ [NC,OR]
RewriteCond %{QUERY_STRING} .*(feed|rdf|rss|rss2|atom).* [NC]
RewriteRule .* http://feeds.askapache.com/apache/htaccess? [R=302,L]</pre>
































<h2>More Unreleased Caching Tests</h2>
<pre># +ASKAPACHE CRAZYCACHE 2.3
#######################################################
#               __                          __
#   ____ ______/ /______ _____  ____ ______/ /_  ___
#  / __ `/ ___/ //_/ __ `/ __ \/ __ `/ ___/ __ \/ _ \
# / /_/ (__  ) ,&lt; / /_/ / /_/ / /_/ / /__/ / / /  __/
# \__,_/____/_/|_|\__,_/ .___/\__,_/\___/_/ /_/\___/
#                     /_/
# - - - - - - - - - - - - - - - - - - - - - - - - - - -
# +ACACHE RULES
# +RULE
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ //?(.+)\.rdf\ HTTP/ [NC]
RewriteCond %{DOCUMENT_ROOT}/wp-cache/%2.html/index.rdf -f
RewriteRule ^(.+)\.rdf$ /wp-cache/%2.html/index.rdf [L,S=3]
&nbsp;
RewriteCond %{QUERY_STRING} !^.*cacheit.* [NC]
#RewriteCond %{HTTP_USER_AGENT} W3C_Validator [OR,NC]
#RewriteCond %{REMOTE_ADDR} = [OR]
&nbsp;
RewriteCond %{REQUEST_METHOD} =POST [OR]
RewriteCond %{THE_REQUEST} ^$ [OR]
RewriteCond %{QUERY_STRING} nocache [OR]
RewriteCond %{REMOTE_ADDR} = [OR]
RewriteCond %{HTTP_COOKIE} ^.*wordpress_logged_in_.*$ [NC]
RewriteRule .+ - [S=2]
&nbsp;
RewriteCond %{DOCUMENT_ROOT}/wp-cache%{REQUEST_URI} !-d
RewriteRule .+ - [S=1]
&nbsp;
RewriteCond %{DOCUMENT_ROOT}/wp-cache%{REQUEST_URI}/index.html -f
RewriteRule .+ /wp-cache%{REQUEST_URI}/index.html [L]
# -RULE
# -ACACHE RULES
# - - - - - - - - - - - - - - - - - - - - - - - - - - -
#               __                          __
#   ____ ______/ /______ _____  ____ ______/ /_  ___
#  / __ `/ ___/ //_/ __ `/ __ \/ __ `/ ___/ __ \/ _ \
# / /_/ (__  ) ,&lt; / /_/ / /_/ / /_/ / /__/ / / /  __/
# \__,_/____/_/|_|\__,_/ .___/\__,_/\___/_/ /_/\___/
#                     /_/
#######################################################
# -ASKAPACHE CRAZYCACHE 2.3
&nbsp;
# +ASKAPACHE CRAZYCACHE 2.3
#######################################################
#               __                          __
#   ____ ______/ /______ _____  ____ ______/ /_  ___
#  / __ `/ ___/ //_/ __ `/ __ \/ __ `/ ___/ __ \/ _ \
# / /_/ (__  ) ,&lt; / /_/ / /_/ / /_/ / /__/ / / /  __/
# \__,_/____/_/|_|\__,_/ .___/\__,_/\___/_/ /_/\___/
#                     /_/
# - - - - - - - - - - - - - - - - - - - - - - - - - - -
# +ACACHE RULES
# +RULE
FileETag None
AddOutputFilterByType DEFLATE text/html
&nbsp;
AddType &#039;text/html; charset=UTF-8&#039; .html
&nbsp;
Header set P3P "policyref=\"http://www.askapache.com/w3c/p3p.xml\""
Header set X-Pingback "http://www.askapache.com/xmlrpc.php"
Header set Content-Language "en-US"
Header set Vary "Accept-Encoding,Accept"
&nbsp;
&lt;ifModule mod_expires.c&gt;
ExpiresActive On
ExpiresDefault M7200
&lt;/ifModule&gt;
# -RULE
# -ACACHE RULES
# - - - - - - - - - - - - - - - - - - - - - - - - - - -
#               __                          __
#   ____ ______/ /______ _____  ____ ______/ /_  ___
#  / __ `/ ___/ //_/ __ `/ __ \/ __ `/ ___/ __ \/ _ \
# / /_/ (__  ) ,&lt; / /_/ / /_/ / /_/ / /__/ / / /  __/
# \__,_/____/_/|_|\__,_/ .___/\__,_/\___/_/ /_/\___/
#                     /_/
#######################################################
# -ASKAPACHE CRAZYCACHE 2.3
&nbsp;
Options +IndexesOptions +FollowSymLinks
AddHandler application/x-httpd-php .php
&nbsp;
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} !^tyy+$ [NC]
RewriteCond %{REMOTE_USER} ^(.+)$
RewriteRule ^(.*)$ $1/-%1 [R=302,L]
Options +FollowSymLinks
DirectoryIndex index.php
ErrorDocument 404 /cgi-bin/pro/index.php
&nbsp;
AuthName "Protection"
AuthUserFile /home/askapache/sites/askapache.com/.htpasswda1
AuthGroupFile /dev/null
AuthType Basic
Require valid-user
Satisfy Any
&nbsp;
&lt;ifModule mod_security.c&gt;
SecFilterEngine Off
&lt;/ifModule&gt;
Options +ExecCGI -Indexes -Includes +FollowSymLinks
Order Deny,Allow
Deny from All
Allow from 208.113.134.190 64.111.114.111  env=REDIRECT_STATUS
&nbsp;
#SetEnvIf Remote_Addr ^$ MODSEC_ENABLE=Off
#SetEnvIf Server_Addr ^$ MODSEC_ENABLE=Off
#SetEnvIf Remote_Addr ^({SERVER_ADDR}e)$ GOOD=$1
#SetEnvIf Server_Addr GOOD R</pre>


<h2>Default HTACCESS</h2>
<pre>#
# Directives controlling the display of server-generated directory listings.
#
# Required modules: mod_autoindex, mod_alias
#
# To see the listing of a directory, the Options directive for the
# directory must include "Indexes", and the directory must not contain
# a file matching those listed in the DirectoryIndex directive.
#
Options +Indexes +MultiViews -ExecCGI +FollowSymLinks
DirectoryIndex index.html
&nbsp;
#
#
# IndexOptions: Controls the appearance of server-generated directory
# listings.
#
IndexOptions FancyIndexing IconHeight=22 IconWidth=20 IgnoreClient NameWidth=* DescriptionWidth=* ScanHTMLTitles SuppressLastModified XHTML FoldersFirst SuppressHTMLPreamble
&nbsp;
#
# AddIcon* directives tell the server which icon to show for different
# files or filename extensions.  These are only displayed for
# FancyIndexed directories.
#
&nbsp;
AddIconByEncoding (CMP,http://z.askapache.com/i/s/compressed.gif) x-compress x-gzip
&nbsp;
AddIconByType (IMG,http://z.askapache.com/i/s/image.gif) image/*
AddIconByType (SND,http://z.askapache.com/i/s/sound2.gif) audio/*
AddIconByType (TXT,http://z.askapache.com/i/s/text.gif) text/*
AddIconByType (VID,http://z.askapache.com/i/s/movie.gif) video/*
&nbsp;
AddIcon http://z.askapache.com/i/s/hand.right.gif README
AddIcon http://z.askapache.com/i/s/folder.gif ^^DIRECTORY^^
AddIcon http://z.askapache.com/i/s/dir.png ^^DIRECTORY^^
AddIcon http://z.askapache.com/i/s/blank.gif ^^BLANKICON^^
AddDescription "100 Continue" 100* 100/index.html
AddDescription "101 Switching Protocols" 101* 101/index.html
AddDescription "102 Processing" 102* 102/index.html
AddDescription "200 OK" 200* 200/index.html
AddDescription "201 Created" 201* 201/index.html
AddDescription "202 Accepted" 202* 202/index.html
AddDescription "203 Non-Authoritative Information" 203* 203/index.html
AddDescription "204 No Content" 204* 204/index.html
AddDescription "205 Reset Content" 205* 205/index.html
AddDescription "206 Partial Content" 206* 206/index.html
AddDescription "207 Multi-Status" 207* 207/index.html
AddDescription "300 Multiple Choices" 300* 300/index.html
AddDescription "301 Moved Permanently" 301* 301/index.html
AddDescription "302 Found" 302* 302/index.html
AddDescription "303 See Other" 303* 303/index.html
AddDescription "304 Not Modified" 304* 304/index.html
AddDescription "305 Use Proxy" 305* 305/index.html
AddDescription "306 unused" 306* 306/index.html
AddDescription "307 Temporary Redirect" 307* 307/index.html
AddDescription "400 Bad Request" 400* 400/index.html
AddDescription "401 Authorization Required" 401* 401/index.html
AddDescription "402 Payment Required" 402* 402/index.html
AddDescription "403 Forbidden" 403* 403/index.html
AddDescription "404 Not Found" 404* 404/index.html
AddDescription "405 Method Not Allowed" 405* 405/index.html
AddDescription "406 Not Acceptable" 406* 406/index.html
AddDescription "407 Proxy Authentication Required" 407* 407/index.html
AddDescription "408 Request Time-out" 408* 408/index.html
AddDescription "409 Conflict" 409* 409/index.html
AddDescription "410 Gone" 410* 410/index.html
AddDescription "411 Length Required" 411* 411/index.html
AddDescription "412 Precondition Failed" 412* 412/index.html
AddDescription "413 Request Entity Too Large" 413* 413/index.html
AddDescription "414 Request-URI Too Large" 414* 414/index.html
AddDescription "415 Unsupported Media Type" 415* 415/index.html
AddDescription "416 Requested Range Not Satisfiable" 416* 416/index.html
AddDescription "417 Expectation Failed" 417* 417/index.html
AddDescription "418 unused" 418* 418/index.html
AddDescription "419 unused" 419* 419/index.html
AddDescription "420 unused" 420* 420/index.html
AddDescription "421 unused" 421* 421/index.html
AddDescription "422 Unprocessable Entity" 422* 422/index.html
AddDescription "423 Locked" 423* 423/index.html
AddDescription "424 Failed Dependency" 424* 424/index.html
AddDescription "425 No code" 425* 425/index.html
AddDescription "426 Upgrade Required" 426* 426/index.html
AddDescription "500 Internal Server Error" 500* 500/index.html
AddDescription "501 Method Not Implemented" 501* 501/index.html
AddDescription "502 Bad Gateway" 502* 502/index.html
AddDescription "503 Service Temporarily Unavailable" 503* 503/index.html
AddDescription "504 Gateway Time-out" 504* 504/index.html
AddDescription "505 HTTP Version Not Supported" 505* 505/index.html
AddDescription "506 Variant Also Negotiates" 506* 506/index.html
AddDescription "507 Insufficient Storage" 507* 507/index.html
AddDescription "508 unused" 508* 508/index.html
AddDescription "509 unused" 509* 509/index.html
AddDescription "510 Not Extended" 510* 510/index.html
AddDescription ".htaccess ErrorDocuments" *
&nbsp;
#
# HeaderName is the name of a file which should be prepended to
# directory indexes.
ReadmeName /X/error/README.html
HeaderName /X/error/HEADER.html
&nbsp;
# DefaultIcon is which icon to show for where none is explicitly set.
DefaultIcon http://z.askapache.com/i/s/generic.gif</pre>


<h2>Ok I'm done commenting..</h2>
<pre>#
# IndexIgnore is a set of filenames which directory indexing should ignore
# and not include in the listing.  Shell-style wildcarding is permitted.
#
IndexIgnore .??*  *_notes *~
RewriteEngine On
RewriteCond %{HTTPS} !=on [NC]
RewriteRule .* https://www.askapache.com%{REQUEST_URI}
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},E=REMOTE_USER:%{HTTP:Authorization}]
&nbsp;
#RewriteCond %{QUERY_STRING} openid.mode=authorize
#RewriteCond %{REQUEST_URI} ^/openid.*$ [NC]
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},E=REMOTE_USER:%{HTTP:Authorization}]
Options +FollowSymLinks
DirectoryIndex index.html
&nbsp;
#SetEnvIfNoCase ^Cookie$ "(.*)" HTTP_MY_COOKIE=$1
#SetEnvIfNoCase Remote_Addr "(.*)" HTTP_MY_REMOTE_ADDR=$1
ExpiresActive Off
FileETag None
Header unset Connection
Header set Connection "close"
Header unset Last-Modified
Header unset ETag
Header unset Accept-Ranges
Header unset Vary
Header unset Content-Type
Header unset X-Pingback
Header unset P3P
#Header add RouterBits "%D %t"
#Header add Location "http://www.askapache.com/feed/"
#Header add Found "http://askapache.com/feed/"
#Header add Content-Location "http://www.askapache.com/feed/"
#Header add Refresh "http://www.askapache.com/feed/"
#Header set Hi "%{HTTP_MY_REMOTE_ADDR}e"
### Section 1: Global Environment
#
# The directives in this section affect the overall operation of Apache,
# such as the number of concurrent requests it can handle or where it
# can find its configuration files.
#
#
# TZ: Your address, where problems with the server should be
# e-mailed.  This address appears on some server-generated pages, such
# as error documents.  e.g. admin@your-domain.com
#
SetEnv TZ America/Indianapolis
&nbsp;
#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed.  This address appears on some server-generated pages, such
# as error documents.  e.g. admin@your-domain.com
#
SetEnv SERVER_ADMIN webmaster@askapache.com
&nbsp;
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs/2.0/mod/core.html#options
# for more information.
#
Options  +FollowSymLinks -ExecCGI -Indexes -Includes -MultiViews
&nbsp;
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
DirectoryIndex index.html index.php /index.php
&nbsp;
#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
&lt;filesMatch "^\.ht"&gt;
    Order allow,deny
    Deny from all
  Satisfy All
&lt;/filesMatch&gt;
&nbsp;
#
# DefaultType: the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain" is
# a good value.  If most of your content is binary, such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
DefaultType text/html
&nbsp;
#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
# Set to one of:  On | Off | EMail
#
ServerSignature Off
&nbsp;
##############################################
#           HEADERS and CACHING              #
##############################################
Header unset Pragma
Header unset Last-Modified
FileETag None
&nbsp;
Redirect 400 /e/400
Redirect 401 /e/401
Redirect 402 /e/402
Redirect 403 /e/403
Redirect 404 /e/404
Redirect 405 /e/405
Redirect 406 /e/406
Redirect 407 /e/407
Redirect 408 /e/408
Redirect 409 /e/409
Redirect 410 /e/410
Redirect 411 /e/411
Redirect 412 /e/412
Redirect 413 /e/413
Redirect 414 /e/414
Redirect 415 /e/415
Redirect 416 /e/416
Redirect 417 /e/417
Redirect 418 /e/418
Redirect 419 /e/419
Redirect 420 /e/420
Redirect 421 /e/421
Redirect 422 /e/422
Redirect 423 /e/423
Redirect 424 /e/424
Redirect 425 /e/425
Redirect 426 /e/426
Redirect 500 /e/500
Redirect 501 /e/501
Redirect 502 /e/502
Redirect 503 /e/503
Redirect 504 /e/504
Redirect 505 /e/505
Redirect 506 /e/506
Redirect 507 /e/507
Redirect 508 /e/508
Redirect 509 /e/509
Redirect 510 /e/510
&nbsp;
#
# Redirect allows you to tell clients about documents which used to exist in
# your server&#039;s namespace, but do not anymore. This allows you to tell the
# clients where to look for the relocated document.
##############################################
#          PERMANENT REDIRECTS               #
##############################################
Redirect 301 /12-lessons-for-those-afraid-of-css.html http://www.askapache.com/css/12-lessons-for-those-afraid-of-css.html
Redirect 301 /2006/htaccess/htaccesselite-ultimate-htaccess-article.html http://www.askapache.com/htaccess/apache-htaccess.html
Redirect 301 /2007/phpbb/sending-post-form-data-with-php-curl.html http://www.askapache.com/htaccess/sending-post-form-data-with-php-curl.html
Redirect 301 /2007/webmaster/custom-phpini-with-fastcgi-on-dreamhost.html http://www.askapache.com/dreamhost/custom-phpini-with-fastcgi-on-dreamhost.html
Redirect 301 /2007/webmaster/custom-phpini-with-fastcgi-on-dreamhost.html http://www.askapache.com/dreamhost/custom-phpini-with-fastcgi-on-dreamhost.html
Redirect 301 /2007/webmaster/php-and-ajax-shell-console.html http://www.askapache.com/tools/php-and-ajax-shell-console.html
Redirect 301 /27-request-methods-for-use-with-apache-and-rewritecond-and-htaccess.html http://www.askapache.com/htaccess/27-request-methods-for-use-with-apache-and-rewritecond-and-htaccess.html
Redirect 301 /404-google-wordpress-plugin.html http://www.askapache.com/seo/404-google-wordpress-plugin.html
Redirect 301 /503-service-temporarily-unavailable.html http://www.askapache.com/htaccess/503-service-temporarily-unavailable.html
Redirect 301 /Overview-about.rdf http://www.askapache.com/askapache-home.rdf
Redirect 301 /abbr-acronym.html http://www.askapache.com/xhtml/abbr-acronym.html
Redirect 301 /adsense-robots.html http://www.askapache.com/google/adsense-robots.html
Redirect 301 /alexa-toolbar-firefox.html http://www.askapache.com/tools/alexa-toolbar-firefox.html
Redirect 301 /allowing-access-from-1-static-ip-and-deny-the-rest.html http://www.askapache.com/htaccess/apache-htaccess.html
Redirect 301 /anti-virus-spyware-rootkit.html http://www.askapache.com/security/anti-virus-spyware-rootkit.html
Redirect 301 /apache-ssl-in-htaccess-examples.html http://www.askapache.com/htaccess/apache-ssl-in-htaccess-examples.html
Redirect 301 /awk-tutorial.html http://www.askapache.com/awk/awk-tutorial.html
Redirect 301 /best-adsense-optimization.html http://www.askapache.com/wordpress/best-adsense-optimization.html
Redirect 301 /commonly-used-htaccess-code-examples.html http://www.askapache.com/htaccess/commonly-used-htaccess-code-examples.html
Redirect 301 /css-background-image-sprite.html http://www.askapache.com/css/css-background-image-sprite.html
Redirect 301 /css-browser-screenshots.html http://www.askapache.com/tools/css-browser-screenshots.html
Redirect 301 /css-class-example.html http://www.askapache.com/css/css-class-example.html
Redirect 301 /curl-multi-downloads.html http://www.askapache.com/php/curl-multi-downloads.html
Redirect 301 /custom-boot-menu-in-windows-xp.html http://www.askapache.com/windows/custom-boot-menu-in-windows-xp.html
Redirect 301 /donate http://www.dreamhost.com/donate.cgi?id=8261
Redirect 301 /donate/ http://www.dreamhost.com/donate.cgi?id=8261
Redirect 301 /htaccess.txt http://z.askapache.com/p/htaccess.txt
Redirect 301 /htaccess/404-errorpages.html http://www.askapache.com/seo/google-ajax-search-seo-tips.html
Redirect 301 /htaccess/feedsmith http://www.askapache.com/htaccess/feedsmith-htaccess.html
Redirect 301 /htaccess/http-status-codes.html http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html
Redirect 301 /htaccess/instruct-search-engines-to-come-back-to-site-after-you-finish-working-on-it.html http://www.askapache.com/htaccess/503-service-temporarily-unavailable.html
Redirect 301 /htaccess/speed-up-the-apache-web-server-with-configuration-hacks.html http://www.askapache.com/htaccess/apache-web-server-speed-configuration-hacks.html
Redirect 301 /instruct-search-engines-to-come-back-to-site-after-you-finish-working-on-it.html http://www.askapache.com/htaccess/503-service-temporarily-unavailable.html
Redirect 301 /security/bypassing-vlan.html http://www.askapache.com/security/hacking-vlan-switched-networks.html
Redirect 301 /security/bypassing-vlanbypassing-vlan.html http://www.askapache.com/security/hacking-vlan-switched-networks.html
Redirect 301 /security/rigging-the-dreamhost-site-of-the-month-contest.html http://www.askapache.com/dreamhost/rigging-the-dreamhost-site-of-the-month-contest.html
Redirect 301 /seo/tailrankcom-robot.html http://www.askapache.com/seo/tailrank-robot.html
Redirect 301 /webmaster/caching-tutorial-for-webmasters.html http://www.askapache.com/htaccess/caching-tutorial-for-webmasters.html
Redirect 301 /webmaster/lft-traceroute-tool.html http://www.askapache.com/tools/lft-traceroute-tool.html
&nbsp;
##############################################
#          PERMANENT REDIRECTMATCH           #
##############################################
#RedirectMatch 301 ^/&amp;(.*)$ http://www.askapache.com/
RedirectMatch 301 ^/&amp;amp(.*)$ http://www.askapache.com/
RedirectMatch 301 ^/([^/]+)//$ http://www.askapache.com/$1/
RedirectMatch 301 ^/(.+)/htaccesselite-ultimate-htaccess-article.html(.*) http://www.askapache.com/htaccess/apache-htaccess.html
RedirectMatch 301 ^/(.+)\.html/([a-z][a-z])/$ http://www.askapache.com/$1.html
RedirectMatch 301 ^/([\(]+)(.*)$ http://www.askapache.com/
RedirectMatch 301 ^/([^9]*)9O1X.3y(.*)/(.*)$ http://www.askapache.com/$2
RedirectMatch 301 ^/.3y(.*)$ http://www.askapache.com/
RedirectMatch 301 ^/200([0-9])/([0-9])(.*)$ http://www.askapache.com/top-100/
RedirectMatch 301 ^/200([0-9])/([^01])(.*)$ http://www.askapache.com/$2$3
RedirectMatch 301 ^/about/glossary(.*)$ http://www.askapache.com/glossary$1
RedirectMatch 301 ^/apache-speed(.*)$ http://www.askapache.com/htaccess/apache-speed$1
RedirectMatch 301 ^/category/(.+)$ http://www.askapache.com/$1
RedirectMatch 301 ^/docs/(.*)$ http://askapache.info/$1
RedirectMatch 301 ^/htaccess/feedsmith-htaccess(.*) http://www.askapache.com/htaccess/redirecting-wordpress-feeds-to-feedburner.html
RedirectMatch 301 ^/robots-txt(.*)$ http://www.askapache.com/robots.txt
#RedirectMatch 301 ^/wp-content/uploads/(.*)$ http://z.askapache.com/uploads/$1
RedirectMatch 301 ^/z/(.+)$ http://z.askapache.com/$1
RedirectMatch 301 ^/(z|t|i|j|c|p)/(.*)$ http://z.askapache.com/$1/$2
RedirectMatch 301 ^/hosting/?$ http://www.askapache.com/hosting/
&nbsp;
##############################################
#          TEMPORARY REDIRECTMATCH           #
##############################################
RedirectMatch 307 ^/getflash/?$ http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash
RedirectMatch 307 ^/dream/?$ http://www.askapache.com/dreamhost/
RedirectMatch 307 ^/(cse|apachecse|apachecsetest|apachesearch)/?$ http://www.google.com/coop/cse?cx=002660089121042511758%3Akk7rwc2gx0i
&nbsp;
#
# Commonly used filename extensions to character sets. You probably
# want to avoid clashes with the language extensions, unless you
# are good at carefully testing your setup after each change.
# See http://www.iana.org/assignments/character-sets for the
# official list of charset names and their respective RFCs.
#
AddDefaultCharset UTF-8
&nbsp;
#
# AddType allows you to add to or override the MIME configuration
# file mime.types for specific file types.
#
#
AddType &#039;application/rdf+xml; charset=UTF-8&#039; .rdf
AddType &#039;application/xhtml+xml; charset=UTF-8&#039; .xhtml
AddType &#039;application/xhtml+xml; charset=UTF-8&#039; .xhtml.gz
AddType &#039;text/html; charset=UTF-8&#039; .html
AddType &#039;text/html; charset=UTF-8&#039; .html.gz
AddType application/octet-stream .rar .chm .bz2 .tgz .msi .pdf .exe
AddType application/vnd.ms-excel .csv
AddType application/x-httpd-php-source .phps
AddType application/x-pilot .prc .pdb
AddType application/x-shockwave-flash .swf
AddType application/xrds+xml .xrdf
AddType text/plain .ini .sh .bsh .bash .awk .nawk .gawk .csh .var .c .in .h .asc .md5 .sha .sha1
AddType video/x-flv .flv
&nbsp;
#
# AddEncoding allows you to have certain browsers uncompress
# information on the fly. Note: Not all browsers support this.
# Despite the name similarity, the following Add* directives have nothing
# to do with the FancyIndexing customization directives above.
#
AddEncoding x-compress .Z
AddEncoding x-gzip .gz .tgz
&nbsp;
#
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
AddHandler php-cgi .php
&nbsp;
#
# Action lets you define media types that will execute a script whenever
# a matching file is called. This eliminates the need for repeated URL
# pathnames for oft-used CGI file processors.
# Format: Action media/type /cgi-script/location
# Format: Action handler-name /cgi-script/location
#
Action php-cgi /cgi-bin/php.cgi
&nbsp;
#
# Customizable error responses come in three flavors:
# 1) plain text 2) local redirects 3) external redirects
#
#100 Continue
#101 Switching Protocols
#102 Processing
#200 OK
#201 Created
#202 Accepted
#203 Non-Authoritative Information
#204 No Content
#205 Reset Content
#206 Partial Content
#207 Multi-Status
#300 Multiple Choices
#301 Moved Permanently
#302 Found
#303 See Other
#304 Not Modified
#305 Use Proxy
#306 unused
#307 Temporary Redirect
#400 Bad Request
#401 Authorization Required
#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
#416 Requested Range Not Satisfiable
#417 Expectation Failed
#418 unused
#419 unused
#420 unused
#421 unused
#422 Unprocessable Entity
#423 Locked
#424 Failed Dependency
#425 No code
#426 Upgrade Required
#500 Internal Server Error
#501 Method Not Implemented
#502 Bad Gateway
#503 Service Temporarily Unavailable
#504 Gateway Time-out
#505 HTTP Version Not Supported
#506 Variant Also Negotiates
#507 Insufficient Storage
#508 unused
#509 unused
#510 Not Extended
&nbsp;
#ErrorDocument 100 /X/err/1/HTTP_CONTINUE.html
#ErrorDocument 101 /X/err/1/HTTP_SWITCHING_PROTOCOLS.html
#ErrorDocument 102 /X/err/1/HTTP_PROCESSING.html
&nbsp;
#ErrorDocument 200 /X/err/2/HTTP_OK.html
#ErrorDocument 201 /X/err/2/HTTP_CREATED.html
#ErrorDocument 202 /X/err/2/HTTP_ACCEPTED.html
#ErrorDocument 203 /X/err/2/HTTP_NON_AUTHORITATIVE.html
#ErrorDocument 204 /X/err/2/HTTP_NO_CONTENT.html
#ErrorDocument 205 /X/err/2/HTTP_RESET_CONTENT.html
#ErrorDocument 206 /X/err/2/HTTP_PARTIAL_CONTENT.html
#ErrorDocument 207 /X/err/2/HTTP_MULTI_STATUS.html
&nbsp;
#ErrorDocument 300 /X/err/HTTP_MULTIPLE_CHOICES.html
#ErrorDocument 301 /X/err/HTTP_MOVED_PERMANENTLY.html
#ErrorDocument 302 /X/err/HTTP_MOVED_TEMPORARILY.html
#ErrorDocument 303 /X/err/HTTP_SEE_OTHER.html
#ErrorDocument 304 /X/err/HTTP_NOT_MODIFIED.html
#ErrorDocument 305 /X/err/HTTP_USE_PROXY.html
#ErrorDocument 307 /X/err/HTTP_TEMPORARY_REDIRECT.html
#ErrorDocument 404 /X/err/HTTP_NOT_FOUND.html
&nbsp;
ErrorDocument 400 /X/err/4/HTTP_BAD_REQUEST.html
ErrorDocument 401 /X/err/4/HTTP_UNAUTHORIZED.html
ErrorDocument 402 /X/err/4/HTTP_PAYMENT_REQUIRED.html
ErrorDocument 403 /X/err/4/HTTP_FORBIDDEN.html
ErrorDocument 405 /X/err/4/HTTP_METHOD_NOT_ALLOWED.html
ErrorDocument 406 /X/err/4/HTTP_NOT_ACCEPTABLE.html
ErrorDocument 407 /X/err/4/HTTP_PROXY_AUTHENTICATION_REQUIRED.html
ErrorDocument 408 /X/err/4/HTTP_REQUEST_TIME_OUT.html
ErrorDocument 409 /X/err/4/HTTP_CONFLICT.html
ErrorDocument 410 /X/err/4/HTTP_GONE.html
ErrorDocument 411 /X/err/4/HTTP_LENGTH_REQUIRED.html
ErrorDocument 412 /X/err/4/HTTP_PRECONDITION_FAILED.html
ErrorDocument 413 /X/err/4/HTTP_REQUEST_ENTITY_TOO_LARGE.html
ErrorDocument 414 /X/err/4/HTTP_REQUEST_URI_TOO_LARGE.html
ErrorDocument 415 /X/err/4/TTP_UNSUPPORTED_MEDIA_TYPE.html
ErrorDocument 416 /X/err/4/HTTP_RANGE_NOT_SATISFIABLE.html
ErrorDocument 417 /X/err/4/HTTP_EXPECTATION_FAILED.html
ErrorDocument 422 /X/err/4/HTTP_UNPROCESSABLE_ENTITY.html
ErrorDocument 423 /X/err/4/HTTP_LOCKED.html
ErrorDocument 424 /X/err/4/HTTP_FAILED_DEPENDENCY.html
ErrorDocument 426 /X/err/4/HTTP_UPGRADE_REQUIRED.html
&nbsp;
ErrorDocument 500 /X/err/5/HTTP_INTERNAL_SERVER_ERROR.html
ErrorDocument 501 /X/err/5/HTTP_NOT_IMPLEMENTED.html
ErrorDocument 502 /X/err/5/HTTP_BAD_GATEWAY.html
ErrorDocument 503 /X/err/5/HTTP_SERVICE_UNAVAILABLE.html
ErrorDocument 504 /X/err/5/HTTP_GATEWAY_TIME_OUT.html
ErrorDocument 505 /X/err/5/HTTP_VERSION_NOT_SUPPORTED.html
ErrorDocument 506 /X/err/5/HTTP_VARIANT_ALSO_VARIES.html
ErrorDocument 507 /X/err/5/HTTP_INSUFFICIENT_STORAGE.html
ErrorDocument 510 /X/err/5/HTTP_NOT_EXTENDED.html
ErrorDocument 404 /index.php?error=404
&nbsp;
# 1 YEAR
&lt;filesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$"&gt;
Header unset P3P
Header set Cache-Control "public"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
&lt;/filesMatch&gt;
&nbsp;
# 2 HOURS
&lt;filesMatch "\.(html|htm|xml|txt|xsl)$"&gt;
&lt;ifModule mod_expires.c&gt;
ExpiresActive On
ExpiresDefault A3600
&lt;/ifModule&gt;
&lt;/filesMatch&gt;
&nbsp;
RewriteEngine On
RewriteBase /
&nbsp;
RewriteCond %{ENV:REDIRECT_STATUS} =200
RewriteRule .* - [L]
&nbsp;
RewriteCond %{REQUEST_METHOD} !^(GET|HEAD) [OR]
#RewriteCond %{QUERY_STRING} !^$ [OR]
RewriteCond %{HTTP_COOKIE} ^.*(comment_author_|wordpress|wp-postpass_).*$ [NC]
RewriteRule ^(.*)$ - [S=6]
&nbsp;
RewriteCond %{HTTP_USER_AGENT} .*W3C_Validator.* [NC]
RewriteCond %{HTTP:Accept-Encoding} gzip [NC]
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/aa/$1/index.xhtml.gz -f
RewriteRule ^(.*)$ /wp-content/cache/aa/$1/index.xhtml.gz [L,S=5]
&nbsp;
RewriteCond %{HTTP:Accept} application/xhtml\+xml [NC]
RewriteCond %{HTTP:Accept-Encoding} gzip [NC]
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/aa/$1/index.xhtml.gz -f
RewriteRule ^(.*)$ /wp-content/cache/aa/$1/index.xhtml.gz [L,S=4]
&nbsp;
RewriteCond %{HTTP:Accept-Encoding} gzip [NC]
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/aa/$1/index.html.gz -f
RewriteRule ^(.*)$ /wp-content/cache/aa/$1/index.html.gz [L,S=3]
&nbsp;
RewriteCond %{HTTP_USER_AGENT} .*W3C_Validator.* [NC]
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/aa/$1/index.xhtml -f
RewriteRule ^(.*)$ /wp-content/cache/aa/$1/index.xhtml [L,S=2]
&nbsp;
RewriteCond %{HTTP:Accept} application/xhtml\+xml [NC]
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/aa/$1/index.xhtml -f
RewriteRule ^(.*)$ /wp-content/cache/aa/$1/index.xhtml [L,S=1]
&nbsp;
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/aa/$1/index.html -f
RewriteRule ^(.*)$ /wp-content/cache/aa/$1/index.html [L]
&nbsp;
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.+)\.rdf\ HTTP/ [NC]
RewriteCond %{DOCUMENT_ROOT}/wp-content/rdf/%1.html/index.rdf -f
RewriteRule ^(.*)$ /wp-content/rdf/%1.html/index.rdf [L,S=1]
&nbsp;
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(error|w3c|openid)(/?.*)\ HTTP/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /X/%1%2 [L]
&nbsp;
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(y_key_bf61afd498f7623a\.html|google3bb7b7e1032ad0d4\.html|yadis\.xrdf|askapache-home\.rdf|os-description\.xml|labels\.rdf|gnu-fdl\.txt|wlmmanifest\.xml|robots\.txt)\ HTTP/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /X/%1 [L]
&nbsp;
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /X(.*)\ HTTP/ [NC]
RewriteRule .* - [F]
&nbsp;
RewriteRule ^osq?(.*)$ /wp-content/plugins/wp-opensearch.php?$1 [QSA,L]
&nbsp;
#RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /wp-login(.+)\ HTTP/ [NC]
#RewriteRule .+ https://www.askapache.com/wp-login%1 [R,L]
&nbsp;
RewriteCond %{REQUEST_URI} ^/cgi-bin/(hash|java)\.cgi$ [NC]
RewriteCond %{HTTP:P3P} ^(([^:]+):(.+))$ [NC]
RewriteRule .* - [E=HTTP_JS:%{HTTP:P3P},E=HTTP_US:%2,E=HTTP_PA:%3]
&nbsp;
RewriteCond %{HTTP_ACCEPT} application/xrds\+xml
RewriteCond %{HTTP_ACCEPT} !application/xrds\+xml\s*;\s*q\s*=\s*0(\.0{1,3})?\s*(,|$)
RewriteRule ^$ http://www.askapache.com/yadis.xrdf [R,L]
&nbsp;
RewriteCond %{HTTP_USER_AGENT} !^(FeedBurner|FeedValidator|talkr.com).* [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(feed|rdf|rss|rss2|atom)/?.*\ HTTP/ [NC]
#RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(feed|rdf|rss|rss2|atom|wp-atom|wp-feed|wp-rdf|wp-rss|wp-rss2).*\ HTTP/ [NC]
RewriteRule .* http://feeds.askapache.com/apache/htaccess? [R=302,L]
&nbsp;
#RewriteCond %{REMOTE_ADDR} ^$
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.+)\.phps$ /cgi-bin/phps.php?file=$1.php [L,NC]</pre>

<p><a href="http://www.askapache.com/htaccess/real-world-htaccess-files.html"></a><a href="http://www.askapache.com/htaccess/real-world-htaccess-files.html">Actual Htaccess Files from My Server</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/real-world-htaccess-files.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>30x Faster Cache and Site Speed with TMPFS</title>
		<link>http://www.askapache.com/optimize/super-speed-secrets.html</link>
		<comments>http://www.askapache.com/optimize/super-speed-secrets.html#comments</comments>
		<pubDate>Thu, 18 Mar 2010 15:43:21 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Optimization]]></category>
		<category><![CDATA[tmpfs]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=3220</guid>
		<description><![CDATA[<p><a href="http://www.askapache.com/optimize/super-speed-secrets.html" id="id0"></a></p>
<p>NOT a typo..  30x is measurable, well-documented, and easily tested.  This is what <strong>open-source</strong> is about.   I haven’t had time to post much the past year, I'm always working!  So I wanted to make up for that by publishing an article on a topic that would blow your mind and be something that you could actually start using and really get some benefit out of it. This is one of those articles that the majority of web hosting companies would love to see in paperback, <strong>so they could burn it.</strong></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/optimize/super-speed-secrets.html"></a><a href="http://www.askapache.com/optimize/super-speed-secrets.html"><cite>AskApache.com</cite></a></p><p><a href="http://www.askapache.com/optimize/super-speed-secrets.html"><img src="http://uploads.askapache.com/2009/09/top.jpg" alt="Top showing swap and memory" title="Top showing swap and memory" width="434" height="52" class="size-full wp-image-3270" /></a></p>
<p>I haven't had time to post much the past year, so I wanted to make up for that by publishing an article on a topic that would blow your mind and be something that you could actually start using and really get some benefit out of it.  This is one of those articles that the majority of web hosting companies would love to see in paperback, <strong>so they could burn it</strong>.  Now ask yourself, if a webhost makes money based on how much memory, bandwidth, and data used by a customer, what would they not want their customers to do?  That's right, they do not want their customers to learn how to minimize and drastically reduce these moneymakers.  They get giddy when you complain about slow-site-speed, or that it takes a long time for your site to load, because they have exactly the right answer- upgrade your memory, bandwidth, and data by purchasing a more expensive plan.</p>


<p class="anote"><strong>WARNING</strong>!!  This article has some seriously advanced stuff in it, pretty far beyond my skill level as well (getting there).  I personally shutdown some of my own servers with various webhosts because of this.. Note I said personally, not intentionally.  Even after spending almost a year (this has been in my drafts folder a long time) using TMPFS on as many machines as I can, I still make mistakes (gotta pay attention!) and lose a tmpfs folder..   Oh and if you go experimenting with this stuff on your web host, you will almost definately, most certainly be on the road to getting your account terminated if you are with one of the cheap hosts.  They hate this stuff because it cuts right into the heart of their profit curves and can seriously disrupt a poorly configured machine.  DO NOT TRY THIS!!  (except and of course on your own development machines).   Of course the whole point of this article is how you can take advantage of this incredible filesystem to get crazy speed improvements..  Those are the follow up articles ;)</p>

<p>For those of you who thought modifying your server httpd.conf and htaccess files is very dangerous, you are right.  But this is not like that, this is dangerous in the sense that if you try to rush through with your super amazing "copy and paste skills" (script kids) you will easily lose entire folders.  That's because TMPFS is stored in RAM/Memory, and upon reboot RAM is cleared.  I personally loathe disclaimers, and if you look around you will see there aren't many even with all my sloppy poorly documented articles...  So be careful if you feel up to going further.</p>

<h2>Introducing tmpfs</h2>
<p>If I had to <strong>explain tmpfs</strong> in one breath, I'd say that tmpfs is like a ramdisk, but different. Like a ramdisk, tmpfs can use your RAM, but it can also use your swap devices for storage. And while a traditional ramdisk is a block device and requires a mkfs command of some kind before you can actually use it, tmpfs is a filesystem, not a block device; you just mount it, and it's there. All in all, this makes tmpfs the niftiest RAM-based filesystem I've had the opportunity to meet.</p>


<h2>Beware of WebHosts</h2>
<p>What is a modern day web hosting company?  What costs do they actually have?  A webhost's only unique ability is their connection to the Internet.  That is why you can see such tremendous link speed.  Other than that they consist of servers that are getting smaller and cheaper for them every month.  The servers they use are generally just like any computer, except much larger and built specifically for multi-tasking.</p>
<blockquote cite="http://content.dell.com/us/en/enterprise/virtualization-what-is-it.aspx">
<p>Virtualization allows you to run multiple applications and operating systems independently on a single server. Additionally, administrators can quickly move workloads from one virtual workspace to another — easily prioritizing business needs while maximizing server resources....</p>
<p>Virtualization removes the limitations of the traditional IT approach, enabling <strong>a single PowerEdge server</strong> to operate <strong>multiple applications simultaneously in "virtual machines"</strong></p>
</blockquote>



<h2>Hosting Company Tricks</h2>
<p>Web hosts like to vaguely describe their products as if you are buying your own powerful machine, but in reality you get placed on the same machine as hundreds or thousands of other customers, and the server basically creates an operating system for each customer using virtualization technology.  Everyone on the machine literally is sharing the same RAM and resources, many times even sharing IP address's, and the virtualization software lets them limit the amount of memory / cpu / disk / and bandwidth for each of these virtual machines.  That is why so often when a web host has an outage they make big public announcements and it appears that hundreds or thousands of their customers have been affected.. One of their server farm machines goes offline and it literally takes down all the customers virtualized machines with it.</p>

<h3>Why it gets Evil</h3>
<p>Don't get me wrong, I absolutely love this technology, both the hardware virtualization and the software side, but what I truly do not appreciate is how these companies take advantage of their customers every day and know it.  Here's what they do, they make justifications about why one plan costs more than another, and these justifications are always about the same thing:  CPU's, how fast the data can crunch..  RAM/Memory: How fast and how much your server can handle in terms of traffic... Disk Usage:  How much storage you have... And finally bandwidth: How fast can people get data off your sites, and how many people can connect.</p>
<p>Now lets think for a second.  The webhost has a BIG computer/server/machine that has MASSIVE amounts of RAM, DISK, PROCESSING power, and NETWORK bandwidth.. but just like anything they all have limits.   So if this machine has 10GB of RAM, and the webhost offered plans that have 1GB of RAM, then on that machine they can only have 10 customers right?  WRONG.  If each customer pays $100/month, then of course they would love to have as many customers on that machine as possible.  This builtin incentive is just the reality and isn't anyone fault.</p>

<h3>Where it gets Evil</h3>
<p>Here's what goes on.. all the host advertises is the 1GB of guaranteed RAM with your machine, but for even if the web server was fairly busy it would never use all of that ram because all the software is careful not to use too much, or has no need for any RAM.  Runtime libraries and internal caches use ram, but it's not directly accessed by the customer, only the software.   What happens is when those 10 customers aren't using 100% of their ram, which never happens, then the virtualization technology can use that RAM elsewhere.  So technically you do have 1GB of RAM available, but if you aren't using it then it is essentially FREE RAM that they can sell to another customer.  The only way this wouldn't work of course is if all 11 customers somehow used 100% of RAM simultaneously, at that point the 11th customer would be ramless.  But that is impossible because the system is a load-balancing system that provides both an upper and a lower limit to how much RAM is allotted to each virtual machine.</p>
<p>It sounds unrealistic but I see server farms all the time that are stuffed full of virtual machines, like situations where there are 100 1GB customers all sharing 10GB of RAM..  no-one uses the whole 1GB allotted to them as the maximum amount they can use, and they don't know because it appears they have a lot of free RAM, but really that is virtual RAM and could be used by anyone else on the machine.</p>

<h3>Where it gets Fun (for me)</h3>
<p><a class="IFL" href="http://www.askapache.com/linux/bash-power-prompt.html"><img src="http://uploads.askapache.com/2010/03/askapache-htop.jpg" alt="The HTOP command in full color to manage mysql" title="The HTOP command in full color to manage mysql" width="404" height="176" class="size-full wp-image-4149" /></a>This is actually even worse for anyone who is using what they call "shared-hosting" which is the budget hosting that is the most common.  With shared-hosting there is actually some skill involved on the hosting companies part, like real linux skills.  In this setup they may or more often may not use any virtualization software.  It's just a vanilla multi-user server machine where each customer gets a restricted unix account that powers their website using the same system as thousands of others on the box.  This is usually dirt cheap because it costs so little to do, but alot of companies charge outrageous amounts for shared-hosting because they make it look really full-featured, which it can be, they just don't mention 1000 other people use the same machine, hard-drive, /tmp directory, network device, IP address, etc..  Alot of the times the cheaper end of the spectrum is where the most gifted system administrators are located, they are so good with linux administration that they could fit 10 customers and 100 websites on an XBOX converted to run linux, and you'd think you got a great deal until you found out! lol.  Anyone alive is able to buy more hardware to expand their capacity to take on more customers,  but it takes a lot of knowhow and real skill to have that many users on 1 machine.  I've seen pretty extreme cases that are analogous to the XBOX example (which is possible by the way).<br class="C" /></p>
<p>I personally love shared-hosting environments, because for those of us who know almost as much or more than the system administrators running the machine we are able to use a disproportionate (legally) amount of the CPU and RAM available on the system.  So for example my sites would  all show up fast and be able to handle more traffic than several other customers combined.  Not because
anything has been circumvented, but because I am able to access and utilize as much of the guaranteed 1GB of RAM that I am paying for every month, which is usually just a few bucks.  The downside is that when you have corporate sites or really high-traffic sites then you are forced to move to a more powerful machine..  </p>
<p>This leads to a familiar situation for some of you..  When your site starts becoming popular and you are getting a lot of traffic, this means that your site could be using 10x the amount of RAM and Bandwidth of any other customer in that server farm.  And what that really means to the webhost is that you are costing them 10x what anyone else is..  And if they removed you, they would have the space for 10 new customers to take your place, and they would make 10x more money.  DreamHost is notorious for terminating accounts because of that..  It happened to me except I was given the option to pay 5x more a month for their "upgrade" to a VPS.  Giant shared-hosts advertise like crazy how they offer unlimited bandwidth, but <strong>when you start using 100x more bandwidth than anyone on your server you are costing them 100x what you are paying them, every month</strong>.  That's why you will never see a webhost offering this kind of unlimited bandwidth that doesn't require you to sign a contract giving them permission to terminate your account <em>for any reason</em>.  Seriously read the fine print at DreamHost or anywhere else, it's included because that is a core part of their business to terminate anyone using too much bandwidth since that is bandwidth they can't sell to dozens of other customers.  That's why I eventually closed my account with them and moved to a legitimate company, it's a great host for spammers though.</p>

<p>Back in the mid-90's I was doing a lot of war-dialing with my modem and discovering all sorts of networks and machines, many of them were Unix and Solaris based public systems, and when I managed to gain access to the system and found myself staring at a unix shell I was very excited but also a total idiot.  In those days of using the phone networks to research unknown systems it was very difficult for anyone to actually get the phone company to trace a call, so instead of what happens today where it is child's play to trace an IP address, back then it was a very real back-and-forth battle between the system admin and whoever was gaining access to their system.  Essentially, I would gain a shell or some kind of terminal, and just go at it trying to figure out what it could do, trying all kinds of commands.  Inevitably this would eventually alert even the laziest admin and they would proceed to attempt to lock me out. It was great sport and extremely addictive.  When my favorite system (a massive sun machine in the basement of a big library) finally locked me out and I couldn't get back in I went to my local library and got some reading material -- one of my favorites was the red hat bible.  I was able to acquire my own computer and the first thing I did was install red hat linux onto it from the discs included with the book.  For the next several years I was essentially offline, all we had at home was a modem and it was becoming difficult to locate any more systems in my area code.. I was into phreaking of course as well, but I never was able to make free long-distance war-dialing a reality.  So I just read the books and learned what I could.  I would also goto the library when I could in order to use their machines which were connected to the internet (before aol it was much different than today's internet) and since my time was short I would download as many documents as I could so that I could read them offline.  The TLDP documentation that we know today was around back then in various forms, and I read every HOWTO in the index, though not understanding half.  The other big resource I found for really intense reading was the <a href="http://www.kernel.org/doc/Documentation/">kernel documentation</a>, which admitedly I still don't comprehend 1/4th of..   I try and peruse all the new documents when a new kernel is released, since the kernel is where all the real action is, hence the military authoritative name, and that is how I discovered one of the coolest features of Linux that I have found.  TMPFS!</p>



<h2>TMPFS kills the RAMDISK</h2>
<p>Ok so we all know what RAM is, it's the memory cards that most people never see that is used by the computer to store and access data that all programs need.  RAM is very expensive compared to most PC components, because it's what makes a computer blazing fast or slow.  So real quick lets look at a few (there are not many) ways that various linux hackers use RAM in non-conventional ways in the past.</p>
<p>Tmpfs is a file system which keeps all files in virtual memory.  Everything is temporary in the sense that no files will be created on your hard drive. If you reboot, everything in tmpfs will be lost.</p>
<p>In contrast to RAM disks, which get allocated a fixed amount of physical RAM, tmpfs grows and shrinks to accommodate the files it contains and is able to swap unneeded pages out to swap space.</p>
<p>Like a ramdisk, tmpfs can use your RAM, but it can also use your swap devices for storage. And while a traditional ramdisk is a block device and requires a mkfs command of some kind before you can actually use it, tmpfs is a filesystem, not a block device; you just mount it, and it's there. All in all, this makes tmpfs the niftiest RAM-based filesystem I've had the opportunity to meet.</p>
<p>If I had to <strong>explain tmpfs</strong> in one breath, I'd say that tmpfs is like a ramdisk, but different. Like a ramdisk, tmpfs can use your RAM, but it can also use your swap devices for storage. And while a traditional ramdisk is a block device and requires a mkfs command of some kind before you can actually use it, tmpfs is a filesystem, not a block device; you just mount it, and it's there. All in all, this makes tmpfs the niftiest RAM-based filesystem I've had the opportunity to meet.</p>
<br class="C" />




<p>What kind of filesystem is used on your server to store all your site files?  EXT4, REISERFS, EXT3, NFS, etc.. are the usual filesystems, Windows users are limited to the NTFS filesystem.   A filesystem is different than a device, a device is a hard-drive disk.  A filesystem is how the device is formatted to allow for file and folder structures.  A hard drive is slow compared to RAM, no question about that.  So what if instead of your server serving files off a hard-drive it served files stored in RAM?  <strong>30x faster thats what happens!</strong></p>
<p class="wnote">I just figured out how to store my cached static files created by WP-Super Cache in my server's RAM, and the difference is unbelievable.  My "AskApache Crazy Cache" plugin basically forces WP-Super Cache, Hyper Cache, etc.. to recreate a static cached file for every page on a blog.  For the AskApache.com site this takes around 3 minutes to complete.  Once I switched to using this new method of storing the files on RAM I am able to re-cache the entire site in about 15 seconds!!!!</p>


<p class="wnote">tmpfs is a dynamically expandable/shrinkable ramdisk, and will
# use almost no memory if not populated with files</p>


<blockquote cite="">
<p>Tmpfs is a file system which keeps all files in virtual memory.</p>
<p>Everything in tmpfs is temporary in the sense that no files will be created on your hard drive. If you unmount a tmpfs instance, everything stored therein is lost.</p>
<p>tmpfs puts everything into the kernel internal caches and grows and shrinks to accommodate the files it contains and is able to swap unneeded pages out to swap space. It has maximum size limits which can be adjusted on the fly via 'mount -o remount ...'</p>
<p>If you compare it to ramfs (which was the template to create tmpfs) you gain swapping and limit checking. Another similar thing is the RAM disk (/dev/ram*), which simulates a fixed size hard disk in physical RAM, where you have to create an ordinary filesystem on top. Ramdisks cannot swap and you do not have the possibility to resize them.</p>
<p>Since tmpfs lives completely in the page cache and on swap, all tmpfs pages currently in memory will show up as cached. It will not show up as shared or something like that. Further on you can check the actual RAM+swap use of a tmpfs instance with df(1) and du(1).</p>
</blockquote>

<p>Both tmpfs and ramfs mount will give you the power of fast reading and writing files from and to the primary memory. When you test this on a small file, you may not see a huge difference. You’ll notice the difference only when you write large amount of data to a file with some other processing overhead such as network.</p>




<h2>TMPFS uses RAM+SWAP</h2>
<p>TMPFS is another filesystem with uniquely cool capabilities.  It stores any files contained within it on RAM and in SWAP which means your server can access any files stored on TMPFS without even having to access the disk, which according to technical stats is around 30 times faster than accessing a file off disk.</p>
<p>Some other cool aspects of TMPFS are that it intelligently and automatically sizes itself to be just alittle bigger then it needs to be.  So when you remove files to a folder stored on a TMPFS filesystem, the TMPFS filesystem shrinks by allocating less RAM and/or SWAP.  Conversely when adding files to TMPFS it grows larger.  You can set the max-size and max-number-of-files as a mount option to make sure your TMPFS never uses all of the available RAM and SWAP, which would halt your server.</p>

<h3>Swap</h3>
<p>Find the swap size.</p>
<pre>
# free -m -t
             total       used       free     shared    buffers     cached
Mem:           458         93        364          0          0          0
-/+ buffers/cache:         93        364
Swap:          900          0        900
Total:        1358         93       1264
</pre>

<pre>
Adding 3004144k swap on /dev/sdb2.  Priority:-1 extents:1 across:3004144k
Adding 2096472k swap on /dev/sda3.  Priority:-2 extents:1 across:2096472k
</pre>

<h2>Using TMPFS for Cache</h2>
<p>The method here will show how to create and use a TMPFS filesystem to hold all the static files created by WP-Super Cache.  These static files are served to visitors instead of loading php for every request, so by moving those static files to TMPFS your server will be able to access and start sending your site to the browser 30x faster!</p>
<p>The WP-Super Cache plugin stores all the static files in the wp-content/cache folder of your WordPress installation, so to enable TMPFS we simply will create a new TMPFS filesystem and mount it to the wp-content/cache folder.  That makes anything in that folder (all the static files) be part of the TMPFS filesystem.</p>


<h2>Boosting Cache with TMPFS</h2>
<p>There are a lot of maybe new concepts surrounding TMPFS and it may seem too complicated, but the process of actually setting up a robust tmpfs to use for wp-super-cache's cache folder is actually very simple.  As long as you have shell access to your server and the permissions required (any sudo or private server should be good to go) you can set this up in a couple minutes and not really have to give it a second thought or debug anything.  Here's the process I've used on several client sites.</p>
<ol>
<li>Create a TMPFS Filesystem and Mount at /wp-content/cache/</li>
<li>Restore TMPFS Cached Files across Reboots</li>
<li>Keep a semi-current mirror of the TMPFS files on Disk</li>
</ol>
<br class="C" />

<h3>Create TMPFS at wp-content/cache</h3>
<p>/etc/fstab</p>
<pre>tmpfs /home/askapache/wp-content/cache tmpfs defaults,size=2g,noexec,nosuid,uid=648,gid=648,mode=1755 0 0</pre>


<h3>Restoring TMPFS across Reboots</h3>
<p>In /etc/rc.local</p>
<pre>
ionice -c3 -n7 nice -n 19 rsync -ahv --stats --delete /_b/tmpfs/cache/ /home/askapache/wp-content/cache/ 1&gt;/dev/null
</pre>

<h3>Mirroring TMPFS to Disk</h3>
<p>Cronjob entry</p>
<pre>
*/5 * * * * /usr/bin/ionice -c3 -n7 /bin/nice -n 19 /usr/bin/rsync -ah --stats --delete /home/askapache/wp-content/cache/ /_b/tmpfs/cache/ 1&gt;/dev/null
</pre>






<span id="more-3220"></span>
<h2>/tmp, /var/run, and /var/lock</h2>
<p>The directories /tmp, /var/run, and /var/lock contain files that are not needed across reboots.  This means they are ideal candidates for tmpfs.  HEre's how to do it.</p>
<pre>tmpfs /var/run tmpfs defaults,rw,nosuid,mode=0755 0 0</pre>
<pre>tmpfs /var/lock tmpfs defaults,rw,noexec,nosuid,nodev,mode=1777 0 0</pre>

<h2>Resize /dev/shm</h2>
<p>You can view your current /dev/shm size with the command <code>df -ha|grep /dev/shm</code> then if you want to resize that use the command:</p>
<pre>mount -t tmpfs -o remount,size-2G,rw,nosuid,nodev tmpfs /dev/shm</pre>

<pre>
Secure /dev/shm:
&nbsp;
Step 1: Edit your /etc/fstab:
&nbsp;
nano -w /etc/fstab
&nbsp;
Locate:
&nbsp;
none /dev/shm tmpfs defaults,rw 0 0
&nbsp;
Change it to:
&nbsp;
none /dev/shm tmpfs defaults,nosuid,noexec,rw 0 0
&nbsp;
Step 2: Remount /dev/shm:
&nbsp;
mount -o remount /dev/shm
&nbsp;
guilt makes extensive use of the &#039;$$&#039; shell variable for temporary
files in /tmp. This is a serious security vulnerability; on multi-user
systems it allows an attacker to clobber files with something like the
following:
&nbsp;
for i in `seq 1 32768`; do
ln -sf /etc/passwd /tmp/guilt.log.$i;
done
&nbsp;
(In this example, if root does e.g. &#039;guilt push&#039;, /etc/passwd will get
clobbered.)
</pre>
<br class="C" />


<h3>Securing and Using /tmp</h3>
<ul>
<li><a href="http://www.sysadmin.md/secure-temporary-folders-on-existing-unix-or-linux-systems.html">Secure temporary folders on existing Unix or Linux systems</a></li>
<li><a href="https://wiki.torproject.org/noreply/TheOnionRouter/OperationalSecurity">Encrypt Storage and Swap Space</a></li>
</ul>










<p><a id="tmpfs-mount"></a></p>
<h2>tmpfs mount parameters</h2>
<p>A good way to find a good tmpfs upper-bound is to use top to monitor your system's swap usage during peak usage periods. Then, make sure that you specify a tmpfs upper-bound that's slightly less than the sum of all free swap and free RAM during these peak usage times. </p>
<p><strong>mode=1777</strong> sets sticky bit on directory. Only file owners can delete files in this directory.</p>
<p>The following parameters accept a suffix k, m or g for Ki, Mi, Gi (binary kilo, mega and giga) and can be changed on remount.</p>
<ul>
<li><strong>size</strong>:  Override default maximum size of the filesystem.  The size is given in bytes, and rounded down to entire pages.  The default is half of the memory.The limit of allocated bytes for this tmpfs instance. The default is half of your physical RAM without swap. If you oversize your tmpfs instances the machine will deadlock since the OOM handler will not be able to free that memory.</li>
<li><strong>nr_inodes</strong>:  Set number of inodes.</li>
<li><strong>nr_blocks</strong>:  Set number of blocks.</li>
<li><strong>mode</strong>: The permissions as an octal number</li>
<li><strong>uid</strong>: The user id</li>
<li><strong>gid</strong>: The group id</li>
</ul>
<pre>mount -t tmpfs -o size=10G,nr_inodes=10k,mode=700 tmpfs /mytmpfs</pre>
<p>Will give you tmpfs instance on /mytmpfs which can allocate 10GB RAM/SWAP in 10240 inodes and it is only accessible by root.</p>









<p><a id="tmp-tmpfs"></a></p>
<h2>Using tmpfs for /tmp storage</h2>
<p>Many users find it very convenient to use tmpfs for /tmp and /var/tmp which does a number of positive things.  Any temporary files are instead created in RAM not your hard-drive, which means that reading/writing/accessing those temporary files by various processes doesn't slow down your hard-drive read/writes/accesses for your other processes.  This also has a side-effect of making your hard-drive have a longer life as it reduces activity by a huge amount.</p>
<p>Remember that tmpfs uses both RAM and swap, so make sure your machine has a large swapfile, like gigabytes.  If your tmpfs consumes all the swap and RAM then you are screwed, so make sure that you correctly set the mount options for the tmpfs so that it doesn't do that.  If your /tmp or /var/tmp gets filled with tmp files that for some reason don't get deleted except at reboot, and your machine has a very high uptime, then you will want to run some cron jobs to periodically clean the /tmp and /var/tmp directories of older files...</p>

<p>Here's an example scenario: let's say that we have an existing filesystem mounted at /tmp. However, we decide that we'd like to start using tmpfs for /tmp storage.</p>
<p>with recent 2.4 kernels, you can mount your new /tmp filesystem without getting the "device is busy" error: </p>
<pre>mount tmpfs /tmp -t tmpfs -o size=64m</pre>
<p>With a single command, your new tmpfs /tmp filesystem is mounted at /tmp, on top of the already-mounted partition, which can no longer be directly accessed. However, while you can't get to the original /tmp, any processes that still have open files on this original filesystem can continue to access them. And, if you umount your tmpfs-based /tmp, your original mounted /tmp filesystem will reappear. In fact, you can mount any number of filesystems to the same mountpoint, and the mountpoint will act like a stack; unmount the current filesystem, and the last-most-recently mounted filesystem will reappear from underneath.</p>







<p><a id="bind-mounts"></a></p>
<h2>Bind Mounts</h2>
<p>Using bind mounts, we can mount all, or even part of an already-mounted filesystem to another location, and have the filesystem accessible from both mountpoints at the same time!</p>
<p>For example, you can use bind mounts to mount your existing /tmp filesystem to /sites/askapache.com/tmp, as follows:</p>
<pre>mount --bind /tmp /sites/askapache.com/tmp</pre>
<p>Now, if you look inside /sites/askapache.com/tmp, you'll see your /tmp filesystem and all its files. And if you modify a file on your /tmp filesystem, you'll see the modifications in /sites/askapache.com/tmp as well. This is because <strong>they are one and the same filesystem; the kernel is simply mapping the filesystem to two different mountpoints for us</strong>. </p>
<p>Note that when you mount a filesystem somewhere else, any filesystems that were mounted to mountpoints inside the bind-mounted filesystem will not be moved along. In other words, if you have /tmp/cache on a separate filesystem, the bind mount we performed above will leave /sites/askapache.com/tmp/cache empty. You'll need an additional bind mount command to allow you to browse the contents of /tmp/cache at /sites/askapache.com/tmp/cache:</p>
<pre>mount --bind /tmp/cache /sites/askapache.com/tmp/cache</pre>

<h3>Bind mounting and /dev/shm</h3>
<p>glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for POSIX shared memory (shm_open, shm_unlink). Adding the following line to /etc/fstab should take care of this:</p>
<pre>tmpfs  /dev/shm  tmpfs  defaults  0 0</pre>

<p>Many systems by default have a tmpfs filesystem mounted at /dev/shm that defaults to a size of half of your physical RAM without swap.  Say you decide that you'd like to start using tmpfs for /tmp, which currently lives on your root filesystem. Rather than mounting a new tmpfs filesystem to /tmp (which is possible), you may decide that you'd like the new /tmp to share the currently mounted /dev/shm filesystem. However, while you could bind mount /dev/shm to /tmp and be done with it, your /dev/shm contains some directories that you don't want to appear in /tmp. So, what do you do? How about this:</p>



<pre>
mkdir /dev/shm/tmp
chmod 1777 /dev/shm/tmp
mount --bind /dev/shm/tmp /tmp
</pre>

<p>In this example, we first create a /dev/shm/tmp directory and then give it 1777 perms, the proper permissions for /tmp. Now that our directory is ready, we can mount /dev/shm/tmp, and only /dev/shm/tmp to /tmp. So, while /tmp/foo would map to /dev/shm/tmp/foo, there's no way for you to access the /dev/shm/bar file from /tmp.</p>
<br class="C" />









<p><a id="default-tmpfs-workaround"></a></p>
<h2>/etc/default/tmpfs WorkAround</h2>
<pre>
$ cat /etc/default/tmpfs
# SHM_SIZE sets the maximum size (in bytes) that the /dev/shm tmpfs can use.
# If this is not set then the size defaults to the value of TMPFS_SIZE
# if that is set; otherwise to the kernel&#039;s default.
#
# The size will be rounded down to a multiple of the page size, 4096 bytes.
SHM_SIZE=524288000
# TMPFS_SIZE sets the max size that /dev/shm can use.  By default, the
# kernel sets this upper limit to half of available memory.
TMPFS_SIZE=524288000
</pre>




<p><a id="rsync-vs-cp"></a></p>
<h2>RSYNC vs. CP</h2>
<pre>
rsync [options]  SRC DEST
rsync -av --delete --stats /home/wincom/public_html/wp-content/cache/ /backups/tmp-mnt/cache/
-a, --archive               archive mode; same as -rlptgoD (no -H)
-r, --recursive             recurse into directories
-l, --links                 copy symlinks as symlinks
-p, --perms                 preserve permissions
-t, --times                 preserve times
-g, --group                 preserve group
-o, --owner                 preserve owner (super-user only)
-D                          same as --devices --specials
    --devices               preserve device files (super-user only)
    --specials              preserve special files
 -h, --human-readable        output numbers in a human-readable format
     --progress              show progress during transfer
</pre>




<p><a id="mount-options"></a></p>
<h2>Mount Options</h2>
<p>The following options apply to any file system that is being mounted (but not every file  system  actually honors them)</p>
<ul>
<li><code>async</code> All I/O to the file system should be done asynchronously.</li>
<li><code>atime</code> Update inode access time for each access. This is the default.</li>
<li><code>auto</code> Can be mounted with the -a option.</li>
<li><code>defaults</code> Use default options: rw, suid, dev, exec, auto, nouser, and async.</li>
<li><code>dev</code> Interpret character or block special devices on the file system.</li>
<li><code>exec</code> Permit execution of binaries.</li>
<li><code>group</code> Allow an ordinary (i.e., non-root) user to mount the file system if one of his groups matches the group of the device.  This option implies the options nosuid and nodev (unless overridden by subsequent options, as in the option line group,dev,suid).</li>
<li><code>mand</code> Allow mandatory locks on this filesystem. See fcntl(2).</li>
<li><code>_netdev</code> The filesystem resides on a device that requires network access (used to prevent the system from attempting to mount these filesystems until the network has been enabled on the system).</li>
<li><code>noatime</code> Do not update inode access times on this file system (e.g, for faster access on the news spool to speed up news servers).</li>
<li><code>nodiratime</code> Do not update directory inode access times on this filesystem.</li>
<li><code>noauto</code> Can only be mounted explicitly (i.e., the -a option will not cause the file system to be mounted).</li>
<li><code>nodev</code> Do not interpret character or block special devices on the file system.</li>
<li><code>noexec</code> Do not allow direct execution of any binaries on the mounted file system.  (Until recently it was possible to run binaries anyway using a command like /lib/ld*.so /mnt/binary. This trick fails since Linux 2.4.25 / 2.6.0.)</li>
<li><code>nomand</code> Do not allow mandatory locks on this filesystem.</li>
<li><code>nosuid</code> Do not allow set-user-identifier or set-group-identifier bits to take effect. (This seems safe, but is in fact rather unsafe if you have suidperl(1) installed.)</li>
<li><code>nouser</code> Forbid an ordinary (i.e., non-root) user to mount the file system.  This is the default.</li>
<li><code>owner</code> Allow an ordinary (i.e., non-root) user to mount the file system if he is the owner of the device.  This option implies the options nosuid and nodev (unless overridden by subsequent options, as in the option line owner,dev,suid).</li>
<li><code>remount</code> Attempt to remount an already-mounted file system.  This is commonly used to change the mount flags for a file system, especially to make a readonly file system writeable. It does not change device or mount point.</li>
<li><code>ro</code> Mount the file system read-only.</li>
<li><code>_rnetdev</code> Like _netdev, except "fsck -a" checks this filesystem during rc.sysinit.</li>
<li><code>rw</code> Mount the file system read-write.</li>
<li><code>suid</code> Allow set-user-identifier or set-group-identifier bits to take effect.</li>
<li><code>sync</code> All I/O to the file system should be done synchronously. In case of media with limited number of write cycles (e.g. some flash drives) "sync" may cause life-cycle shortening.</li>
<li><code>dirsync</code> All directory updates within the file system should be done synchronously.  This affects the following system calls: creat, link, unlink, symlink, mkdir, rmdir, mknod and rename.</li>
<li><code>user</code> Allow  an ordinary user to mount the file system.  The name of the mounting user is written to mtab so that he can unmount the file system again.  This option implies the options noexec, nosuid, and nodev (unless overridden by subsequent options, as in the option line user,exec,dev,suid).</li>
<li><code>users</code> Allow every user to mount and unmount the file system.  This option implies the options noexec, nosuid, and nodev (unless overridden by subsequent options, as in the option line users,exec,dev,suid).</li>
</ul>



<p><a id="filesystems"></a></p>
<h2>Filesystems</h2>
<p>You can find out what is filesystems are in place by using one of the following linux commands:</p>
<pre>
cat /etc/fstab
cat /etc/mtab
cat /proc/mounts
df -a
</pre>
<h2>/etc/fstab</h2>
<pre>
       /etc/fstab        file system table
       /etc/mtab         table of mounted file systems
       /etc/mtab~        lock file
       /etc/mtab.tmp     temporary file
       /etc/filesystems  a list of filesystem types to try
</pre>

<p>From /etc/mtab</p>
<pre>none /tmp tmpfs size=128m,mode=1777 0 0</pre>

<p>From /proc/mounts</p>
<pre>none /tmp tmpfs rw,nodev,relatime,size=131072k 0 0</pre>






<br class="C" />
<p><a id="fstab"></a></p>
<h2>/etc/fstab</h2>
<p>It is possible that files /etc/mtab and /proc/mounts don’t match. The first file is based only on the mount command options, but the content of the second file also depends on the kernel and others settings (e.g.  remote NFS server. In particular case  the  mount  command  may reports unreliable information about a NFS mount point and the /proc/mounts file usually contains more reliable information.)</p>
<p>This file is used in three ways:</p>
<ol>
<li>The following command (usually given in a bootscript) causes all file systems mentioned in fstab (of the proper type and/or having or not having the proper options) to be mounted as indicated, except for those whose line contains the noauto keyword. Adding the -F option will  make  mount  fork,  so that the filesystems are mounted simultaneously.<pre>mount -a [-t type] [-O optlist]</pre></li>
<li>When mounting a file system mentioned in fstab, it suffices to give only the device, or only the mount point.</li>
<li>Normally, only the superuser can mount file systems.  However, when fstab contains the user option on a line, anybody can mount the corresponding system.</li>
</ol>
<p>The programs mount and umount maintain a list of currently mounted file systems in the file /etc/mtab.</p>
<p>Only the user that mounted a filesystem can unmount it again.  If any user should be able to unmount, then use users instead of user in the fstab line.  The owner option is similar to the user option, with the restriction that the user must be the owner of the special file.  The group option is similar, with the restriction that the user must be member of the group of the special file.</p>
<p>The order of records in fstab is important because fsck(8), mount(8), and umount(8) sequentially iterate through fstab doing their thing.</p>
<h3>The first field, (fs_spec)</h3>
<p>Describes the block special device or remote filesystem to be mounted.  For ordinary mounts it will hold (a link to) a block special device node (as created by mknod(8)) for the device to be mounted, like ‘/dev/cdrom’ or ‘/dev/sdb7’.  For NFS mounts one will have <code>&lt;host&gt;:&lt;dir&gt;</code>, e.g., ‘knuth.aeb.nl:/’.  For procfs, use ‘proc’.</p>
<p>Instead of giving the device explicitly, one may indicate the (ext2 or xfs) filesystem that is to be mounted by its UUID or volume label (cf.  e2label(8) or xfs_admin(8)), writing LABEL=<label> or UUID=<uuid>, e.g., ‘LABEL=Boot’ or  ‘UUID=3e6be9de-8139-11d1-9106-a43f08d823a6’.  This will make the system more robust: adding or removing a SCSI disk changes the disk device name but not the filesystem volume label.</p>
<h3>The second field, (fs_file)</h3>
<p>Describes the mount point for the filesystem.  For swap partitions, this field should be specified as ‘none’. If the name of the mount point contains spaces these can be escaped as ‘\040’.</p>
<p>The  third  field,  (fs_vfstype),  describes the type of the filesystem.  Linux supports lots of filesystem types, such as adfs, affs, autofs, coda, coherent, cramfs, devpts, efs, ext2, ext3, hfs, hpfs, iso9660, jfs, minix, msdos, ncpfs, nfs, ntfs, proc, qnx4, reiserfs, romfs, smbfs, sysv, tmpfs, udf, ufs, umsdos, vfat, xenix, xfs, and possibly others. For more details, see mount(8).  <strong>For the filesystems currently supported by the running kernel, see /proc/filesystems</strong>.  An entry swap denotes  a  file  or  partition  to  be  used  for  swapping,  cf.  swapon(8).  An entry ignore causes the line to be ignored.  This is useful to show disk partitions which are currently unused.</p>
<h3>The fourth field, (fs_mntops)</h3>
<p>Describes the mount options associated with the filesystem.  It  is formatted as a comma separated list of options.  It contains at least the type of mount plus any additional options appropriate to the filesystem type.  For documentation on the available options for non-nfs file systems, see mount(8).  For documentation on all nfs-specific options have a look at nfs(5).</p>
<p>Common for all types of file system are the options:</p>

<ul>
<li><strong>noauto</strong>: (do not mount when "mount -a" is given, e.g., at boot time)</li>
<li><strong>user</strong>: (allow a user to mount)</li>
<li><strong>owner</strong>: (allow device owner to mount)</li>
<li><strong>pamconsole</strong>: (allow a user at the console to mount)</li>
<li><strong>comment</strong>: (e.g., for use by fstab-maintaining programs).</li>
</ul>
<h3>The fifth field, (fs_freq)</h3>
<p>Used for these filesystems by the dump(8) command to determine which filesystems need to be dumped.  If the fifth field is not present, a value of zero is returned and dump will assume that the filesystem does not need to be dumped.</p>
<h3>The  sixth  field,  (fs_passno)</h3>
<p>Used by the fsck(8) program to determine the order in which filesystem checks are done at reboot time.  The root filesystem should be specified with a fs_passno of 1, and other filesystems should have a fs_passno of 2.  Filesystems within a drive will be checked sequentially, but filesystems on different drives will be checked at the same time to utilize parallelism available in the hardware.  If the sixth field is not present or zero, a value of zero is returned and <strong>fsck will assume that the filesystem does not need to be checked</strong>.








<h3>More Reading</h3>
<ul>
<li><a href="http://www.thegeekstuff.com/2008/11/overview-of-ramfs-and-tmpfs-on-linux/">Overview of RAMFS and TMPFS on Linux</a></li>
<li><a href='http://uploads.askapache.com/2009/09/ramfs-rootfs-initramfs.txt'>ramfs, rootfs and initramfs</a></li>
<li><a href='http://uploads.askapache.com/2009/09/tmpfs.txt'>Tmpfs is a file system which keeps all files in virtual memory</a></li>
<li><a href="http://www.ibm.com/developerworks/library/l-fs3.html">IBM: Advanced filesystem implementor's guide, Part 3</a></li>
<li><a href="http://en.wikipedia.org/wiki/TMPFS">TMPFS Wikipedia Entry</a></li>
<li><a href="http://en.wikipedia.org/wiki/Shared_memory">Shared Memory</a></li>
<li><a href="http://kevin.vanzonneveld.net/techblog/article/create_turbocharged_storage_using_tmpfs/">Create turbocharged storage using tmpfs</a></li>

<li><a href="http://dev.mysql.com/doc/refman/4.1/en/temporary-files.html">Where MySQL Stores Temporary Files</a></li>
<li><a href="http://www.linuxized.com/2009/05/speeding-up-firefox-with-tmpfs-and-automatic-rsync/">speeding up firefox with tmpfs and automatic rsync</a> <a href="http://www.linuxized.com/wp-content/uploads/2009/05/speedfox">(shell-script)</a> <a href="http://autoverse.net/blog/2009/apr/23/speed-firefox/">Original</a></li>
<li><a href="http://www.kernel.org/doc/Documentation/filesystems/tmpfs.txt">kernel documentation for tmpfs</a></li>
<li><a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=386368">initscripts: please don't mount /dev/shm noexec</a></li>
<li><a href="http://forums.debian.net/viewtopic.php?t=16450">HOWTO: Using tmpfs for /tmp, /var/{log,run,lock...}</a></li>
<li><a href="http://forums.gentoo.org/viewtopic-t-371889-highlight-tmpfs.html">Gentoo Forums: Using tmpfs for /var/{log,lock,...}</a></li>
<li><a href="http://forums.gentoo.org/viewtopic-t-717117-highlight-tmpfs.html">[TIP] Firefox and tmpfs: a surprising improvement</a></li>
</ul>

<blockquote cite="http://openquery.com/blog/experiment-mysql-tmpdir-on-tmpfs">
<cite><a href="http://openquery.com/blog/experiment-mysql-tmpdir-on-tmpfs">Experiment: MySQL tmpdir on tmpfs</a></cite>
<p>In MySQL, the tmpdir path is mainly used for disk-based sorts (if the sort_buffer_size is not enough) and disk-based temp tables. The latter cannot always be avoided even if you made tmp_table_size and max_heap_table_size quite large, since MEMORY tables don’t support TEXT/BLOB type columns, and also since you just really don’t want to run the risk of exceeding available memory by setting these things too large.</p></blockquote>
<br class="C" />






<h2>Use tmpfs for MySQL</h2>
<pre>
--tmpdir=path, -t path
</pre>
<blockquote cite="http://dev.mysql.com/doc/refman/4.1/en/server-options.html#option_mysqld_tmpdir">The path of the directory to use for creating temporary files. It might be useful if your default /tmp directory resides on a partition that is too small to hold temporary tables. Starting from MySQL 4.1.0, this option accepts several paths that are used in round-robin fashion. Paths should be separated by colon characters (“:”) on Unix and semicolon characters (“;”) on Windows, NetWare, and OS/2. If the MySQL server is acting as a replication slave, you should not set --tmpdir to point to a directory on a memory-based file system or to a directory that is cleared when the server host restarts. For more information about the storage location of temporary files, see Section A.1.4.4, “Where MySQL Stores Temporary Files”. A replication slave needs some of its temporary files to survive a machine restart so that it can replicate temporary tables or LOAD DATA INFILE operations. If files in the temporary file directory are lost when the server restarts, replication fails. </blockquote>

<blockquote cite="http://dev.mysql.com/doc/refman/4.1/en/temporary-files.html">On Unix, MySQL uses the value of the TMPDIR  environment variable as the path name of the directory in which to store temporary files. If TMPDIR  is not set, MySQL uses the system default, which is usually /tmp, /var/tmp, or /usr/tmp.

 If the file system containing your temporary file directory is too small, you can use the --tmpdir option to mysqld to specify a directory in a file system where you have enough space.

Starting from MySQL 4.1, the --tmpdir option can be set to a list of several paths that are used in round-robin fashion. Paths should be separated by colon characters (“:”) on Unix and semicolon characters (“;”) on Windows, NetWare, and OS/2.
Note

To spread the load effectively, these paths should be located on different physical disks, not different partitions of the same disk.

If the MySQL server is acting as a replication slave, you should not set --tmpdir to point to a directory on a memory-based file system or to a directory that is cleared when the server host restarts. A replication slave needs some of its temporary files to survive a machine restart so that it can replicate temporary tables or LOAD DATA INFILE operations. If files in the temporary file directory are lost when the server restarts, replication fails.

MySQL creates all temporary files as hidden files. This ensures that the temporary files are removed if mysqld is terminated. The disadvantage of using hidden files is that you do not see a big temporary file that fills up the file system in which the temporary file directory is located.
</blockquote>
<br class="C" />








<h2>Shell Script for Firefox tmpfs</h2>
<pre>
#!/bin/bash
### Bind temporary directories to /dev/shm ###
# I do this instead of mounting tmpfs on the #
# directories, so less memory gets wasted.   #
##############################################
mkdir /dev/shm/{tmp,lock}
mount --bind /dev/shm/tmp /tmp
mount --bind /dev/shm/tmp /var/tmp
mount --bind /dev/shm/lock /var/lock
chmod 1777 /dev/shm/{tmp,lock}
</pre>




<hr />

<p><strong>Hey!</strong> You made it!@ at least to the bottom of the page..  I still have to finish this article, so check back in a few months.</p><p><a href="http://www.askapache.com/optimize/super-speed-secrets.html"></a><a href="http://www.askapache.com/optimize/super-speed-secrets.html">30x Faster Cache and Site Speed with TMPFS</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/optimize/super-speed-secrets.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

