<?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;  cheatsheet</title>
	<atom:link href="http://www.askapache.com/search/cheatsheet/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>3 Ways to Serve PDF Files using Htaccess Cookies, Headers, Rewrites</title>
		<link>http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html</link>
		<comments>http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html#comments</comments>
		<pubDate>Sun, 21 Aug 2011 03:07:53 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Htaccess]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=2328</guid>
		<description><![CDATA[<p><a class="IFL" href="http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html"><img height="60" width="45" src='http://uploads.askapache.com/2007/11/60x45_acrobat_trefoil.gif' alt='Adobe PDF' /></a>FYI, using the <a href="http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html">Mod_Rewrite Variables Cheatsheet</a> makes this example, and all advanced .htaccess code easier to understand.  This demo lets you set a cookie with 1 of 3 values, then you just request the pdf file with a normal link click and get 1 of 3 different responses. This is accomplished with a nice bit of <a href="http://www.askapache.com/htaccess/htaccess.html">.htaccess</a> code.<br class="C" /></p>
<div class="cnote">
<p><strong>Set PDF Viewing Mode</strong> - <kbd id="pdfr">Make a selection, then click the view pdf button.</kbd></p>
<p><span id="pdfi" class="FL btnn">Inline</span> <span id="pdfa" class="FL btnn">Download</span> <span id="pdfs" class="FL btnn">Save As</span> <a class="FL btnn" style="margin-left:10px; border-top:1px solid #96F8AF; background:-moz-linear-gradient(center top , #3E9D43, #6ED766) repeat scroll 0 0 transparent;margin-left:20px;" rel="nofollow" href="http://www.askapache.com/storage/pdf/AskApache-Test.pdf">View PDF using selected mode &#187;</a><br class="C" /></p>
</div>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html"></a><a href="http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html"><cite>AskApache.com</cite></a></p><p><a class="IFL" id="id10" href="http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html"></a>FYI, using the <a href="http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html">Mod_Rewrite Variables Cheatsheet</a> makes this example, and all advanced .htaccess code easier to understand.  This demo lets you set a cookie with 1 of 3 values, then you just request the pdf file with a normal link click and get 1 of 3 different responses. This is accomplished with a nice bit of <a href="http://www.askapache.com/htaccess/htaccess.html">.htaccess</a> code.<br /><br />As I explain the htaccess code that achieves this, keep in mind this is merely one simple application for this code.  It's much more advanced than your basic htaccess trick, notice how this htaccess acts like a php script, very unusual..  I really wanted to share this trick after I created it for one of my clients because this is the tip of the iceberg.  Another use would be to display an alternate style sheet depending on a users theme preference.  The coolest thing is that it uses multiple advanced .htaccess ideas.  This code uses mod_headers to set the Content-Disposition header for forcing a download and uses mod_rewrite to: Send different Content-Type headers, Check the value of a cookie, Set environment variables for use later by mod_headers header directive<br class="C" /></p>

<div class="cnote">
<p><strong>Set PDF Viewing Mode</strong> - <kbd id="pdfr">Make a selection, then click the view pdf button.</kbd></p>
<p><span id="pdfi" class="FL btnn">Inline</span> <span id="pdfa" class="FL btnn">Download</span> <span id="pdfs" class="FL btnn">Save As</span> <a class="FL btnn" style="margin-left:10px; border-top:1px solid #96F8AF; background:-moz-linear-gradient(center top , #3E9D43, #6ED766) repeat scroll 0 0 transparent;margin-left:20px;" rel="nofollow" href="http://www.askapache.com/storage/pdf/AskApache-Test.pdf">View PDF using selected mode &raquo;</a><br class="C" /></p>
</div>


<h2>What's Going On</h2>
<p>There are 3 different ways for a server to send a pdf file in response to a request for one.  This causes 3 different ways to open/view the pdf file in the clients browser.</p>
<ol>
<li>The browser display's a <strong>"Save File As"</strong> dialog, allowing you to save the file or open.</li>
<li>The browser opens the pdf file <strong>"Inline"</strong>, opening the pdf file in the browser like a web page.</li>
<li>The browser "<strong>Downloads</strong>" the pdf file automatically as an "<strong>Attachment</strong>" and then causes an external pdf reader program like adobe reader to open the file.</li>
</ol>
<p>Some people prefer to have the option of saving the file to view later, some prefer opening it with an external program, and some just like the pdf file to load right in the browser...  The point is that by using .htaccess, we can let them choose any of the 3 methods and save their preference for all further pdf files requested from our site by that user.</p>





<h2>How It Works</h2>
<p>When you click on one of the 3 demo buttons above, "Inline", "Save As", or "Download", a cookie named <code>askapache_pdf</code> is saved in your browser using the javascript below, with the value being set to which button you clicked.  Then when you request the pdf file the .htaccess code below uses mod_rewrite to read the value of the askapache_pdf cookie, and depending on which was your preference it will send alternate HTTP Headers that control how your browser handles the file.</p>


<h3>Unique HTTP Headers Returned</h3>
<p>When it comes down to it, the following information is the 3 modes.  Notice each one is different, because these headers are the only thing controlling how your browser handles the file.</p>
<h4>Save As Mode (askapache_pdf=s)</h4>
<pre>Content-Disposition: attachment
Content-Type: application/pdf</pre>
<h4>Inline Mode (askapache_pdf=i)</h4>
<pre>Content-Type: application/pdf</pre>
<h4>Download Mode (askapache_pdf=a)</h4>
<pre>Content-Type: application/octet-stream</pre>


<h3>Htaccess Demo File</h3>
<p>For the demo I created the folder /storage/pdf/ and this is the .htaccess file at /storage/pdf/.htaccess</p>
<p>The default Content-Type for .pdf files.  This will make .pdf files default Content-Type header have  the value 'application/pdf' - but the default can be overridden by using RewriteRule with the <code>[T=&#039;different/type&#039;]</code></p>
<pre>AddType application/pdf .pdf</pre>

<p>Turn on the rewrite engine if its already on you dont need this </p>
<pre>RewriteEngine On</pre>

<p>Skip RewriteRules if not .pdf request, like autoindexing. The next [2] RewriteRule directives are specific for .pdf files so if the filename requested does not end in .pdf then the <code>[S=2]</code> instructs the next 2 RewriteRule  directives to be completely skipped.</p>
<pre>RewriteRule !.*\.pdf$ - [S=2]</pre>


<p>The first RewriteCond checks to see if the askapache_pdf cookie is NOT set.  The second RewriteCond checks to see if the askapche_pdf cookie has the value of s, which is the value corresponding to someone clicking the "Save As" button.</p>
<p>The <code>[NC,OR]</code> flag means that if the cookie askapache_pdf does not exist, OR (next cond) if the askapache_pdf cookie does exist and is set to 's' then process the RewriteRule.  If neither cond is true the rewriterule is skipped.</p>
<p>If one of the RewriteCond is true, then the RewriteRule is processed.   The RewriteRule applies to any/all requests (.*) but doesn't rewrite anything (-) This RewriteRule sets an Apache environment variable ASKAPACHE_PDFS to have the value of 1 if either rewritecond is true.  The variable can be checked by any directives following the rewriterule in the whole htaccess file.  The ASKAPACHE_PDFS ends in S because if this variable exists then it means the users preference is 'Save As'</p>
<p>Notice that if the user requested the pdf file without selecting a preference i.e. no cookie exists, then the ASKAPACHE_PDFS variable is still set. This just lets us pick the default preference for them, in this example the default is 'Save As'</p>
<pre>RewriteCond %{HTTP_COOKIE} !^.*askapache_pdf.*$ [NC,OR]
RewriteCond %{HTTP_COOKIE} ^.*askapache_pdf=s.*$ [NC]
RewriteRule .* - [E=ASKAPACHE_PDFS:1]</pre>

<p>The RewriteCond checks the askapache_pdf cookie for the value 'a' which 'a' represents 'Download'</p>
<p>If the cookies value is 'a' then the RewriteRule overrides the default Content-Type from 'application/pdf' set with AddType earlier, to 'application/octet-stream', which is a special content-type that tells the browser that the file cannot be loaded by the browser 'Inline', but must be saved which will be opened by an external viewer depending on browser configuration and plugins.</p>
<pre>RewriteCond %{HTTP_COOKIE} ^.*askapache_pdf=a.*$
RewriteRule .* - [T=application/octet-stream]</pre>

<p>This is superfly.  If the cookie/users-preference was 'Save As' (s) then the RewriteRule above the last one set the environment variable ASKAPACHE_PDFS to have the value 1.  The Header directive here is ONLY processed in that variable ASKAPACHE_PDFS exists.  That is what the end 'env=ASKAPACHE_PDFS' does, it is the condition that must be met or the Header directive is skipped.  If the ASKAPACHE_PDFS environment variable set by RewriteRule does exist then the header directive adds the header '<code>Content-Disposition: attachment</code>' to  the normal Response Headers.  The 'Content-Disposition: attachment' header instructs your browser to present you with the 'Save As' dialog box allowing you to choose whether you want to save or open.</p>
<pre>Header set Content-Disposition "attachment" env=ASKAPACHE_PDFS</pre>






<h2>Javascript used by Demo</h2>
<p>The best place for javascript is quirksmode, here is a definitive article on setting, reading, parsing, etc.. <a title="I am a javascript cookie monster" href="http://www.quirksmode.org/js/cookies.html">COOKIES</a>.</p>
<p>Note, I now prefer using jQuery over my AAJS javascript library.  Also, the whole using cookies aspect is just to highlight some advanced htaccess, you can accomplish this much easier without javascript or cookies.</p>
<pre>if(!gi(&#039;pdfr&#039;))return;
var pdfr=gi(&#039;pdfr&#039;);
var cval=getCookie(&#039;askapache_pdf&#039;);
&nbsp;
if(cval==&#039;i&#039;){pdfr.innerHTML=&#039;Currently set to "Inline".&#039;;}
else if(cval==&#039;a&#039;){pdfr.innerHTML=&#039;Currently set to "Download" mode.&#039;;}
else if(cval==&#039;s&#039;){pdfr.innerHTML=&#039;Currently set to "Save As" mode.&#039;;}
&nbsp;
addMyEvent(gi(&#039;pdfi&#039;),"mousedown",function(){
  setCookie("askapache_pdf", "i", "", "/", "www.askapache.com"); gi(&#039;pdfr&#039;).innerHTML = &#039;Changed mode to "Inline".&#039;; return false; });
addMyEvent(gi(&#039;pdfa&#039;),"mousedown",function(){
  setCookie("askapache_pdf", "a", "", "/", "www.askapache.com"); gi(&#039;pdfr&#039;).innerHTML = &#039;Changed mode to "Download".&#039;; return false; });
addMyEvent(gi(&#039;pdfs&#039;),"mousedown",function(){
  setCookie("askapache_pdf", "s", "", "/", "www.askapache.com"); gi(&#039;pdfr&#039;).innerHTML = &#039;Changed mode to "Save As".&#039;; return false; });</pre>

<h2>Alternative Method - No Cookies + PHP</h2>
<p>This is what I came up with first for my client, and then while programming the php I noticed.. Hey!  I think I can do the same thing using .htaccess, which would save me on cpu/memory/potential security/etc.. but this works great too.  Though you will need to hack the code to get it working probably..</p>
<p>Note that the .htaccess rewrite code I used here used FILENAME-i.pdf or FILENAME-s.pdf to pass the preference to the pdf-dl.php script, it also worked for FILENAME.pdf?i=i</p>

<h3>pdf-dl.php</h3>
<pre>&lt;?php
if (
  !isset($_GET[&#039;file&#039;])
  || ($f=$_GET[&#039;file&#039;])===false
  || ($fp=@fopen($f,"rb"))===false
  || ($fi=pathinfo($f))===false
  || ($fi[&#039;fsize&#039;]=filesize($f))===false
  || strtolower($fi["extension"])!=&#039;pdf&#039;
) die(&#039;Failed&#039;);
&nbsp;
ob_start();
header(&#039;Accept-Ranges: bytes&#039;);
header("Content-Length: {$fi[&#039;fsize&#039;]}");
header(&#039;Content-Type: application/pdf&#039;);
if(!isset($_GET[&#039;i&#039;])) header("Content-Disposition: attachment; filename=\"{$fi[&#039;basename&#039;]}\"");
&nbsp;
$sent = 0;
while ( !feof($fp) &amp;&amp; $sent &lt; $fi[&#039;fsize&#039;] &amp;&amp; ($buf = fread($fp, 8192)) != &#039;&#039; ){
  echo $buf;
  $sent += strlen($buf);
  flush();  ob_flush();
}
fclose($fp);
exit;
?&gt;</pre>


<h3>Alternate Method .htaccess</h3>
<p>Deny direct request to pdf-dl.php file</p>
<pre>RewriteCond %{THE_REQUEST} ^.*pdf-dl\.php.*$ [NC]
RewriteRule .* - [F]</pre>
<p>Handle PDF files named anything-i.pdf as inline</p>
<pre>RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^/]*)-i\.pdf$  /cgi-bin/pdf-dl.php?i=i&amp;file=%{DOCUMENT_ROOT}/storage/pdf/$1.pdf [L,NC,QSA,S=1]</pre>
<p>Handle PDF files without -i.pdf as attachments</p>
<pre>RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^/]*)\.pdf$  /cgi-bin/pdf-dl.php?file=%{DOCUMENT_ROOT}/storage/pdf/$1.pdf [L,NC,QSA]</pre>




<h2>More Info</h2>
<p>The following is more information about the Content-Dispositon header and related subjects for fast readers.</p>

<h3>Interesting Reading</h3>
<p>Here is the thread of the original draft proposal for the Content-Disposition header.</p>
<ul>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03620.html">Content-Disposition Header</a>, <em>Rens Troost - 22 Jun 1993</em>
<ul>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03629.html">Re: Content-Disposition Header</a>, <em>Nathaniel Borenstein</em>
<ul>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03630.html">Re: Content-Disposition Header</a>, <em>Gabe Beged-Dov</em>
<ul>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03631.html">Re: Content-Disposition Header</a>, <em>Rens Troost</em></li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03635.html">Re: Content-Disposition Header</a>, <em>Gabe Beged-Dov</em></li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03641.html">Content-Disposition Header and multipart/alternative</a>, <em>Rens Troost</em></li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03645.html">Re: Content-Disposition Header and multipart/alternative</a>, <em>Nathaniel Borenstein</em></li>
</ul>
</li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03632.html">Re: Content-Disposition Header</a>, <em>Keith Moore</em>
<ul>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03633.html">Re: Content-Disposition Header</a>, <em>Nathaniel Borenstein</em></li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03634.html">Re: Content-Disposition Header</a>, <em>Ed Levinson (Contractor)</em></li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03636.html">Re: Content-Disposition Header</a>, <em>Keith Moore</em></li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03640.html">Re: Content-Disposition Header</a>, <em>Rens Troost</em></li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03650.html">Re: Content-Disposition Header</a>, <em>Harald Tveit Alvestrand</em></li>
</ul>
</li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03621.html">Re: Content-Disposition Header</a>, <em>Steve Dorner</em>
<ul>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03622.html">Re: Content-Disposition Header</a>, <em>Rens Troost</em>
<ul>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03624.html">Re: Content-Disposition Header</a>, <em>Keith Moore</em></li>
</ul>
</li>
</ul>
</li>
<li><a href="http://www.imc.org/ietf-822/old-archive1/msg03652.html">Re: Content-Disposition Header</a>, <em>Carlyn M. Lowery</em></li>
</ul>
</li>
</ul>
</li>
</ul>



<h3>Intense Reading</h3>
<ul>
<li><a href="http://www2.roguewave.com/support/docs/leif/sourcepro/html/protocolsug/10-1.html">Using the MIME Headers Effectively</a></li>
<li><a href="http://www.iana.org/assignments/mail-cont-disp">Mail Content Disposition Values and Parameters</a></li>
<li><cite><a href="http://rfc.askapache.com/rfc1766/rfc1766.txt">Tags for the Identification of Languages</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1436/rfc1436.txt">The Internet Gopher Protocol (a distributed document search and retrieval protocol)</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1630/rfc1630.txt">Universal Resource Identifiers in WWW</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1738/rfc1738.txt">Uniform Resource Locators (URL)</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1866/rfc1866.txt">Hypertext Markup Language - 2.0</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1945/rfc1945.txt">Hypertext Transfer Protocol -- HTTP/1.0</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2045/rfc2045.txt">Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1123/rfc1123.txt">Requirements for Internet Hosts -- Communication Layers</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc822/rfc822.txt">Standard for The Format of ARPA Internet Text Messages</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1808/rfc1808.txt">Relative Uniform Resource Locators</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1036/rfc1036.txt">Standard for Interchange of USENET Messages</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc977/rfc977.txt">Network News Transfer Protocol</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2047/rfc2047.txt">MIME (Multipurpose Internet Mail Extensions) Part Three: Message Header Extensions for Non-ASCII Text</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1867/rfc1867.txt">Form-based File Upload in HTML</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc821/rfc821.txt">Simple Mail Transfer Protocol</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1590/rfc1590.txt">Media Type Registration Procedure</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc959/rfc959.txt">File Transfer Protocol</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1700/rfc1700.txt">Assigned Numbers</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1737/rfc1737.txt">Functional Requirements for Uniform Resource Names</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1864/rfc1864.txt">The Content-MD5 Header Field</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1900/rfc1900.txt">Renumbering Needs Work</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1952/rfc1952.txt">GZIP file format specification version 4.3</a></cite></li>
<li><cite>Improving HTTP Latency</cite></li>
<li><cite><a href="http://www.isi.edu/touch/pubs/http-perf96/">Analysis of HTTP Performance</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1305/rfc1305.txt">Network Time Protocol (Version 3) Specification, Implementation and Analysis</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1951/rfc1951.txt">DEFLATE Compressed Data Format Specification version 1.3</a></cite></li>
<li><cite><a href="http://sunsite.unc.edu/mdma-release/http-prob.html">Analysis of HTTP Performance Problems,</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1950/rfc1950.txt">ZLIB Compressed Data Format Specification version 3.3</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2069/rfc2069.txt">An Extension to HTTP: Digest Access Authentication</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2068/rfc2068.txt">Hypertext Transfer Protocol -- HTTP/1.1</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2119/rfc2119.txt">Key words for use in RFCs to Indicate Requirement Levels</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc1806/rfc1806.txt">Communicating Presentation Information in Internet Messages: The Content-Disposition Header</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2145/rfc2145.txt">Use and Interpretation of HTTP Version Numbers</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2076/rfc2076.txt">Common Internet Message Headers</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2279/rfc2279.txt">UTF-8, a transformation format of Unicode and ISO-10646</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2046/rfc2046.txt">Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2277/rfc2277.txt">IETF Policy on Character Sets and Languages</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2396/rfc2396.txt">Uniform Resource Identifiers (URI): Generic Syntax and Semantics</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2617/rfc2617.txt">HTTP Authentication: Basic and Digest Access Authentication</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2110/rfc2110.txt">MIME E-mail Encapsulation of Aggregate Documents, such as HTML (MHTML)</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2026/rfc2026.txt">The Internet Standards Process -- Revision 3</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2324/rfc2324.txt">Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0)</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2049/rfc2049.txt">Multipurpose Internet Mail Extensions (MIME) Part Five: Conformance Criteria and Examples</a></cite></li>
<li><cite><a href="http://rfc.askapache.com/rfc2183/rfc2183.txt">Communicating Presentation Information in Internet Messages: The Content-Disposition Header Field</a></cite></li>
</ul><p><a href="http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html"></a><a href="http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html">3 Ways to Serve PDF Files using Htaccess Cookies, Headers, Rewrites</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Htaccess Rewrites &#8211; Rewrite Tricks and Tips</title>
		<link>http://www.askapache.com/htaccess/modrewrite-tips-tricks.html</link>
		<comments>http://www.askapache.com/htaccess/modrewrite-tips-tricks.html#comments</comments>
		<pubDate>Sun, 10 Apr 2011 14:05:00 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Htaccess]]></category>

		<guid isPermaLink="false">http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html</guid>
		<description><![CDATA[<p><strong>htaccess rewrite</strong> / Mod_Rewrite Tips and Tricks is as glamorous as it sounds!  htaccess rewrite mod_rewrite is just possibly one of the most useful Apache modules and features.  The ability to rewrite requests internally as well as externally is extremely powerful.</p>
<p><a class="hs hs13" href="http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html"></a></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/htaccess/modrewrite-tips-tricks.html"></a><a href="http://www.askapache.com/htaccess/modrewrite-tips-tricks.html"><cite>AskApache.com</cite></a></p><p><strong>Htaccess Rewrites</strong> are enabled by using the Apache module <a href="http://www.askapache.com/servers/mod_rewrite.c.html">mod_rewrite</a>, which is one of the most powerful Apache modules and features availale.  Htaccess Rewrites through mod_rewrite provide the special ability to <strong>Rewrite requests internally</strong> as well as <em>Redirect request externally</em>.<br class="C" /></p>
<p><a class="hs hs13" href="http://www.askapache.com/servers/mod_rewrite.c.html"></a></p>

<p>When the url in your browser's location bar stays the same for a request it is an internal rewrite, when the url changes an external redirection is taking place.  This is one of the first, and one of the biggest mental-blocks people have when learning about mod_rewrite...  But I have a secret weapon for you to use, a new discovery from years of research that makes learning mod_rewrite drastically quicker and easier.  It truly does or I wouldn't be saying so in the introduction of this article.</p>

<blockquote><p>Despite the tons of examples and docs, <strong>mod_rewrite is voodoo</strong>.
Damned cool voodoo, but still voodoo.<br />-- <cite>Brian Moore</cite></p></blockquote>

<p class="anote"><strong>Note:</strong>  After years of fighting to learn my way through rewriting urls with mod_rewrite, I finally had a breakthrough and found a way to outsmart the difficulty of mod_rewrite that I just couldn't seem to master.  The <a href="http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html">Mod_Rewrite RewriteCond/RewriteRule Variable Value Cheatsheet</a> is the one-of-a-kind tool that changed the game for me and made mod_rewriting no-harder than anything else.</p>

<p>So keep that mod_rewrite reference bookmarked and you will be able to figure out any RewriteRule or RewriteCond, an amazing feat considering it took me a LONG time to figure this stuff out on my own.  But that was before <a href="http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html">the craziness</a>, one of the most challenging and productive .htaccess experiments I've done... An experiment so <strong>ILL</strong> it's sick like a diamond disease on your wrist! $$$.  That mod_rewrite experiment/tutorial was the culmination of many different advanced mod_rewrite experiments I had done in the past and included most of my very best .htaccess tricks.  With the cheatsheet it's no longer Voodoo.. Its just what you do.  Now lets dig in!</p>


<!--
<h2>Htaccess rewrites TOC</h2>
        <ul>
            <li><a href="#default-mod-rewrite-hint" title=".htaccess mod rewrite should use Options +FollowSymLinks">.htaccess rewrite examples should begin with:</a></li>
            <li><a href="#require-the-www-in-htaccess" title="Use mod_rewrite in Apache htaccess to Require the www for SEO">Require the www</a></li>
            <li><a href="#require-no-www-in-htaccess" title="Use mod_rewrite in Apache htaccess to Require no www for SEO">Require no www</a></li>
            <li><a href="#check-for-key-in-query-string" title="Search for a key in the query string">Check for a key in QUERY_STRING</a></li>
            <li><a href="#delete-query-string" title="Remove the query string from url">Removes the QUERY_STRING from the URL</a></li>
            <li><a href="#fix-infinite-loop-redirects" title="Stop internal redirect looping">Fix for infinite loops</a></li>
            <li><a href="#external-redirect-php-files-to-html" title="Redirecting .php file extensions to .html">Redirect .php files to .html files (SEO friendly)</a></li>
            <li><a href="#internal-redirect-php-files-to-html" title="Redirecting .html file extensions to .php">Redirect .html files to actual .php files (SEO friendly)</a></li>
            <li><a href="#time-based-access" title="Deny access with Apache htaccess during certain hours of the day">block access to files during certain hours of the day</a></li>
            <li><a href="#convert-underscore-hyphen" title="Change underscores to hyphens for SEO URL">Rewrite underscores to hyphens for SEO URL</a></li>
            <li><a href="#require-www-no-hardcoding" title="mod_rewrite example of SEO 301 redirecting non-www to www">Require the www without hardcoding</a></li>
            <li><a href="#require-no-subdomain-1" title="mod_rewrite subdomain usage example of SEO 301 redirecting">Require no subdomain</a></li>
            <li><a href="#require-no-subdomain-2" title="Apache htaccess htaccess rewrite ~without slash">Require no subdomain</a></li>
            <li><a href="#redirect-wordpress-feed" title="Rewriting WordPress RSS feeds to Feedburner in SEO friendly method">Redirecting WordPress Feeds to Feedburner</a></li>
            <li><a href="#only-allow-get-and-put-requests" title="Deny Request Methods other than GET or PUT">Only allow GET and PUT request methods</a></li>
            <li><a href="#prevent-hotlinking" title="hotlinking and bandwidth stealing with mod_rewrite, hotlinking example">Prevent Files image/file hotlinking and bandwidth stealing</a></li>
            <li><a href="#stop-browser-prefetching" title="Fix prefetching in browsers">Stop browser prefetching</a></li>
        </ul>

<hr />
-->
<p>If you really want to take a look, check out the <a href="http://www.askapache.com/servers/mod_rewrite.c.html">mod_rewrite.c</a> and <a href="http://www.askapache.com/servers/mod_rewrite.h.html">mod_rewrite.h</a> files.</p>

<p>Be aware that mod_rewrite (<em>RewriteRule, RewriteBase, and RewriteCond</em>) code is executed for each and every HTTP request that accesses a file in or below the directory where the code resides, so it's always good to limit the code to certain circumstances if readily identifiable.</p>
<p><strong>For example</strong>, to limit the next 5 RewriteRules to only be applied to .html and .php files, you can use the following code, which tests if the url does not end in .html or .php and if it doesn't, it will skip the next 5 RewriteRules.</p><hr />
<pre>
RewriteRule !\.(html|php)$ - [S=5]
RewriteRule ^.*-(vf12|vf13|vf5|vf35|vf1|vf10|vf33|vf8).+$ - [S=1]
</pre>

<h2><a href="#default-mod-rewrite-hint" name="default-mod-rewrite-hint" id="default-mod-rewrite-hint" title="Mostly .htaccess rewrite examples should begin with:" class="acd">.htaccess rewrite examples should begin with:</a></h2>
<pre>
Options +FollowSymLinks
&nbsp;
RewriteEngine On
RewriteBase /
</pre>


<h2><a href="#require-the-www-in-htaccess" name="require-the-www-in-htaccess" id="require-the-www-in-htaccess" title="Require the www" class="acd">Require the www</a></h2>
<pre>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.askapache\.com$ [NC]
RewriteRule ^(.*)$ http://www.askapache.com/$1 [R=301,L]
</pre>


<h2>Loop Stopping Code</h2>
<p>Sometimes your rewrites cause infinite loops, stop it with one of these rewrite code snippets.</p>
<pre>
RewriteCond %{REQUEST_URI} ^/(stats/|missing\.html|failed_auth\.html|error/).* [NC]
RewriteRule .* - [L]
&nbsp;
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
</pre>

<h2>Cache-Friendly File Names</h2>
<p>This is probably my favorite, and I use it on every site I work on.  It allows me to update my javascript and css files in my visitors cache's simply by naming them differently in the html, on the server they stay the same name.  This rewrites all files for <code>/zap/j/anything-anynumber.js to /zap/j/anything.js and /zap/c/anything-anynumber.css to /zap/c/anything.css</code></p>
<pre>
RewriteRule ^zap/(j|c)/([a-z]+)-([0-9]+)\.(js|css)$ /zap/$1/$2.$4 [L]
</pre>




<h2>SEO friendly link for non-flash browsers</h2>
<p>When you use flash on your site and you properly supply a link to download flash that shows up for non-flash aware browsers, it is nice to use a shortcut to keep your code clean and your external links to a minimum.  This code allows me to link to <code>site.com/getflash/</code> for non-flash aware browsers.</p>
<pre>
RewriteRule ^getflash/?$ http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash [NC,L,R=307]
</pre>

<h2>Removing the Query_String</h2>
<p>On many sites, the page will be displayed for both page.html and page.html?anything=anything, which hurts your SEO with duplicate content.  An easy way to fix this issue is to redirect external requests containing a query string to the same uri without the query_string.</p>
<pre>
RewriteCond %{THE_REQUEST} ^GET\ /.*\;.*\ HTTP/
RewriteCond %{QUERY_STRING} !^$
RewriteRule .* http://www.askapache.com%{REQUEST_URI}? [R=301,L]
</pre>


<h2>Sending requests to a php script</h2>
<p>This .htaccess rewrite example invisibly rewrites requests for all Adobe pdf files to be handled by <code>/cgi-bin/pdf-script.php</code></p>
<pre>
RewriteRule ^(.+)\.pdf$  /cgi-bin/pdf-script.php?file=$1.pdf [L,NC,QSA]
</pre>


<h2>Setting the language variable based on Client</h2>
<p>For sites using multiviews or with multiple language capabilities, it is nice to be able to send the correct language automatically based on the clients preferred language.</p>
<pre>
RewriteCond %{HTTP:Accept-Language} ^.*(de|es|fr|it|ja|ru|en).*$ [NC]
RewriteRule ^(.*)$ - [env=prefer-language:%1]
</pre>



<h2>Deny Access To Everyone Except PHP fopen</h2>
<p>This allows access to all files by php fopen, but denies anyone else.</p>
<pre>
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^.+$ [NC]
RewriteRule .* - [F,L]
</pre>


<p class="cnote">If you are looking for ways to block or deny specific requests/visitors, then you should definately read <a href="http://perishablepress.com/press/2009/02/03/eight-ways-to-blacklist-with-apaches-mod_rewrite/" title="Eight Ways to Blacklist with Apache’s mod_rewrite">Blacklist with mod_rewrite</a>.  I give it a 10/10</p>


<h2>Deny access to anything in a subfolder except php fopen</h2>
<p>This can be very handy if you want to serve media files or special downloads but only through a php proxy script.</p>
<pre>
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+)/.*\ HTTP [NC]
RewriteRule .* - [F,L]
</pre>





<h2><a href="#require-no-www-in-htaccess" name="require-no-www-in-htaccess" id="require-no-www-in-htaccess" title="Require no www" class="acd">Require no www</a></h2>
<pre>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^askapache\.com$ [NC]
RewriteRule ^(.*)$ http://askapache.com/$1 [R=301,L]
</pre>


<h2><a href="#check-for-key-in-query-string" name="check-for-key-in-query-string" id="check-for-key-in-query-string" title="Search for a key in the query string" class="acd">Check for a key in QUERY_STRING</a></h2>
<p>Uses a <a href="http://askapache.info/trunk/mod/mod_rewrite.html#rewritecond" title="RewriteCond Directive Use in htaccess">RewriteCond</a> Directive to check QUERY_STRING for passkey, if it doesn't find it it redirects all requests for anything in the /logged-in/ directory to the /login.php script.</p>
<pre>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} !passkey
RewriteRule ^/logged-in/(.*)$ /login.php [L]
</pre>


<h2><a href="#delete-query-string" name="delete-query-string" id="delete-query-string" title="Remove the query string from url" class="acd">Removes the QUERY_STRING from the URL</a></h2>
<p>If the QUERY_STRING has any value at all besides blank than the<code>?</code>at the end of /login.php? tells mod_rewrite to remove the QUERY_STRING from login.php and redirect.</p>
<pre>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} .
RewriteRule ^login.php /login.php? [L]
</pre>


<h2><a href="#fix-infinite-loop-redirects" name="fix-infinite-loop-redirects" id="fix-infinite-loop-redirects" title="Fix for infinite loops" class="acd">Fix for infinite loops</a></h2>
<p>An error message related to this is<code>Request exceeded the limit of 10 internal redirects due to probable configuration error. Use &#039;LimitInternalRecursion&#039; to increase the limit if necessary. Use &#039;LogLevel debug&#039; to get a backtrace.</code>or you may see<code>Request exceeded the limit</code>,<code>probable configuration error</code>,<code>Use &#039;LogLevel debug&#039; to get a backtrace</code>, or<code>Use &#039;LimitInternalRecursion&#039; to increase the limit if necessary</code></p>
<pre>
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
</pre>


<h2><a href="#external-redirect-php-files-to-html" name="external-redirect-php-files-to-html" id="external-redirect-php-files-to-html" title="External Redirect .php files to .html files (SEO friendly)" class="acd">External Redirect .php files to .html files (SEO friendly)</a></h2>
<pre>
RewriteRule ^(.*)\.php$ /$1.html [R=301,L]
</pre>


<h2><a href="#internal-redirect-php-files-to-html" name="internal-redirect-php-files-to-html" id="internal-redirect-php-files-to-html" title="Internal Redirect .php files to .html files (SEO friendly)" class="acd">Internal Redirect .php files to .html files (SEO friendly)</a></h2>
<p>Redirects all files that end in .html to be served from filename.php  so it looks like all your pages are .html but really they are .php</p>
<pre>
RewriteRule ^(.*)\.html$ $1.php [R=301,L]
</pre>


<h2><a href="#time-based-access" name="time-based-access" id="time-based-access" title="block access to files during certain hours of the day" class="acd">block access to files during certain hours of the day</a></h2>
<pre>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# If the hour is 16 (4 PM) Then deny all access
RewriteCond %{TIME_HOUR} ^16$
RewriteRule ^.*$ - [F,L]
</pre>


<h2><a href="#convert-underscore-hyphen" name="convert-underscore-hyphen" id="convert-underscore-hyphen" title="Change underscores to hyphens for SEO URL" class="acd">Rewrite underscores to hyphens for SEO URL</a></h2>
<p>Converts all underscores "_" in urls to hyphens "-" for SEO benefits...  See the <a href="http://www.askapache.com/htaccess/rewrite-underscores-to-hyphens-for-seo-url.html">full article</a> for more info.</p>
<pre>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
&nbsp;
RewriteRule !\.(html|php)$ - [S=4]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5 [E=uscor:Yes]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4 [E=uscor:Yes]
RewriteRule ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3 [E=uscor:Yes]
RewriteRule ^([^_]*)_(.*)$ $1-$2 [E=uscor:Yes]
&nbsp;
RewriteCond %{ENV:uscor} ^Yes$
RewriteRule (.*) http://d.com/$1 [R=301,L]
</pre>


<h2><a href="#require-www-no-hardcoding" name="require-www-no-hardcoding" id="require-www-no-hardcoding" title="Require the www without hardcoding" class="acd">Require the www without hardcoding</a></h2>
<pre>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.[a-z-]+\.[a-z]{2,6} [NC]
RewriteCond %{HTTP_HOST} ([a-z-]+\.[a-z]{2,6})$     [NC]
RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]
</pre>


<h2><a href="#require-no-subdomain-1" name="require-no-subdomain-1" id="require-no-subdomain-1" title="Require no subdomain" class="acd">Require no subdomain</a></h2>
<pre>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} \.([a-z-]+\.[a-z]{2,6})$ [NC]
RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]
</pre>


<h2><a href="#require-no-subdomain-2" name="require-no-subdomain-2" id="require-no-subdomain-2" title="Require no subdomain" class="acd">Require no subdomain</a></h2>
<pre>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} \.([^\.]+\.[^\.0-9]+)$
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
</pre>


<h2><a href="#redirect-wordpress-feed" name="redirect-wordpress-feed" id="redirect-wordpress-feed" title="Redirecting WordPress Feeds to Feedburner" class="acd">Redirecting WordPress Feeds to Feedburner</a></h2>
<p>Full article:<a href="http://www.askapache.com/htaccess/redirecting-wordpress-feeds-to-feedburner.html" title="Redirecting WordPress Feeds to Feedburner">Redirecting WordPress Feeds to Feedburner</a></p>
<pre>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/feed\.gif$
RewriteRule .* - [L]
&nbsp;
RewriteCond %{HTTP_USER_AGENT} !^.*(FeedBurner|FeedValidator) [NC]
RewriteRule ^feed/?.*$ http://feeds.feedburner.com/apache/htaccess [L,R=302]
&nbsp;
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</pre>


<h2><a href="#only-allow-get-and-put-requests" name="only-allow-get-and-put-requests" id="only-allow-get-and-put-requests" title="Only allow GET and PUT request methods" class="acd">Only allow GET and PUT Request Methods</a></h2>
<p>Article: <a class="acd" href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#http-methods-recognized" title="List of Apache Recognized Request Methods">Request Methods</a></p>
<pre>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} !^(GET|PUT)
RewriteRule .* - [F]
</pre>


<h2><a href="#prevent-hotlinking" name="prevent-hotlinking" id="prevent-hotlinking" title="Prevent Files image/file hotlinking and bandwidth stealing" class="acd">Prevent Files image/file hotlinking and bandwidth stealing</a></h2>
<pre>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?askapache.com/.*$ [NC]
RewriteRule \.(gif|jpg|swf|flv|png)$ /feed/ [R=302,L]
</pre>


<h2><a href="#stop-browser-prefetching" name="stop-browser-prefetching" id="stop-browser-prefetching" title="Stop browser prefetching" class="acd">Stop browser prefetching</a></h2>
<pre>
RewriteEngine On
SetEnvIfNoCase X-Forwarded-For .+ proxy=yes
SetEnvIfNoCase X-moz prefetch no_access=yes
&nbsp;
# block pre-fetch requests with X-moz headers
RewriteCond %{ENV:no_access} yes
RewriteRule .* - [F,L]
</pre>



<blockquote cite="http://askapache.info/trunk/mod/mod_rewrite.html#rewritebase">
<p>This module uses a rule-based rewriting engine (based on a regular-expression parser) to rewrite requested URLs on the fly. It supports an unlimited number of rules and an unlimited number of attached rule conditions for each rule, to provide a really flexible and powerful URL manipulation mechanism. The URL manipulations can depend on various tests, of server variables, environment variables, HTTP headers, or time stamps. Even external database lookups in various formats can be used to achieve highly granular URL matching.</p>
<p>This module operates on the full URLs (including the path-info part) both in per-server context (<code>httpd.conf</code>) and per-directory context (<code>.htaccess</code>) and can generate query-string parts on result. The rewritten result can lead to internal sub-processing, external request redirection or even to an internal proxy throughput.</p>
<p>Further details, discussion, and examples, are provided in the <a href="http://askapache.info/trunk/rewrite/index.html">detailed mod_rewrite documentation</a>.</p>
</blockquote>
<h2>Directives</h2>
<ul>
    <li><a href="http://askapache.info/trunk/mod/mod_rewrite.html#rewritebase">RewriteBase</a></li>
    <li><a href="http://askapache.info/trunk/mod/mod_rewrite.html#rewritecond">RewriteCond</a></li>
    <li><a href="http://askapache.info/2.2/mod/mod_rewrite.html#rewriteengine">RewriteEngine</a></li>
    <li><a href="http://askapache.info/trunk/mod/mod_rewrite.html#rewritelock">RewriteLock</a></li>
    <li><a href="http://askapache.info/2.0/mod/mod_rewrite.html#rewritelog">RewriteLog</a></li>
    <li><a href="http://askapache.info/trunk/mod/mod_rewrite.html#rewriteloglevel">RewriteLogLevel</a></li>
    <li><a href="http://askapache.info/trunk/mod/mod_rewrite.html#rewritemap">RewriteMap</a></li>
    <li><a href="http://askapache.info/1.3/mod/mod_rewrite.html#rewriteoptions">RewriteOptions</a></li>
    <li><a href="http://askapache.info/trunk/mod/mod_rewrite.html#rewriterule">RewriteRule</a></li>
</ul>



<p>If you aren't already comfortable using mod_rewrite then I recommend this <a href="http://check-these.info/mod_rewrite-basic.html">excellent mod_rewrite guide</a> by one of my favorite mod_rewrite gurus that I've met.</p>



<hr />
<h2>htaccess Guide Sections</h2>
<ul class="ou">
    <li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/htaccess-for-webmasters.html" title="Apache HTTP Web Server htaccess tips and tricks">htaccess tricks for Webmasters</a></li>
    <li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/using-http-headers-with-htaccess.html" title="Creating and using HTTP Headers with htaccess">HTTP Header control with htaccess</a></li>
    <li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/php-htaccess-tips-and-tricks.html" title="mod_php or php as a cgi with htaccess tips, htaccess php tricks">PHP on Apache tips and tricks</a></li>
    <li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/seo-search-engine-friendly-redirects-without-mod_rewrite.html" title="SEO-Friendly 301 Redirects without mod_rewrite">SEO Redirects without mod_rewrite</a></li>
    <li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html" title="mod_rewrite tips and tricks with RewriteEngine, RewriteBase, RewriteRule, and RewriteCond">mod_rewrite examples, tips, and tricks</a></li>
    <li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/speed-up-your-site-with-caching-and-cache-control.html" title="Caching, cache-control, cache, expires, and optimizing htaccess">HTTP Caching and Site Speedups</a></li>
    <li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/apache-authentication-in-htaccess.html" title="htaccess and Apache authentication with htpasswd, 401, and 403">Authentication on Apache</a></li>
    <li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/security-with-htaccess.html" title="Security, hacking, and anti-hacking tips and tricks for htaccess">htaccess Security Tricks and Tips</a></li>
    <li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/ssl-example-usage-in-htaccess.html" title="Apache SSL examples">SSL tips and examples</a></li>
    <li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/apache-variable-fun-in-htaccess.html" title="Apache variables info, tricks, and tips">Variable Fun (mod_env) Section</a></li><li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/mod_security-htaccess-tricks.html" title="mod_security Guide and sample mod_Security diretive usage in .htaccess">.htaccess Security with MOD_SECURITY</a></li><li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/setenvif.html" title="SetEnvIf and SetEnvIfNoCase Examples for conditionally setting variables in Apache .htaccess">SetEnvIf and SetEnvIfNoCase Examples</a></li>
</ul>


<p class="ment"><a rel="prev" href="http://www.askapache.com/htaccess/seo-search-engine-friendly-redirects-without-mod_rewrite.html" title="Use htaccess to create SEO-Friendly 301 Redirects without mod_rewrite">&laquo;  Search Engine Friendly Redirects</a> | <a href="http://www.askapache.com/htaccess/htaccess.html" class="acd1" rel="Contents Index Start" title=".htaccess tutorial">.htaccess Tutorial Index</a> | <a rel="next" href="http://www.askapache.com/htaccess/speed-up-your-site-with-caching-and-cache-control.html" title="The Apache method for speeding up sites with Caching, cache-control, cache, expires, and optimizing htaccess">&raquo;  Speed up your site with Caching and cache-control</a></p><p><a href="http://www.askapache.com/htaccess/modrewrite-tips-tricks.html"></a><a href="http://www.askapache.com/htaccess/modrewrite-tips-tricks.html">Htaccess Rewrites &#8211; Rewrite Tricks and Tips</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/modrewrite-tips-tricks.html/feed</wfw:commentRss>
		<slash:comments>130</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>Advanced WordPress wp-config.php Tweaks</title>
		<link>http://www.askapache.com/wordpress/advanced-wp-config-php-tweaks.html</link>
		<comments>http://www.askapache.com/wordpress/advanced-wp-config-php-tweaks.html#comments</comments>
		<pubDate>Wed, 03 Mar 2010 08:23:37 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=3341</guid>
		<description><![CDATA[<p>The bottom line for this article is that I want to make WordPress as fast, secure, and easy to install, run, and manage because I am using it more and more for client production sites, I will work for days in order to solve an issue so that I never have to spend time on that issue again. Time is money in this industry and that is ultimately (time) what there is to gain by tweaking WordPress.</p>

<p class="cnote"><strong>Note:</strong> I spent no time on readability, this is primarily a read the code and figure it out article.. This is for advanced users looking for a reference or discussion and for those of you looking to advance.  Feedback would be great <em>if you make it that far..</em></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/wordpress/advanced-wp-config-php-tweaks.html"></a><a href="http://www.askapache.com/wordpress/advanced-wp-config-php-tweaks.html"><cite>AskApache.com</cite></a></p><p>The bottom line for this article is that I want to make WordPress as fast, secure, and easy to install, run, and manage because I am using it more and more for client production sites, I will work for days in order to solve an issue so that I never have to spend time on that issue again. Time is money in this industry and that is ultimately (time) what there is to gain by tweaking WordPress.</p>
<p class="cnote"><strong>Note:</strong> I spent no time on readability, this is primarily a read the code and figure it out article.. This is for advanced users looking for a reference or discussion and for those of you looking to advance.  Feedback would be great <em>if you make it that far..</em></p>
<p>For a better handle on the way I like to structure web site directories, see <a href="http://www.askapache.com/htaccess/optimize-website-files-cache-security.html">Optimize a Website for Speed, Security, and Easy Management</a> but note it is a bit outdated compared to what I'm doing now.  I don't have the luxury of using only one type of server, or hosting provider anymore, so I have been working towards making things even more portable in order to move from host to host from server to server without issues i.e. my portable <a href="http://www.askapache.com/linux/bash_profile-functions-advanced-shell.html">.bash_profile</a>.</p>
<p>So I've been basically experimenting various ways to accomplish that and thought I would share what I am currently doing for my benefit and hopefully get some input.  All of my WP installs run the development version, and one main idea with my setups is that upgrading is automated.  So I really keep the WordPress install clean and use plugins and wp-config.php to do all the customization.</p>
<ul>
    <li>Portability - Hands-free upgrades and easy to move</li>
    <li>Security - Additional security and protection</li>
    <li>Speed - Less CPU and Disk I/O</li>
    <li>Customization - All my favorite customizations</li>
</ul>
<h2>wp-config.php</h2>
<p>These are the main settings I use.. Seriously this is more like an interactive article, because to understand it you will need to do some code grepping.  You may want to grab a jolt.</p>
<h3>ASKAPACHE_ROOT</h3>
<p>The ASKAPACHE_ROOT variable is just a better way for me to be able to include and access all the different files in my site tree.  For instance, in my non-wp php files, I can do this:</p>
<pre>!defined(&#039;ASKAPACHE_ROOT&#039;) &amp;&amp; require $_SERVER[&#039;DOCUMENT_ROOT&#039;] . &#039;/wp-config.php&#039;;
include(ASKAPACHE_ROOT . &#039;/includes/custom-download.inc.php&#039;);</pre>
<h3>ASKAPACHE_LOCK</h3>
<p>This is one of my all-time favorite hacks, that I think is one of the most useful methods I employ as a web developer.  This allows me to use far-future-expire headers for optimum caching, while still forcing browsers to re-validate every day or so automatically, or forcing them to re-validate whenever I change the suffix.  This takes advantage of the <a href="http://www.askapache.com/htaccess/mod_rewrite-fix-for-caching-updated-files.html">mod_rewrite trick</a> that I use on EVERY site I run, definately worth learning. Because I practice best-practice web-standards, for every web site I create a single css file and javascript file, which I then add to the template like:</p>
<pre>&lt;link rel="stylesheet" type="text/css" media="all" href="http://static.askapache.com/c/apache-0&lt;?php echo ASKAPACHE_LOCK?&gt;.css" /&gt;
&lt;script src="http://static.askapache.com/j/apache-0&lt;?php echo ASKAPACHE_LOCK;?&gt;.js" type="text/javascript"&gt;&lt;/script&gt;</pre>
<pre>&lt;?php
/**
 * The base configurations of the WordPress.
 *
 * This file has the following configurations: MySQL settings, Table Prefix,
 * Secret Keys, WordPress Language, and ABSPATH. You can find more information by
 * visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing
 * wp-config.php} Codex page. You can get the MySQL settings from your web host.
 *
 * This file is used by the wp-config.php creation script during the
 * installation. You don&#039;t have to use the web site, you can just copy this file
 * to "wp-config.php" and fill in the values.
 *
 * @package WordPress
 */
/* http://codex.wordpress.org/Editing_wp-config.php */
&nbsp;
/** /home/liet/askapache.com */
!defined(&#039;ASKAPACHE_ROOT&#039;) &amp;&amp; define(&#039;ASKAPACHE_ROOT&#039;, str_replace(&#039;/public_html&#039;,&#039;&#039;, $_SERVER[&#039;DOCUMENT_ROOT&#039;]));
&nbsp;
/** The 008 at the end is for manual tweaking.  time() returns seconds since &#039;00:00:00 1970-01-01 UTC&#039;. */
// http://www.askapache.com/htaccess/mod_rewrite-fix-for-caching-updated-files.html
!defined(&#039;ASKAPACHE_LOCK&#039;) &amp;&amp; define(ASKAPACHE_LOCK&#039;, substr(time(),0,5).&#039;008&#039;); // 12533001
&nbsp;
/** absolute path to the WordPress directory */
!defined(&#039;ABSPATH&#039;) &amp;&amp; define(&#039;ABSPATH&#039;, ASKAPACHE_ROOT .&#039;/public_html/&#039;);
&nbsp;
/**
 * WP_SITEURL, defined since WordPress Version 2.2, allows the WordPress address (URL) to be defined. The valued defined is the address where your WordPress core files reside.
 * It should include the http:// part too. Do not put a slash "/" at the end.
 * Setting this value in wp-config.php overrides the wp_options table value for siteurl and disables the WordPress address (URL) field in the Administration &gt; Settings &gt; General panel.
 */
!defined(&#039;WP_SITEURL&#039;) &amp;&amp; define(&#039;WP_SITEURL&#039;, &#039;http://&#039;.$_SERVER[&#039;SERVER_NAME&#039;]);
&nbsp;
/**
 * WP_HOME is another wp-config.php option added in WordPress Version 2.2. Similar to WP_SITEURL,
 * WP_HOME overrides the wp_options table value for home but does not change it permanently.
 * home is the address you want people to type in their browser to reach your WordPress blog. It should include the http:// part. Also, do not put a slash "/" at the end.
 */
!defined(&#039;WP_HOME&#039;) &amp;&amp; define(&#039;WP_HOME&#039;, WP_SITEURL);
&nbsp;
/** no trailing slash, full paths only */
!defined(&#039;WP_CONTENT_DIR&#039;) &amp;&amp; define( &#039;WP_CONTENT_DIR&#039;, ABSPATH . &#039;wp-content&#039; );
&nbsp;
// full url - WP_CONTENT_DIR is defined further up
!defined(&#039;WP_CONTENT_URL&#039;) &amp;&amp; define( &#039;WP_CONTENT_URL&#039;, WP_SITEURL . &#039;/wp-content&#039;);
&nbsp;
/** Allows for the plugins directory to be moved from the default location. @since 2.6.0 */
// full path, no trailing slash
!defined(&#039;WP_PLUGIN_DIR&#039;) &amp;&amp; define( &#039;WP_PLUGIN_DIR&#039;, WP_CONTENT_DIR . &#039;/plugins&#039; );
&nbsp;
/** Allows for the plugins directory to be moved from the default location. @since 2.6.0 */
// full url, no trailing slash
!defined(&#039;WP_PLUGIN_URL&#039;) &amp;&amp; define( &#039;WP_PLUGIN_URL&#039;, WP_CONTENT_URL . &#039;/plugins&#039; );
&nbsp;
/** Allows for the plugins directory to be moved from the default location. @since 2.1.0 */
// Relative to ABSPATH.  For back compat.
//!defined(&#039;PLUGINDIR&#039;) &amp;&amp; define( &#039;PLUGINDIR&#039;, &#039;wp-content/plugins&#039; );
&nbsp;
/** Number of autosaves to save. TRUE is default and enables post revisions, FALSE disables revisions completely. */
!defined(&#039;WP_POST_REVISIONS&#039;) &amp;&amp; define(&#039;WP_POST_REVISIONS&#039;, 150);
&nbsp;
/* ini_set(&#039;memory_limit&#039;, WP_MEMORY_LIMIT); */
!defined(&#039;WP_MEMORY_LIMIT&#039;) &amp;&amp; define(&#039;WP_MEMORY_LIMIT&#039;, &#039;64M&#039;);
&nbsp;
/** Only check at this interval for new messages. Default is 5min */
/** @since 2.9  */
!defined(&#039;WP_MAIL_INTERVAL&#039;) &amp;&amp; define(&#039;WP_MAIL_INTERVAL&#039;, 3600); // 1 hour
&nbsp;
/** Saves updated post values to post from edit window every x seconds. (default 60)
 * When editing a post, WordPress uses Ajax to auto-save revisions to the post as you edit. You may want to increase this setting for longer delays in between auto-saves, or decrease the setting to make sure you never lose changes.
 * @since 2.5.0 */
!defined( &#039;AUTOSAVE_INTERVAL&#039; ) &amp;&amp; define( &#039;AUTOSAVE_INTERVAL&#039;, 60 );
&nbsp;
/** @since 2.9.0  */
/** Permanently deletes posts, pages, attachments, and comments which have been in the trash for EMPTY_TRASH_DAYS. */
!defined( &#039;EMPTY_TRASH_DAYS&#039; ) &amp;&amp; define( &#039;EMPTY_TRASH_DAYS&#039;, 300 );</pre>
<hr class="C" />
<h2>Debugging WordPress</h2>
<p>One of my secrets for getting really good at this stuff is to master debugging.  There is really not ever a time when I am working on a site that I don't have <a href="http://www.askapache.com/security/elite-log-file-scrolling-with-color-syntax.html">color-highlighted logs scrolling automatically in an ssh window</a>.  It's really almost impossible to fix problems with wordpress or do any kind of advanced anything without being able to view debugging info.  At first I relied heavily on a <a href="http://www.askapache.com/php/custom-phpini-tips-and-tricks.html">custom php.ini</a> being available on the server, but after having to deal with many hosts who don't allow <code>php.ini</code> files I now rely completely on setting values using <a href="http://php.net/manual/en/function.ini-set.php">ini_set</a> for ultimate portability. Detailed towards the end of this article and is also included in this <code>wp-config.php</code></p>
<pre>/**#@+
 * DEBUGGING STUFF
 */
/** display of notices during development. if false, error_reporting is E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR otherwise E_ALL */
!defined(&#039;WP_DEBUG&#039;) &amp;&amp; define(&#039;WP_DEBUG&#039;, false);
&nbsp;
/** The SAVEQUERIES definition saves the database queries to a array and that array can be displayed to help analyze those queries.
 *  The information saves each query, what function called it, and how long that query took to execute.  */
!defined(&#039;SAVE_QUERIES&#039;) &amp;&amp; define(&#039;SAVE_QUERIES&#039;, WP_DEBUG);
&nbsp;
!defined(&#039;ACTION_DEBUG&#039;) &amp;&amp; define(&#039;ACTION_DEBUG&#039;, WP_DEBUG);
&nbsp;
/** This will allow you to edit the scriptname.dev.js files in the wp-includes/js and wp-admin/js directories.  */
!defined(&#039;SCRIPT_DEBUG&#039;) &amp;&amp; define(&#039;SCRIPT_DEBUG&#039;, WP_DEBUG);
&nbsp;
/** Add define(&#039;WP_DEBUG_LOG&#039;, true); to enable php debug logging to WP_CONTENT_DIR/debug.log */
//!defined(&#039;WP_DEBUG_LOG&#039;) &amp;&amp; define(&#039;WP_DEBUG_LOG&#039;, true);
&nbsp;
/** This determines whether errors should be printed to the screen as part of the output or if they should be hidden from the user.
 *  Add define(&#039;WP_DEBUG_DISPLAY&#039;, false); to wp-config.php to use the globally configured setting for display_errors and not force it to On */
!defined(&#039;WP_DEBUG_DISPLAY&#039;) &amp;&amp; define(&#039;WP_DEBUG_DISPLAY&#039;, false);</pre>
<hr class="C" />
<h2>Ultimate Security Tweaks</h2>
<p>Well, ultimate for WP's built-in keys and password functions, this is all for wp-config.php keep in mind.  This is a very neccessary and recommended step, and is one of the only things I modify for each new installation.</p>
<h3>Security KEYS</h3>
<p>If like me you are familiar with password-cracking software like John the ripper, rainbow hash tables, l0pht-crack, etc.. then you will like to know that you can specify your own keys and salts for the encryption used by WP.  They are <code>AUTH_KEY</code>, <code>AUTH_SALT</code>, <code>SECURE_AUTH_KEY</code>, <code>SECURE_AUTH_SALT</code>, <code>LOGGED_IN_KEY</code>, <code>LOGGED_IN_SALT</code>, <code>NONCE_KEY</code>, <code>NONCE_SALT</code>, <code>SECRET_KEY</code> and <code>SECRET_SALT</code>.</p>
<p>A random and long key gives you better encryption, and exponentially increasing that is using a random and long salt for the encryption.  Encryptions with known salts are incredibly easy to decrypt compared to encryptions with secure salts, because the salt + key individually need to be guessed in order to find a matching hash, vs. just the key if the salt is known.  See: <a href="http://www.askapache.com/security/locating-weak-passwords.html">Locating weak passwords</a>.</p>
<blockquote>
    <p>A secret key is a hashing salt which makes your site harder to hack and access harder to crack by adding random elements to the password.</p>
    <p>In simple terms, a secret key is a password with elements that make it harder to generate enough options to break through your security barriers. A password like "password" or "test" is simple and easily broken. A random, unpredictable password such as "88a7da62429ba6ad3cb3c76a09641fc" takes years to come up with the right combination.</p>
</blockquote>
<p>For more information on the technical background and breakdown of secret keys and secure passwords, see: </p>
<ul>
    <li><a href="http://wordpress.org/support/topic/170987">WordPress Support Forum - HOWTO: Set up secret keys in WordPress 2.6+</a></li>
    <li><a href="http://en.wikipedia.org/wiki/Password_cracking">Wikipedia's explanation of Password Cracking</a></li>
</ul>
<p>I like to use the <a href="https://api.wordpress.org/secret-key/1.1/">WordPress.org secret-key service</a> 4 times.  That's because for each key and salt I like to do: (1 key from api +random keyboard input+1 key from api).</p>
<pre>/**#@+
 * Authentication Unique Keys.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies.
 * This will force all users to have to log in again.
 *
 * @since 2.6.0
 *
 * Get salt to add to hashes to help prevent attacks.
 *
 * The secret key is located in two places: the database in case the secret key
 * isn&#039;t defined in the second place, which is in the wp-config.php file. If you
 * are going to set the secret key, then you must do so in the wp-config.php
 * file.
 *
 * The secret key in the database is randomly generated and will be appended to
 * the secret key that is in wp-config.php file in some instances. It is
 * important to have the secret key defined or changed in wp-config.php.
 *
 * If you have installed WordPress 2.5 or later, then you will have the
 * SECRET_KEY defined in the wp-config.php already. You will want to change the
 * value in it because hackers will know what it is. If you have upgraded to
 * WordPress 2.5 or later version from a version before WordPress 2.5, then you
 * should add the constant to your wp-config.php file.
 *
 * Below is an example of how the SECRET_KEY constant is defined with a value.
 * You must not copy the below example and paste into your wp-config.php. If you
 * need an example, then you can have a
 * {@link https://api.wordpress.org/secret-key/1.1/ secret key created} for you.
 *
 * Salting passwords helps against tools which has stored hashed values of
 * common dictionary strings. The added values makes it harder to crack if given
 * salt string is not weak.
 *
 * @since 2.5
 * @link https://api.wordpress.org/secret-key/1.1/ Create a Secret Key for wp-config.php
 *
 * @return string Salt value from either &#039;SECRET_KEY&#039; or &#039;secret&#039; option
 */
define(&#039;AUTH_KEY&#039;,        &#039;jflkhaskljdfhkljasdhflkjashd;flkjhas;djfh;kajshdflkjashdlfkjhasdlkfhal?p[B+GR{@&gt;{Yq`c|LnG;dvq#| %OA_cbBSU6,rICC1o/c)-|&#039;);
define(&#039;SECURE_AUTH_KEY&#039;, &#039;jflkhaskljdfhkljasdhflkjashd;flkjhas;djfh;kajshdflkjashdlfkjhasdlkfhal?Vp[Bb15baar8&amp;R-r&lt;[T|?(xhJJABGq+Ux+U$)-Hltp/&#039;);
define(&#039;LOGGED_IN_KEY&#039;,   &#039;jflkhaskljdfhkljasdhflkjashd;flkjhas;djfh;kajshdflkjashdlfkjhasdlkfhal?Vp[B&lt;5n6DG|YWnJ9tY2!M1L)`{-$LW~~Ia%.uCbn!P. 41o2$Z$4&#039;);
define(&#039;NONCE_KEY&#039;,       &#039;jflkhaskljdfhkljasdhflkjashd;flkjhas;djfh;kajshdflkjashdlfkjhasdlkfhal?Vp[Bgu&lt;wM*zewR0.{+m:bmrB?wj!B,4]Wo+4 Avk ApR-D?E&#039;);
define(&#039;SECRET_KEY&#039;,     &#039;jflkhaskljdfhkljasdhflkjashd;flkjhas;djfh;kajshdflkjashdlfkjhasdlkfhal?Vp[B52ugH6muE9r4._iZwoYKUybrqLPpv|d Xr+|yrqhUE&#039;);
&nbsp;
define(&#039;AUTH_SALT&#039;,        &#039;123423190847olqkfhladhfsldshafasdfasdf09a7f-90a87df98adfyapoiyaf9asd8f70a9s8d7f908a7sdf97W4qCdm~Ky%+%~PPa5b YEmDI%U[W!-B&#039;);
define(&#039;SECURE_AUTH_SALT&#039;, &#039;123423190847olqkfhladhfsldshafasdfasdf09a7f-90a87df98adfyapoiyaf9asd8f70a9s8d7f908a7sdf97W4qCdmad/7o6.AU3%9o-|Kqm]+eUqr-n~:ag&#039;);
define(&#039;LOGGED_IN_SALT&#039;,   &#039;123423190847olqkfhladhfsldshafasdfasdf09a7f-90a87df98adfyapoiyaf9asd8f70a9s8d7f908a7sdf97W4qCdmsLiCv@KJ{#wd(?qe(KcH3!&#039;);
define(&#039;NONCE_SALT&#039;,       &#039;123423190847olqkfhladhfsldshafasdfasdf09a7f-90a87df98adfyapoiyaf9asd8f70a9s8d7f908a7sdf97W4qCdmG9&gt;+wm 2)bS0Pd_+1rx0brX]ND8|&#039;);
define(&#039;SECRET_SALT&#039;,      &#039;123423190847olqkfhladhfsldshafasdfasdf09a7f-90a87df98adfyapoiyaf9asd8f70a9s8d7f908a7sdf97W4qCdm2&lt;&gt;))U|sty)+4vpWooKls/^[vN&#039;);
/**#@-*/</pre>
<hr class="C" />
<h2>Using SSL for Admin and Login</h2>
<p>SSL is kinda required from my point of view, it is just way to easy to sniff data off the wire otherwise.  At least with SSL you force them to use tools like burpsuite, paros proxy, webscarab, etc..</p>
<pre>/** @since 2.6.0  */
!defined(&#039;FORCE_SSL_ADMIN&#039;) &amp;&amp; define(&#039;FORCE_SSL_ADMIN&#039;, true);
&nbsp;
/** @since 2.6.0  */
!defined(&#039;FORCE_SSL_LOGIN&#039;) &amp;&amp; define(&#039;FORCE_SSL_LOGIN&#039;, true);</pre>
<h3>Mod_Rewrite to Force SSL</h3>
<p>This is pretty cool, it forces non-https for all urls except for /wp-admin and wp-login.php, which both require https.  It also checks for the logged_in_cookie, and if that is present in the request then it doesn't force non-https.  Kinda confusing if you don't have a <a href="http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html">mod_rewrite cheatsheet</a>.</p>
<pre>RewriteCond %{THE_REQUEST} ^$ [OR]
RewriteCond %{REQUEST_URI} ^/(wp-admin|wp-login\.php).*$ [NC,OR]
RewriteCond %{HTTP_COOKIE} ^.*wp_li_sadfsdfasdf11b361cdsdfasdfasd=.*$ [NC]
RewriteRule .* - [S=1]
&nbsp;
RewriteCond %{HTTPS} =on [OR]
RewriteCond %{HTTP_HOST} !^www\.askapache\.com$ [NC]
RewriteRule .* http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
&nbsp;
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(wp-admin/.*|wp-login\.php.*)\ HTTP/ [NC]
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]</pre>
<hr class="C" />
<h2>File System Permissions</h2>
<p><a class="IFR" href="http://www.askapache.com/security/chmod-umask-fileperms-stat-tricks.html"><img src="http://uploads.askapache.com/2008/11/danger-chmod-screenshot.png" alt="chmod, umask, file permissions test" title="chmod, umask, file permissions test" /></a>You can get a basic and solid intro on file permissions by reading: <a href="http://codex.wordpress.org/Changing_File_Permissions">Changing File Permissions</a>, or you can check out some of my <a href="http://www.askapache.com/security/chmod-umask-fileperms-stat-tricks.html">file permission research</a>.<br class="C" />
</p>
<pre>/** The permissions as octal number, usually 0644 for files, 0755 for dirs.
 *  http://codex.wordpress.org/Changing_File_Permissions
 *  if ( !$wp_filesystem-&gt;mkdir($remote_destination, FS_CHMOD_DIR) )
 */
!defined(&#039;FS_CHMOD_DIR&#039;) &amp;&amp; define(&#039;FS_CHMOD_DIR&#039;, (0755 &amp; ~ umask()));
!defined(&#039;FS_CHMOD_FILE&#039;) &amp;&amp; define(&#039;FS_CHMOD_FILE&#039;, (0644 &amp; ~ umask()));
/**#@-*/
&nbsp;
/** Define the timeouts for the connections. Only available after the construct is called to allow for per-transport overriding of the default. */
//stream_set_timeout( $stream, FS_TIMEOUT );
//!defined(&#039;FS_TIMEOUT&#039;) &amp;&amp; define(&#039;FS_TIMEOUT&#039;, 30);
&nbsp;
//$this-&gt;link = @ftp_connect($this-&gt;options[&#039;hostname&#039;], $this-&gt;options[&#039;port&#039;], FS_CONNECT_TIMEOUT);
//!defined(&#039;FS_CONNECT_TIMEOUT&#039;) &amp;&amp; define(&#039;FS_CONNECT_TIMEOUT&#039;, 30);
&nbsp;
// function get_filesystem_method($args = array(), $context = false) {
//  $method = defined(&#039;FS_METHOD&#039;) ? FS_METHOD : false; //Please ensure that this is either &#039;direct&#039;, &#039;ssh&#039;, &#039;ftpext&#039; or &#039;ftpsockets&#039;
//!defined(&#039;FS_METHOD&#039;) &amp;&amp; define(&#039;FS_METHOD&#039;, &#039;direct&#039;);
&nbsp;
/** These methods for the WordPress core, plugin, and theme upgrades try to determine the WordPress path, as reported by PHP, but symlink trickery can sometimes
 * &#039;muck this up&#039; so if you know the paths to the various folders on the server, as seen via your FTP user, you can manually define them in the wp-config.php file.
 * FS_METHOD forces the filesystem method. It should only be "direct", "ssh", "ftpext", or "ftpsockets".
 * FTP_BASE is the full path to the "base" folder of the WordPress installation.
 * FTP_CONTENT_DIR is the full path to the wp-content folder of the WordPress installation.
 * FTP_PLUGIN_DIR is the full path to the plugins folder of the WordPress installation.
 * FTP_PUBKEY is the full path to your SSH public key.
 * FTP_PRIKEY is the full path to your SSH private key.
 * FTP_USER is either user FTP or SSH username. Most likely these are the same, but use the appropriate one for the type of update you wish to do.
 * FTP_PASS is the password for the username entered for FTP_USER. If you are using SSH public key authentication this can be omitted.
 * FTP_HOST is the hostname:port combination for your SSH/FTP server. The standard FTP port is 21 and the standard SSH port is 22.
 */
//define(&#039;FS_METHOD&#039;, &#039;ftpext&#039;);
//define(&#039;FTP_BASE&#039;, &#039;/path/to/wordpress/&#039;);
//define(&#039;FTP_CONTENT_DIR&#039;, &#039;/path/to/wordpress/wp-content/&#039;);
//define(&#039;FTP_PLUGIN_DIR &#039;, &#039;/path/to/wordpress/wp-content/plugins/&#039;);
//define(&#039;FTP_PUBKEY&#039;, &#039;/home/username/.ssh/id_rsa.pub&#039;);
//define(&#039;FTP_PRIKEY&#039;, &#039;/home/username/.ssh/id_rsa&#039;);
//define(&#039;FTP_USER&#039;, &#039;username&#039;);
//define(&#039;FTP_PASS&#039;, &#039;password&#039;);
//define(&#039;FTP_HOST&#039;, &#039;ftp.example.org:21&#039;);
&nbsp;
/**
 * Block requests through the proxy.
 *
 * Those who are behind a proxy and want to prevent access to certain hosts may do so. This will
 * prevent plugins from working and core functionality, if you don&#039;t include api.wordpress.org.
 *
 * You block external URL requests by defining WP_HTTP_BLOCK_EXTERNAL in your wp-config.php file
 * and this will only allow localhost and your blog to make requests.
 * The constant WP_ACCESSIBLE_HOSTS will allow additional hosts to go through for requests. The format of the
 * WP_ACCESSIBLE_HOSTS constant is a comma separated list of hostnames to allow.
 *
 * @since 2.8.0
 * @link http://core.trac.wordpress.org/ticket/8927 Allow preventing external requests.
/** @since 2.9  */
//!defined(&#039;WP_HTTP_BLOCK_EXTERNAL&#039;) &amp;&amp; define( &#039;WP_HTTP_BLOCK_EXTERNAL&#039;, false );
&nbsp;
/*
 * The constant WP_ACCESSIBLE_HOSTS will allow additional hosts to go through for requests. The format of the
 * WP_ACCESSIBLE_HOSTS constant is a comma separated list of hostnames to allow.
 *
 * @since 2.8.0
 * @link http://core.trac.wordpress.org/ticket/8927 Allow preventing external requests.
 * $accessible_hosts = preg_split(&#039;|,\s*|&#039;, WP_ACCESSIBLE_HOSTS);
 * return !in_array( $check[&#039;host&#039;], $accessible_hosts ); //Inverse logic, If its in the array, then we can&#039;t access it.
 */
//!defined(&#039;WP_ACCESSIBLE_HOSTS&#039;) &amp;&amp; define( &#039;WP_ACCESSIBLE_HOSTS&#039;, &#039;askapache.com,askapache.org&#039; );</pre>
<hr class="C" />
<h3>Cookies!</h3>
<p>There's always a little comfort in having non-default cookies for security (against auto-bots), and using shorter names also means smaller HTTP Packets.</p>
<p>The <code>$cookie_hash</code> is my hack to get around the fact that <code>COOKIEHASH</code> isn't definable in <code>wp-config</code>.</p>
<pre>/**#@+
 * COOKIES
 * Used to guarantee unique hash cookies @since 1.5 */
$cookie_hash=md5(WP_SITEURL);
&nbsp;
/** Set a cookie now to see if they are supported by the browser.
 * setcookie(TEST_COOKIE, &#039;WP Cookie check&#039;, 0, COOKIEPATH, COOKIE_DOMAIN);
 * @since 2.3.0 */
!defined(&#039;TEST_COOKIE&#039;) &amp;&amp; define(&#039;TEST_COOKIE&#039;, &#039;wp_tc&#039;);
&nbsp;
/* @since 2.6.0 */
!defined(&#039;LOGGED_IN_COOKIE&#039;) &amp;&amp; define(&#039;LOGGED_IN_COOKIE&#039;, &#039;wp_li_&#039; . $cookie_hash);
&nbsp;
/* @since 2.6.0 */
!defined(&#039;SECURE_AUTH_COOKIE&#039;) &amp;&amp; define(&#039;SECURE_AUTH_COOKIE&#039;, &#039;wp_sa_&#039; . $cookie_hash);
&nbsp;
/* @since 2.5.0 */
!defined(&#039;AUTH_COOKIE&#039;) &amp;&amp; define(&#039;AUTH_COOKIE&#039;, &#039;wp_a_&#039; . $cookie_hash);
&nbsp;
/* @since 2.0.0 */
!defined(&#039;PASS_COOKIE&#039;) &amp;&amp; define(&#039;PASS_COOKIE&#039;, &#039;wp_p_&#039; . $cookie_hash);
&nbsp;
/* @since 2.0.0 */
!defined(&#039;USER_COOKIE&#039;) &amp;&amp; define(&#039;USER_COOKIE&#039;, &#039;wp_u_&#039; . $cookie_hash);
&nbsp;
/* ok unset this var, its not needed as COOKIEHASH will have this value, but is not definable in wp-config.php */
unset($cookie_hash);
&nbsp;
/** @since 1.2.0 */
!defined(&#039;COOKIEPATH&#039;) &amp;&amp; define(&#039;COOKIEPATH&#039;, preg_replace(&#039;|https?://[^/]+|i&#039;, &#039;&#039;, WP_HOME . &#039;/&#039; ) );
&nbsp;
/** @since 1.5.0 */
!defined(&#039;SITECOOKIEPATH&#039;) &amp;&amp; define(&#039;SITECOOKIEPATH&#039;, preg_replace(&#039;|https?://[^/]+|i&#039;, &#039;&#039;, WP_SITEURL . &#039;/&#039; ) );
&nbsp;
/** @since 2.6.0 */
!defined(&#039;ADMIN_COOKIE_PATH&#039;) &amp;&amp; define( &#039;ADMIN_COOKIE_PATH&#039;, SITECOOKIEPATH . &#039;wp-admin&#039; );
&nbsp;
/** @since 2.6.0 */
!defined(&#039;PLUGINS_COOKIE_PATH&#039;) &amp;&amp; define( &#039;PLUGINS_COOKIE_PATH&#039;, preg_replace(&#039;|https?://[^/]+|i&#039;, &#039;&#039;, WP_PLUGIN_URL)  );
&nbsp;
/** @since 2.0.0 */
!defined(&#039;COOKIE_DOMAIN&#039;) &amp;&amp; define(&#039;COOKIE_DOMAIN&#039;, $_SERVER[&#039;SERVER_NAME&#039;]);</pre>
<hr class="C" />
<pre>/**
  * The WP_CACHE setting, if true, includes the wp-content/advanced-cache.php script, when executing wp-settings.php.
  * For an advanced caching plugin to use, static because you would only want one
  * if ( defined(&#039;WP_CACHE&#039;) )@include WP_CONTENT_DIR . &#039;/advanced-cache.php&#039;;
  */
!defined(&#039;WP_CACHE&#039;) &amp;&amp; define(&#039;WP_CACHE&#039;, true);
&nbsp;
/** WordPress Localized Language, defaults to en_US.
 *
 * Change this to localize WordPress.  A corresponding MO file for the chosen
 * language must be installed to wp-content/languages. For example, install
 * de.mo to wp-content/languages and set WPLANG to &#039;de&#039; to enable German
 * language support. */
!defined(&#039;WPLANG&#039;) &amp;&amp; define (&#039;WPLANG&#039;, &#039;en_US&#039;);
&nbsp;
/** Stores the location of the language directory. First looks for language folder in WP_CONTENT_DIR
 *   and uses that folder if it exists. Or it uses the "languages" folder in WPINC. @since 2.1.0 */
//!defined(&#039;WP_LANG_DIR&#039;) &amp;&amp; define(&#039;WP_LANG_DIR&#039;, ABSPATH . WPINC . &#039;/languages&#039;);
&nbsp;
/** LANGDIR defines what directory the WPLANG .mo file resides. If LANGDIR is not defined WordPress looks first to wp-content/languages and then wp-includes/languages for the .mo defined by WPLANG file.  Old static relative path maintained for limited backwards compatibility - won&#039;t work in some cases*/
//!defined(&#039;LANGDIR&#039;) &amp;&amp; define(&#039;LANGDIR&#039;, &#039;wp-content/languages&#039;);
&nbsp;
/** Stores the location of the WordPress directory of functions, classes, and core content. @since 1.0.0 */
//!defined(&#039;WPINC&#039;) &amp;&amp; define(&#039;WPINC&#039;, &#039;wp-includes&#039;);</pre>
<hr class="C" />
<h2>WPMU Stuff</h2>
<p>I personally don't use.</p>
<pre>/** Allows for the mu-plugins directory to be moved from the default location. @since 2.8.0 */
//!defined(&#039;WPMU_PLUGIN_DIR&#039;) &amp;&amp; define( &#039;WPMU_PLUGIN_DIR&#039;, WP_CONTENT_DIR . &#039;/mu-plugins&#039; ); // full path, no trailing slash
&nbsp;
/** Allows for the mu-plugins directory to be moved from the default location. @since 2.8.0 */
//!defined(&#039;WPMU_PLUGIN_URL&#039;) &amp;&amp; define( &#039;WPMU_PLUGIN_URL&#039;, WP_CONTENT_URL . &#039;/mu-plugins&#039; ); // full url, no trailing slash
&nbsp;
/** Allows for the mu-plugins directory to be moved from the default location. @since 2.8.0 */
//!defined( &#039;MUPLUGINDIR&#039; ) &amp;&amp; define( &#039;MUPLUGINDIR&#039;, &#039;wp-content/mu-plugins&#039; ); // Relative to ABSPATH.  For back compat.</pre>
<hr class="C" />
<h2>WordPress Database</h2>
<p>This is usually the only thing I have to manually edit when creating a new site, unless I just use the same DB and modify the $table_prefix, (farther down). I run everything I possibly can in UTF-8, but if you don't already know alot about character sets, wow it is one of the most confusing things so you may want to save learning about that topic for another day.  Otherwise the following are helpful (<em>and show how confusing character sets are!</em>)</p>
<ul>
    <li><a href="http://dev.mysql.com/doc/refman/5.0/en/charset-charsets.html">Character Sets and Collations MySQL Support</a></li>
    <li><a href="http://codex.wordpress.org/Converting_Database_Character_Sets">Converting Database Character Sets</a></li>
    <li><a href="http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-sets.html">UTF-8 character sets</a> (<a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a>)</li>
</ul>
<p>If you ever setup WP to use the builtin membership features, make sure you learn about the <code>CUSTOM_USER_TABLE</code> and <code>CUSTOM_USER_META_TABLE</code> constants, I've found them very helpful.</p>
<pre>/**#@+
 * MySQL settings
 */
/** The name of the database for WordPress */
define(&#039;DB_NAME&#039;, &#039;askapachewpblog75&#039;);
&nbsp;
/** The username to access the database */
define(&#039;DB_USER&#039;, &#039;askapache245d&#039;);
&nbsp;
/** The password for the username to access the database */
define(&#039;DB_PASSWORD&#039;, &#039;asdfklj2340&#039;);
&nbsp;
/** The hostname to connect to the database at */
define(&#039;DB_HOST&#039;, &#039;mysql.askapache.com&#039;);
&nbsp;
/** The charset of the database */
define(&#039;DB_CHARSET&#039;, &#039;utf8&#039;);
&nbsp;
/** The collation of the database */
define(&#039;DB_COLLATE&#039;, &#039;utf8_general_ci&#039;);</pre>
<hr class="C" />
<h2>$table_prefix</h2>
<p>The <code>$table_prefix</code> is the value placed in the front of your database tables. Change the value if you want to use something other than wp_ for your database prefix. Typically this is changed if you are <a href="http://codex.wordpress.org/Installing_Multiple_Blogs">installing multiple WordPress blogs</a> in the same database, and also for enhanced security.</p>
<p>Its a safe and good idea to change this value pre-installation to add more security to your WordPress blog. Exploits attempted against your WordPress blog by malicious crackers often are built with the premise that your blog uses the prefix wp_, by changing the value you mitigate some attack vectors. </p>
<pre>/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each a unique
 * prefix. Only numbers, letters, and underscores please!
 */
$table_prefix  = &#039;ar15_&#039;;
&nbsp;
/** CUSTOM_USER_TABLE and CUSTOM_USER_META_TABLE are used to designated that the user and usermeta tables normally utilized by WordPress are not used, instead these values/tables are used to store your user information. */
//!defined(&#039;CUSTOM_USER_TABLE&#039;) &amp;&amp; define(&#039;CUSTOM_USER_TABLE&#039;, $table_prefix . &#039;my_users&#039;);
//!defined(&#039;CUSTOM_USER_META_TABLE&#039;) &amp;&amp; define(&#039;CUSTOM_USER_META_TABLE&#039;, $table_prefix . &#039;my_usermeta&#039;);</pre>
<h2>Setup PHP Ini Settings</h2>
<pre>
/** Turns the output of errors on or off, you really never want this on, you should only view errors by reading the log file. */
ini_set(&#039;display_errors&#039;, WP_DEBUG_DISPLAY);
&nbsp;
/** Tells whether script error messages should be logged to the server&#039;s error log or error_log. */
ini_set(&#039;log_errors&#039;, &#039;On&#039;);
&nbsp;
/** http://us.php.net/manual/en/timezones.php */
ini_set(&#039;date.timezone&#039;, &#039;America/Indianapolis&#039;);
&nbsp;
/** Where to log php errors */
ini_set(&#039;error_log&#039;, ASKAPACHE_ROOT . &#039;/logs/php_error.log&#039;);
&nbsp;
/** Set the memory limit, otherwise defaults to &#039;32M&#039; */
ini_set(&#039;memory_limit&#039;, WP_MEMORY_LIMIT);</pre>
<h2>Sessions are slow</h2>
<p>So I only use sessions when I have a specific use... In this case I need sessions only when one of the tools in the /online-tools/ directory is being used.  And that is for the <a href="http://www.askapache.com/security/php-captcha-anti-spam-example.html">captcha image</a>.  In the future I won't ever use sessions.</p>
<pre>if(preg_match( &#039;#^/online-tools/#&#039;,$_SERVER[&#039;REQUEST_URI&#039;])) session_start();</pre>
<h2>Include Custom Files</h2>
<p>Sure you could use the my-hacks.php that WP allows, or you can just stick your functions in your <code>TEMPLATEPATH/functions.php</code> file, but they are executed only after the wp-settings.php file, which may be too late for your file.</p>
<p>In the past I've also used the <a href="http://us2.php.net/manual/en/ini.core.php#ini.auto-prepend-file">auto_prepend_file</a> settings to run my script before anything (index.php) but I ran into some issues on different hosts, and it wasn't as portable.</p>
<p>This is useful because you can have a file with globally available functions that you can use in non-WP areas as well as WP areas.  I am moving away from this more and more as I learn more about classes and build plugins instead for portability.</p>
<pre>include_once ASKAPACHE_ROOT . &#039;/includes/myfunctions.inc&#039;;
&nbsp;
/** Sets up WordPress vars and included files. */
require_once(ABSPATH . &#039;wp-settings.php&#039;);
?&gt;</pre>
<h2>Some Useful PHP</h2>
<p>I am constantly trying to make my sites and code more portable, so I am using plugins alot more to accomplish things that I use to do with separate php.  Here are some examples of minimal php.</p>
<pre>add_filter("the_generator", create_function(&#039;$a&#039;,&#039;return "";&#039;));
add_filter(&#039;the_content&#039;, create_function(&#039;$a&#039;, &#039;return ((is_feed())? $a."&lt;p&gt;&lt;a href=\"".get_permalink()."\"&gt;".get_the_title()."&lt;/a&gt; originally appeared on ".get_bloginfo("name").".&lt;/p&gt;" : $a);&#039;), 99999);
add_filter(&#039;excerpt_length&#039;, create_function(&#039;$a&#039;, &#039;return 300;&#039;),99);
add_filter(&#039;excerpt_more&#039;, create_function(&#039;$a&#039;, &#039;return "&amp;hellip;";&#039;),99);
add_action( &#039;wp_head&#039;, create_function(&#039;$a&#039;,&#039;echo "&lt;link rel=\"pingback\" href=\"&#039;.get_bloginfo(&#039;pingback_url&#039;).&#039;\" /&gt;\n";&#039;), 95 );
add_action( &#039;wp_head&#039;, create_function(&#039;$a&#039;,&#039;echo "&lt;link rel=\"schema.rss\" href=\"http://purl.org/rss/1.0/\" /&gt;\n";&#039;), 96 );
add_action( &#039;wp_head&#039;, create_function(&#039;$a&#039;,&#039;echo "&lt;link rel=\"schema.rel\" href=\"http://purl.org/vocab/relationship/\" /&gt;\n";&#039;), 97 );
add_action( &#039;wp_head&#039;, create_function(&#039;$a&#039;,&#039;echo "&lt;link rel=\"meta\" type=\"application/rdf+xml\" href=\"/foaf.rdf\" /&gt;\n";&#039;), 98 );
add_action( &#039;wp_head&#039;, create_function(&#039;$a&#039;,&#039;echo "&lt;link href=\"/favicon.ico\" rel=\"shortcut icon\" type=\"image/x-icon\" /&gt;\n";&#039;), 99 );</pre>
<h2>Debugging Note</h2>
<p><a href="http://wordpress.org/extend/plugins/askapache-debug-viewer/screenshots/"><img alt="AskApache Advanced Debugging Output" src="http://s.wordpress.org/extend/plugins/askapache-debug-viewer/screenshot-1.png?r=160129" title="AskApache Advanced Debugging Output" width="625" height="548" /></a>If you read this far than you probably know how important debugging is, but I sometimes like to stick the best tips deep in my articles to make sure only YOU find it.  GRTFM isn't used on this site, it's mostly a requirement because my writing can get pretty bad..  The point, debugging is more than a crucial requirement if you want to do anything cool.  Don't worry I got you.. check my <a href="http://wordpress.org/extend/plugins/askapache-debug-viewer/">AskApache Debug Viewer Plugin from the official WP site</a>.  It's pretty close to providing as verbose amount of information that I could possibly figure out how to get out of php, probably more than you have ever seen at least, I focused on quantity.  I use it all the time on new installs as there is no setup required and it tells me advanced information about the setup of the server, hacker code for sure.<br class="C" />
</p>
<p>Here's a quick function to see set global vars, I just think this is interesting code.</p>
<pre>function askapache_global_debug(){
  global $_GET,$_POST,$_COOKIE,$_SESSION,$_ENV,$_FILES,$_SERVER,$_REQUEST,$HTTP_POST_FILES,$HTTP_POST_VARS,$HTTP_SERVER_VARS,$HTTP_RAW_POST_DATA,$HTTP_GET_VARS,$HTTP_COOKIE_VARS,$HTTP_ENV_VARS;
  $gv=create_function(&#039;$n&#039;,&#039;global $$n; ob_start(); if ( is_array($$n) &amp;&amp; sizeof($$n)&gt;0 &amp;&amp; print("[{$n}]\n") ) print_r($$n);return ob_get_clean();&#039;);
  foreach (array(&#039;_GET&#039;,&#039;_POST&#039;,&#039;_COOKIE&#039;,&#039;_SESSION&#039;,&#039;_ENV&#039;,&#039;_FILES&#039;,&#039;_SERVER&#039;,&#039;_REQUEST&#039;,&#039;HTTP_POST_FILES&#039;,&#039;HTTP_POST_VARS&#039;,&#039;HTTP_SERVER_VARS&#039;,&#039;HTTP_RAW_POST_DATA&#039;,&#039;HTTP_GET_VARS&#039;,&#039;HTTP_COOKIE_VARS&#039;,&#039;HTTP_ENV_VARS&#039;) as $k)echo $gv($k);
  print_r(get_defined_constants());
}</pre>
<p class="anote">Also check the WordPress Codex page: <a href="http://codex.wordpress.org/Editing_wp-config.php">Editing wp-config.php</a> and Perishable Press's: <a href="http://perishablepress.com/press/2009/12/01/stupid-wordpress-tricks/">Stupid WordPress Tricks</a></p><p><a href="http://www.askapache.com/wordpress/advanced-wp-config-php-tweaks.html"></a><a href="http://www.askapache.com/wordpress/advanced-wp-config-php-tweaks.html">Advanced WordPress wp-config.php Tweaks</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/wordpress/advanced-wp-config-php-tweaks.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Crazy Advanced Mod_Rewrite Debug Tutorial</title>
		<link>http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html</link>
		<comments>http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html#comments</comments>
		<pubDate>Fri, 11 Sep 2009 17:55:32 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Htaccess]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=1209</guid>
		<description><![CDATA[<p><strong>Note:  Extremely ILL Content</strong><br />Find the key to unlocking mod_rewrite and you WILL be sick..  sick with a diamond disease on your wrist!<br /><a class="hs hs13" href="http://uploads.askapache.com/2008/08/mod_rewrite_ascii.png"></a></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html"></a><a href="http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html"><cite>AskApache.com</cite></a></p><p><a class="hs hs13" href="http://uploads.askapache.com/2008/08/mod_rewrite_ascii.png"></a><strong>Are you an advanced mod_rewrite expert or guru?</strong>  This article is for YOU too!  Just make sure to read all the way to the bottom..<br class="C" /></p>

<p class="anote">The following undocumented techniques and methods will allow you to utilize mod_rewrite at an  "expert level" by showing you how to <a href="http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html#decoded">unlock its secrets</a>.  <br class="C" /></p>


<p>Most if not all web developers and server administrators struggle with Apache mod_rewrite.  It's very tough and only gets a little easier with practice.  Until Now!  Get ready to explode your learning curve, I figured something out.</p>


<h2>Why mod_rewrite is so tough</h2>
<p>I have come to the conclusion, after many hours of zenful thought, that the reason mod_rewrite is so tough is pretty obvious, people are trying to apply regular-expressions to URLs and Variables that they don't really understand.  They understand what they want, but they don't understand what the URLS and Variables are that they are trying to rewrite.</p>

<h2>Hit-Or-Miss with mod_rewrite</h2>
<p>A lot of the mod_rewrite "experts" and "gurus" floating around the net absolutely know their mod_rewrite, but what separates them from a beginner or novice is for the most part an understanding of what the URLS and Variables look like that are targeted by the regular expressions.  Take this simple rewriterule that rewrites requests made without the www to www.</p>
<pre>
RewriteEngine On
RewriteBase /
&nbsp;
RewriteCond %{HTTP_HOST} !^www\.askapache\.com$ [NC]
RewriteRule .+ http://www.askapache.com%{REQUEST_URI}
</pre>

<p>Pretty simple right?  WRONG.  Most people could not figure that out..</p>

<h3>Why?</h3>
<p>The reason intelligent people can't figure that out is because they have no idea what HTTP_HOST or REQUEST_URI actually looks like.  How can you write a rule for something if you don't know what it looks like?  You can't.</p>

<h2>When Not To Use Mod_Rewrite</h2>
<p>Ok so heres an important concept that alot of people haven't heard.  You should only use <a href="http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html">mod_rewrite's rewriterule </a>when you use a rewritecond or if you are rewriting internally like my <a href="http://www.askapache.com/htaccess/pimp-out-your-feedburner-count.html">feedcount hack</a>.</p>
<p>If you are simply redirecting one url to another, you should definately be using the much easier <a href="http://www.askapache.com/htaccess/seo-search-engine-friendly-redirects-without-mod_rewrite.html">mod_alias's redirect and redirectmatch</a>, which is enabled on most Apache servers.</p>


<h2>When To Use Mod_Rewrite</h2>
<p>So then, you should only use mod_rewrite's rewriterule when you are checking against one of the Apache Environment Variables to determine whether to rewrite or not.  This is where the Apache Documentation is grossly lacking.  They don't tell you what those variables look like, leaving us completely incapable of creating rewrites based on them.  <strong>Not anymore.</strong></p>

<h3>Mod_Rewrite Environment Variables (The Secret)</h3>
<p>Here's the variables I have found accessible by <a href="http://httpd.apache.org/docs/trunk/mod/mod_rewrite.html#rewritecond">mod_rewrite</a> (both documented and undocumented).   A thing to note is that you can set these variables early in an .htaccess file using SetEnv, RewriteRule, Header, etc.. and they will be accessible at the end of the .htaccess file.<br class="C" /></p>

<table class="bordered"><tbody><tr class="header"><th>Name</th></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#API_VERSION"><code>API_VERSION</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#AUTH_TYPE"><code>AUTH_TYPE</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#CONTENT_LENGTH"><code>CONTENT_LENGTH</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#CONTENT_TYPE"><code>CONTENT_TYPE</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#DOCUMENT_ROOT"><code>DOCUMENT_ROOT</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#GATEWAY_INTERFACE"><code>GATEWAY_INTERFACE</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTPS"><code>HTTPS</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_ACCEPT"><code>HTTP_ACCEPT</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_ACCEPT_CHARSET"><code>HTTP_ACCEPT_CHARSET</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_ACCEPT_ENCODING"><code>HTTP_ACCEPT_ENCODING</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_ACCEPT_LANGUAGE"><code>HTTP_ACCEPT_LANGUAGE</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_CACHE_CONTROL"><code>HTTP_CACHE_CONTROL</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_CONNECTION"><code>HTTP_CONNECTION</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_COOKIE"><code>HTTP_COOKIE</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_FORWARDED"><code>HTTP_FORWARDED</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_HOST"><code>HTTP_HOST</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_KEEP_ALIVE"><code>HTTP_KEEP_ALIVE</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_PROXY_CONNECTION"><code>HTTP_PROXY_CONNECTION</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_REFERER"><code>HTTP_REFERER</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#HTTP_USER_AGENT"><code>HTTP_USER_AGENT</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#IS_SUBREQ"><code>IS_SUBREQ</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#ORIG_PATH_INFO"><code>ORIG_PATH_INFO</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#ORIG_PATH_TRANSLATED"><code>ORIG_PATH_TRANSLATED</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#ORIG_SCRIPT_FILENAME"><code>ORIG_SCRIPT_FILENAME</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#ORIG_SCRIPT_NAME"><code>ORIG_SCRIPT_NAME</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#PATH"><code>PATH</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#PATH_INFO"><code>PATH_INFO</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#PHP_SELF"><code>PHP_SELF</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#QUERY_STRING"><code>QUERY_STRING</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REDIRECT_QUERY_STRING"><code>REDIRECT_QUERY_STRING</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REDIRECT_REMOTE_USER"><code>REDIRECT_REMOTE_USER</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REDIRECT_STATUS"><code>REDIRECT_STATUS</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REDIRECT_URL"><code>REDIRECT_URL</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REMOTE_ADDR"><code>REMOTE_ADDR</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REMOTE_HOST"><code>REMOTE_HOST</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REMOTE_IDENT"><code>REMOTE_IDENT</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REMOTE_PORT"><code>REMOTE_PORT</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REMOTE_USER"><code>REMOTE_USER</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REQUEST_FILENAME"><code>REQUEST_FILENAME</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REQUEST_METHOD"><code>REQUEST_METHOD</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REQUEST_TIME"><code>REQUEST_TIME</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#REQUEST_URI"><code>REQUEST_URI</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SCRIPT_FILENAME"><code>SCRIPT_FILENAME</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SCRIPT_GROUP"><code>SCRIPT_GROUP</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SCRIPT_NAME"><code>SCRIPT_NAME</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SCRIPT_URI"><code>SCRIPT_URI</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SCRIPT_URL"><code>SCRIPT_URL</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SCRIPT_USER"><code>SCRIPT_USER</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SERVER_ADDR"><code>SERVER_ADDR</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SERVER_ADMIN"><code>SERVER_ADMIN</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SERVER_NAME"><code>SERVER_NAME</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SERVER_PORT"><code>SERVER_PORT</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SERVER_PROTOCOL"><code>SERVER_PROTOCOL</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SERVER_SIGNATURE"><code>SERVER_SIGNATURE</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SERVER_SOFTWARE"><code>SERVER_SOFTWARE</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_CIPHER"><code>SSL_CIPHER</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_CIPHER_ALGKEYSIZE"><code>SSL_CIPHER_ALGKEYSIZE</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_CIPHER_EXPORT"><code>SSL_CIPHER_EXPORT</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_CIPHER_USEKEYSIZE"><code>SSL_CIPHER_USEKEYSIZE</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_CLIENT_VERIFY"><code>SSL_CLIENT_VERIFY</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_PROTOCOL"><code>SSL_PROTOCOL</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_A_KEY"><code>SSL_SERVER_A_KEY</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_A_SIG"><code>SSL_SERVER_A_SIG</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_CERT"><code>SSL_SERVER_CERT</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_I_DN"><code>SSL_SERVER_I_DN</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_I_DN_C"><code>SSL_SERVER_I_DN_C</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_I_DN_CN"><code>SSL_SERVER_I_DN_CN</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_I_DN_L"><code>SSL_SERVER_I_DN_L</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_I_DN_O"><code>SSL_SERVER_I_DN_O</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_I_DN_OU"><code>SSL_SERVER_I_DN_OU</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_I_DN_ST"><code>SSL_SERVER_I_DN_ST</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_M_SERIAL"><code>SSL_SERVER_M_SERIAL</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_M_VERSION"><code>SSL_SERVER_M_VERSION</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_S_DN"><code>SSL_SERVER_S_DN</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_S_DN_CN"><code>SSL_SERVER_S_DN_CN</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_S_DN_O"><code>SSL_SERVER_S_DN_O</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_S_DN_OU"><code>SSL_SERVER_S_DN_OU</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_V_END"><code>SSL_SERVER_V_END</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SERVER_V_START"><code>SSL_SERVER_V_START</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_SESSION_ID"><code>SSL_SESSION_ID</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_VERSION_INTERFACE"><code>SSL_VERSION_INTERFACE</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#SSL_VERSION_LIBRARY"><code>SSL_VERSION_LIBRARY</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#THE_REQUEST"><code>THE_REQUEST</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#TIME"><code>TIME</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#TIME_DAY"><code>TIME_DAY</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#TIME_HOUR"><code>TIME_HOUR</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#TIME_MIN"><code>TIME_MIN</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#TIME_MON"><code>TIME_MON</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#TIME_SEC"><code>TIME_SEC</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#TIME_WDAY"><code>TIME_WDAY</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#TIME_YEAR"><code>TIME_YEAR</code></a></td></tr>
<tr><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#TZ"><code>TZ</code></a></td></tr>
<tr class="odd"><td><a href="/htaccess/mod_rewrite-variables-cheatsheet.html#UNIQUE_ID"><code>UNIQUE_ID</code></a></td></tr>
</tbody></table>


<hr class="C" />



<h2>Decoding Mod_Rewrite Variables</h2>
<p>So when I realized my problem was that I didn't know the value of the variable being tested by the RewriteCond, I set out to try and discover how to view those variables..  Keep in mind you can also use RewriteLogging, but its only allowed for root users who can edit the httpd.conf, this is .htaccess.</p>

<h3>Setting Environment Variables with RewriteRule</h3>
<p>I discovered a multitude of methods to set and view apache environment variables, using various modules and some core tricks, but the method that allows me to view the most environment variables is RewriteRule.. I wanted to use <a href="http://www.askapache.com/htaccess/setenvif.html">SetEnvIf</a> more, but its just not as powerful as mod_rewrite, due to programming.</p>

<p>This code sets the variable <code>INFO_REQUEST_URI</code> to have the value of <code>REQUEST_URI</code>.</p>
<pre>
RewriteEngine On
RewriteBase /
RewriteRule .* - [E=INFO_REQUEST_URI:%{REQUEST_URI},NE]
</pre>



<h3>Saving the Apache Variable Values</h3>
<p>Now the trick is how to view that environment variable...  The method I came up with is nice... We will send the environment variable value in an HTTP Header, as there isn't much data manipulation/validation so you get an accurate look at the actual value..  At first I tried adding the variable value to a redirection using the query_string.. but a HTTP_USER_AGENT value doesn't play well as a query_string.</p>

<h4>Using RequestHeader in .htaccess</h4>
<p>This code takes advantage of the incredible mod_headers apache module to actually ADD a whole new header to YOUR request.  Seriously one of the coolest tricks I've found yet.. Its almost the same as being able to spoof POST requests!  Since Headers can be protected data... <em>especially the HTTP_COOKIE header</em>..</p>
<pre>
RequestHeader set INFO_REQUEST_URI "%{INFO_REQUEST_URI}e"
</pre>


<h3>Viewing the Variable Values</h3>
<p>Now you can use any kind of server-run interpreter like perl, php, ruby, etc., to view all the variable values.  All cgi-script handlers like those are able to view request headers.. </p>

<h3>PHP Code to access Apache Variables</h3>
<p>Works even in safe-mode... any interpreter can view HTTP Headers!  Note that each of these variables are added as HTTP headers to the request for the script.. kinda confusing.. So each variable sent as a header is prefixed with HTTP_ to denote it was a header.</p>

<pre>
&lt;?php
header("Content-Type: text/plain");
$INFO=$MISS=array();
foreach($_SERVER as $v=&gt;$r)
{
  if(substr($v,0,9)==&#039;HTTP_INFO&#039;)
  {
    if(!empty($r))$INFO[substr($v,10)]=$r;
    else $MISS[substr($v,10)]=$r;
  }
}
&nbsp;
/* thanks Mike! */
ksort($INFO);
ksort($MISS);
ksort($_SERVER);
&nbsp;
echo "Received These Variables:\n";
print_r($INFO);
&nbsp;
echo "Missed These Variables:\n";
print_r($MISS);
&nbsp;
echo "ALL Variables:\n";
print_r($_SERVER);
?&gt;
</pre>



<h2>Time to Get Crazy</h2>
<p>Just create the above php file on your site as <code>/test/index.php</code> or whatever, then create /test/.htaccess which should contain the below <code>.htaccess file</code> snippet.  Now just request <code>/test/index.php</code> and be amazed!   If you're looking for more general help check out this excellent <a href="http://www.addedbytes.com/apache/mod_rewrite-cheat-sheet/">mod_rewrite cheat sheet</a>.</p>

<p>Ok, so I've prepared the .htaccess code you can use to view the values of all these variables.  Just add it to a .htaccess file and make a request.  For this test I created an index.php file that printed out all the <code>$_SERVER</code> variables, and made requests to it.</p>



<pre>
RewriteEngine On
RewriteBase /
RewriteRule .* - [E=INFO_API_VERSION:%{API_VERSION},NE]
RewriteRule .* - [E=INFO_AUTH_TYPE:%{AUTH_TYPE},NE]
RewriteRule .* - [E=INFO_CONTENT_LENGTH:%{CONTENT_LENGTH},NE]
RewriteRule .* - [E=INFO_CONTENT_TYPE:%{CONTENT_TYPE},NE]
RewriteRule .* - [E=INFO_DOCUMENT_ROOT:%{DOCUMENT_ROOT},NE]
RewriteRule .* - [E=INFO_GATEWAY_INTERFACE:%{GATEWAY_INTERFACE},NE]
RewriteRule .* - [E=INFO_HTTPS:%{HTTPS},NE]
RewriteRule .* - [E=INFO_HTTP_ACCEPT:%{HTTP_ACCEPT},NE]
RewriteRule .* - [E=INFO_HTTP_ACCEPT_CHARSET:%{HTTP_ACCEPT_CHARSET},NE]
RewriteRule .* - [E=INFO_HTTP_ACCEPT_ENCODING:%{HTTP_ACCEPT_ENCODING},NE]
RewriteRule .* - [E=INFO_HTTP_ACCEPT_LANGUAGE:%{HTTP_ACCEPT_LANGUAGE},NE]
RewriteRule .* - [E=INFO_HTTP_CACHE_CONTROL:%{HTTP_CACHE_CONTROL},NE]
RewriteRule .* - [E=INFO_HTTP_CONNECTION:%{HTTP_CONNECTION},NE]
RewriteRule .* - [E=INFO_HTTP_COOKIE:%{HTTP_COOKIE},NE]
RewriteRule .* - [E=INFO_HTTP_FORWARDED:%{HTTP_FORWARDED},NE]
RewriteRule .* - [E=INFO_HTTP_HOST:%{HTTP_HOST},NE]
RewriteRule .* - [E=INFO_HTTP_KEEP_ALIVE:%{HTTP_KEEP_ALIVE},NE]
RewriteRule .* - [E=INFO_HTTP_MOD_SECURITY_MESSAGE:%{HTTP_MOD_SECURITY_MESSAGE},NE]
RewriteRule .* - [E=INFO_HTTP_PROXY_CONNECTION:%{HTTP_PROXY_CONNECTION},NE]
RewriteRule .* - [E=INFO_HTTP_REFERER:%{HTTP_REFERER},NE]
RewriteRule .* - [E=INFO_HTTP_USER_AGENT:%{HTTP_USER_AGENT},NE]
RewriteRule .* - [E=INFO_IS_SUBREQ:%{IS_SUBREQ},NE]
RewriteRule .* - [E=INFO_ORIG_PATH_INFO:%{ORIG_PATH_INFO},NE]
RewriteRule .* - [E=INFO_ORIG_PATH_TRANSLATED:%{ORIG_PATH_TRANSLATED},NE]
RewriteRule .* - [E=INFO_ORIG_SCRIPT_FILENAME:%{ORIG_SCRIPT_FILENAME},NE]
RewriteRule .* - [E=INFO_ORIG_SCRIPT_NAME:%{ORIG_SCRIPT_NAME},NE]
RewriteRule .* - [E=INFO_PATH:%{PATH},NE]
RewriteRule .* - [E=INFO_PATH_INFO:%{PATH_INFO},NE]
RewriteRule .* - [E=INFO_PHP_SELF:%{PHP_SELF},NE]
RewriteRule .* - [E=INFO_QUERY_STRING:%{QUERY_STRING},NE]
RewriteRule .* - [E=INFO_REDIRECT_QUERY_STRING:%{REDIRECT_QUERY_STRING},NE]
RewriteRule .* - [E=INFO_REDIRECT_REMOTE_USER:%{REDIRECT_REMOTE_USER},NE]
RewriteRule .* - [E=INFO_REDIRECT_STATUS:%{REDIRECT_STATUS},NE]
RewriteRule .* - [E=INFO_REDIRECT_URL:%{REDIRECT_URL},NE]
RewriteRule .* - [E=INFO_REMOTE_ADDR:%{REMOTE_ADDR},NE]
RewriteRule .* - [E=INFO_REMOTE_HOST:%{REMOTE_HOST},NE]
RewriteRule .* - [E=INFO_REMOTE_IDENT:%{REMOTE_IDENT},NE]
RewriteRule .* - [E=INFO_REMOTE_PORT:%{REMOTE_PORT},NE]
RewriteRule .* - [E=INFO_REMOTE_USER:%{REMOTE_USER},NE]
RewriteRule .* - [E=INFO_REQUEST_FILENAME:%{REQUEST_FILENAME},NE]
RewriteRule .* - [E=INFO_REQUEST_METHOD:%{REQUEST_METHOD},NE]
RewriteRule .* - [E=INFO_REQUEST_TIME:%{REQUEST_TIME},NE]
RewriteRule .* - [E=INFO_REQUEST_URI:%{REQUEST_URI},NE]
RewriteRule .* - [E=INFO_SCRIPT_FILENAME:%{SCRIPT_FILENAME},NE]
RewriteRule .* - [E=INFO_SCRIPT_GROUP:%{SCRIPT_GROUP},NE]
RewriteRule .* - [E=INFO_SCRIPT_NAME:%{SCRIPT_NAME},NE]
RewriteRule .* - [E=INFO_SCRIPT_URI:%{SCRIPT_URI},NE]
RewriteRule .* - [E=INFO_SCRIPT_URL:%{SCRIPT_URL},NE]
RewriteRule .* - [E=INFO_SCRIPT_USER:%{SCRIPT_USER},NE]
RewriteRule .* - [E=INFO_SERVER_ADDR:%{SERVER_ADDR},NE]
RewriteRule .* - [E=INFO_SERVER_ADMIN:%{SERVER_ADMIN},NE]
RewriteRule .* - [E=INFO_SERVER_NAME:%{SERVER_NAME},NE]
RewriteRule .* - [E=INFO_SERVER_PORT:%{SERVER_PORT},NE]
RewriteRule .* - [E=INFO_SERVER_PROTOCOL:%{SERVER_PROTOCOL},NE]
RewriteRule .* - [E=INFO_SERVER_SIGNATURE:%{SERVER_SIGNATURE},NE]
RewriteRule .* - [E=INFO_SERVER_SOFTWARE:%{SERVER_SOFTWARE},NE]
RewriteRule .* - [E=INFO_THE_REQUEST:%{THE_REQUEST},NE]
RewriteRule .* - [E=INFO_TIME:%{TIME},NE]
RewriteRule .* - [E=INFO_TIME_DAY:%{TIME_DAY},NE]
RewriteRule .* - [E=INFO_TIME_HOUR:%{TIME_HOUR},NE]
RewriteRule .* - [E=INFO_TIME_MIN:%{TIME_MIN},NE]
RewriteRule .* - [E=INFO_TIME_MON:%{TIME_MON},NE]
RewriteRule .* - [E=INFO_TIME_SEC:%{TIME_SEC},NE]
RewriteRule .* - [E=INFO_TIME_WDAY:%{TIME_WDAY},NE]
RewriteRule .* - [E=INFO_TIME_YEAR:%{TIME_YEAR},NE]
RewriteRule .* - [E=INFO_TZ:%{TZ},NE]
RewriteRule .* - [E=INFO_UNIQUE_ID:%{UNIQUE_ID},NE]
&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_CHARSET "%{INFO_HTTP_ACCEPT_CHARSET}e"
RequestHeader set INFO_HTTP_ACCEPT_ENCODING "%{INFO_HTTP_ACCEPT_ENCODING}e"
RequestHeader set INFO_HTTP_ACCEPT_LANGUAGE "%{INFO_HTTP_ACCEPT_LANGUAGE}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_MOD_SECURITY_MESSAGE "%{INFO_HTTP_MOD_SECURITY_MESSAGE}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_PHP_SELF "%{INFO_PHP_SELF}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_TIME "%{INFO_REQUEST_TIME}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"
</pre>








<h2><a id="decoded"></a>Mod_Rewrite Variables Decoded!</h2>
<pre>
[API_VERSION] =&gt; 20020903:12
[AUTH_TYPE] =&gt; Digest
[DOCUMENT_ROOT] =&gt; /home/user/www_root/askapache.com
[HTTPS] =&gt; off
[HTTP_ACCEPT] =&gt; text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
[HTTP_COOKIE] =&gt; PHPSESSID=752ee6d56e15f305233e30045987e5ce568c034; __qca=1176541225-59967328-5223185;
[HTTP_HOST] =&gt; www.askapache.com
[HTTP_REFERER] =&gt; http://www.askapache.com/protest/index.php?askapache=awesomeness&amp;you=rock
[HTTP_USER_AGENT] =&gt; Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16
[IS_SUBREQ] =&gt; false
[QUERY_STRING] =&gt; e=404
[REMOTE_ADDR] =&gt; 22.162.144.211
[REMOTE_HOST] =&gt; 22.162.144.211
[REMOTE_PORT] =&gt; 4511
[REMOTE_USER] =&gt; administrator
[REQUEST_FILENAME] =&gt; /home/user/www_root/askapache.com/protest/index.php
[REQUEST_METHOD] =&gt; GET
[REQUEST_URI] =&gt; /protest/index.php
[SCRIPT_FILENAME] =&gt; /home/user/www_root/askapache.com/protest/index.php
[SCRIPT_GROUP] =&gt; daemonu
[SCRIPT_USER] =&gt; askapache
[SERVER_ADDR] =&gt; 208.113.134.190
[SERVER_ADMIN] =&gt; webmaster@askapache.com
[SERVER_NAME] =&gt; www.askapache.com
[SERVER_PORT] =&gt; 80
[SERVER_PROTOCOL] =&gt; HTTP/1.1
[SERVER_SOFTWARE] =&gt; 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
[THE_REQUEST] =&gt; GET /protest/adf HTTP/1.1
[TIME] =&gt; 20080820014309
[TIME_DAY] =&gt; 20
[TIME_HOUR] =&gt; 01
[TIME_MIN] =&gt; 43
[TIME_MON] =&gt; 08
[TIME_SEC] =&gt; 09
[TIME_WDAY] =&gt; 3
[TIME_YEAR] =&gt; 2008
</pre>


<h3>Request using HTTPS</h3>
<pre>
[API_VERSION] =&gt; 20020903:12
[AUTH_TYPE] =&gt; Digest
[DOCUMENT_ROOT] =&gt; /home/user/www_root/askapache.com
[HTTPS] =&gt; on
[HTTP_ACCEPT] =&gt; text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
[HTTP_COOKIE] =&gt; PHPSESSID=752ee6d56e15f305233e30045987e5ce568c034; __qca=1176541225-59967328-5223185;
[HTTP_HOST] =&gt; www.askapache.com
[HTTP_REFERER] =&gt; http://www.askapache.com/protest/index.php?askapache=awesomeness&amp;you=rock
[HTTP_USER_AGENT] =&gt; Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16
[IS_SUBREQ] =&gt; false
[QUERY_STRING] =&gt; hi=you&amp;whats=&amp;amp;you
[REMOTE_ADDR] =&gt; 22.162.144.211
[REMOTE_HOST] =&gt; 22.162.144.211
[REMOTE_PORT] =&gt; 4605
[REMOTE_USER] =&gt; administrator
[REQUEST_FILENAME] =&gt; /home/user/www_root/askapache.com/protest/index.php
[REQUEST_METHOD] =&gt; GET
[REQUEST_URI] =&gt; /protest/index.php
[SCRIPT_FILENAME] =&gt; /home/user/www_root/askapache.com/protest/index.php
[SCRIPT_GROUP] =&gt; daemonu
[SCRIPT_USER] =&gt; askapache
[SERVER_ADDR] =&gt; 208.113.134.190
[SERVER_ADMIN] =&gt; webmaster@askapache.com
[SERVER_NAME] =&gt; www.askapache.com
[SERVER_PORT] =&gt; 443
[SERVER_PROTOCOL] =&gt; HTTP/1.1
[SERVER_SOFTWARE] =&gt; 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
[THE_REQUEST] =&gt; GET /protest/index.php?hi=you&amp;whats=&amp;amp;you HTTP/1.1
[TIME] =&gt; 20080820015016
[TIME_DAY] =&gt; 20
[TIME_HOUR] =&gt; 01
[TIME_MIN] =&gt; 50
[TIME_MON] =&gt; 08
[TIME_SEC] =&gt; 16
[TIME_WDAY] =&gt; 3
[TIME_YEAR] =&gt; 2008
</pre>





<h2>Emulating ErrorDocuments with Mod_Rewrite</h2>
<p>The ErrorDocument directive is helpful because an errordocument is called differently then a normal file, and it contains special variables to help an admin debug.</p>
<p>I've wanted to use a RewriteCond + a RewriteRule to cause an Apache ErrorDocument to be displayed for a long time... I finally figured it out.  Simply use the <a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html">HTTP STATUS CODE trick</a> in combination with a simple RewriteRule to trigger an Apache ErrorDocument.</p>

<p>This code emulates the internal 404 process Apache goes through.. If the file is not found it requests the /test/trigger-error/404 internally which triggers the 404 ErrorDocument.</p>
<pre>
ErrorDocument 404 /test/errordocument/404.html
Redirect 404 /test/trigger-error/404
&nbsp;
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:REDIRECT_STATUS} !=404
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /test/trigger-error/404 [L]
</pre>

<p><strong>Big Deal..</strong> you might say... well consider that this works with any status code, and using this method you now have the power to trigger any errordocument page based on any kind of rewritecond.  I'll be writing about some practical uses for this powerful method in the coming weeks, but heres a good example now so you can see how it can be used.</p>

<p>This bit of code Triggers the <a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-505">505 HTTP Version Not Supported</a> When a request is made to the server with a protocol other than 1.1.</p>
<pre>
ErrorDocument 505 /test/errordocument/505.html
Redirect 505 /test/trigger-error/505
&nbsp;
RewriteEngine On
RewriteBase /
&nbsp;
RewriteCond %{ENV:REDIRECT_STATUS} !=505
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ /.*\ HTTP/(0\.9|1\.0|1\.1) [NC]
RewriteRule .* /test/trigger-error/505 [L]
</pre>



<p class="anote"><strong>YES!</strong> I realize I didn't explain that very well, I didn't realize it was that complicated..  I wanted to go into how to use these advanced tricks and methods to achieve some really cool stuff, but explaining just this little bit took me awhile and I'm out of page space!<br /><br />So play around with this and I'll post back some of the <em>untapped sicknesses</em> you can give a website with such powerful methods at your disposal.</p>







<blockquote cite="http://httpd.apache.org/">
<cite><strong>Ralf S. Engelschall</strong></cite>
<pre>
/*
 *  URL Rewriting Module
 *
 *  This module uses a rule-based rewriting engine (based on a
 *  regular-expression parser) to rewrite requested URLs on the fly.
 *
 *  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.
 *
 *  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.
 *
 *  This module was originally written in April 1996 and
 *  gifted exclusively to the The Apache Software Foundation in July 1997 by
 *
 *      Ralf S. Engelschall
 *      rse engelschall.com
 *      www.engelschall.com
 */
</pre>
</blockquote><p><a href="http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html"></a><a href="http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html">Crazy Advanced Mod_Rewrite Debug Tutorial</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html/feed</wfw:commentRss>
		<slash:comments>35</slash:comments>
		</item>
		<item>
		<title>THE Ultimate Htaccess</title>
		<link>http://www.askapache.com/htaccess/htaccess.html</link>
		<comments>http://www.askapache.com/htaccess/htaccess.html#comments</comments>
		<pubDate>Sat, 10 Jan 2009 13:05:32 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Htaccess]]></category>

		<guid isPermaLink="false">http://www.askapache.com.com/htaccess/htaccesselite-ultimate-htaccess-article.html</guid>
		<description><![CDATA[<p><strong>Skip this - still under edit</strong></p>
<p>I discovered these tips and tricks mostly while working as a network security penetration specialist hired to find security holes in web hosting environments.  Shared hosting is the most common and cheapest form of web-hosting where multiple customers are placed on a single machine and "share" the resources (CPU/RAM/SPACE).  The machines are configured to basically ONLY do HTTP and FTP.  No shells or any interactive logins, no ssh, just FTP access.  That is when I started examining htaccess files in great detail and learned about the incredible untapped power of htaccess.  For 99% of the worlds best Apache admins, they don't use .htaccess much, if AT ALL.  It's much easier, safer, and faster to configure Apache using the httpd.conf file instead.  However, this file is almost never readable on shared-hosts, and I've never seen it writable.  So the only avenue left for those on shared-hosting was and is the .htaccess file, and holy freaking fiber-optics.. it's almost as powerful as httpd.conf itself!<br /><br />Most all .htaccess code works in the httpd.conf file, but not all httpd.conf code works in .htaccess files, around 50%.  So all the best Apache admins and programmers never used .htaccess files.  There was no incentive for those with access to httpd.conf to use htaccess, and the gap grew.  It's common to see "computer gurus" on forums and mailing lists rail against all uses and users of .htaccess files, smugly announcing the well known problems with .htaccess files compared with httpd.conf - I wonder if these "gurus" know the history of the htaccess file, like it's use in the earliest versions of the HTTP Server- NCSA's HTTPd, which BTW, became known as Apache HTTP.  So you could easily say that htaccess files predates Apache itself.<br /><br />Once I discovered what .htaccess files could do towards helping me enumerate and exploit security vulnerabilities even on big shared-hosts I focused all my research into .htaccess files, meaning I was reading the venerable Apache HTTP Source code 24/7!  I compiled every released version of the Apache Web Server, ever, even NCSA's, and focused on enumerating the most powerful htaccess directives. Good times! Because my focus was on protocol/file/network vulnerabilites instead of web dev I built up a nice toolbox of htaccess tricks to do unusual things.  When I switched over to webdev in 2005 I started using htaccess for websites, not research.  I documented most of my favorites and rewrote the htaccess guide for webdevelopers.  After some great encouragement on various forums and nets I decided to start a blog to share my work with everyone, AskApache.com was registered, I published my guide, and it was quickly plagiarized and scraped all over the net.  Information is freedom, and freedom is information, so this blog has the least restrictive copyright for you.  Feel free to modify, copy, republish, sell, or use anything on this site ;)</p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/htaccess/htaccess.html"></a><a href="http://www.askapache.com/htaccess/htaccess.html"><cite>AskApache.com</cite></a></p><p><dfn title="HyperText Access">.htaccess</dfn> is a very ancient configuration file that controls the Web Server running your website, and is one of the most powerful configuration files you will ever come across. Htaccess has the ability to control access of the <acronym title="World Wide Web">WWW</acronym>'s HyperText Transfer Protocol (<acronym title="HyperText Transfer Protocol">HTTP</acronym>) using Password Protection, 301 Redirects, rewrites, and much much more.  This is because this configuration file was coded in the earliest days of the web (HTTP), for one of the first Web Servers ever!  Eventually these Web Servers (configured with htaccess) became known as the World Wide Web, and eventually grew into the Internet we use today.</p>
<p><a class="IFL" href="/htaccess/htaccess.html"><img src="http://uploads.askapache.com/2008/08/htaccess-up.png" alt=".htaccess file tutorial" title=".htaccess file tutorial" width="141" height="144" /></a>This is not an <em>introduction to .htaccess</em>&hellip; This is the evolution of the best of the best <tt>.htaccess</tt> on the planet.  Its changed over the years with more and better <strong>.htaccess tricks</strong> using real <a href="#htaccess-code-examples">.htaccess example code</a>.  I add my favorite htaccess-related links and sites, results from my <a href="#best-htaccess-articles">htaccess research</a>, and frequently update this article.<br /><br />You've come to the right place if you are looking to acquire <strong>mad skills</strong> for using .htaccess files.<br /><br />Originally (2003) this guide was known in certain hacker circles and hidden corners of the net as an <em>ultimate .htaccess</em> due to the powerful <strong>htaccess tricks</strong> and tips to bypass security on a webhost, and also because many of the tricks and <a href="#htaccess-code-examples">examples</a> were pretty impressive back then in that group.<br class="C" /></p>

<h2>AskApache Htaccess Journey</h2>
<p><strong>Skip this - still under edit</strong></p>
<p>I discovered these tips and tricks mostly while working as a network security penetration specialist hired to find security holes in web hosting environments.  Shared hosting is the most common and cheapest form of web-hosting where multiple customers are placed on a single machine and "share" the resources (CPU/RAM/SPACE).  The machines are configured to basically ONLY do HTTP and FTP.  No shells or any interactive logins, no ssh, just FTP access.  That is when I started examining htaccess files in great detail and learned about the incredible untapped power of htaccess.  For 99% of the worlds best Apache admins, they don't use .htaccess much, if AT ALL.  It's much easier, safer, and faster to configure Apache using the httpd.conf file instead.  However, this file is almost never readable on shared-hosts, and I've never seen it writable.  So the only avenue left for those on shared-hosting was and is the .htaccess file, and holy freaking fiber-optics.. it's almost as powerful as httpd.conf itself!<br /><br />Most all .htaccess code works in the httpd.conf file, but not all httpd.conf code works in .htaccess files, around 50%.  So all the best Apache admins and programmers never used .htaccess files.  There was no incentive for those with access to httpd.conf to use htaccess, and the gap grew.  It's common to see "computer gurus" on forums and mailing lists rail against all uses and users of .htaccess files, smugly announcing the well known problems with .htaccess files compared with httpd.conf - I wonder if these "gurus" know the history of the htaccess file, like it's use in the earliest versions of the HTTP Server- NCSA's HTTPd, which BTW, became known as Apache HTTP.  So you could easily say that htaccess files predates Apache itself.<br /><br />Once I discovered what .htaccess files could do towards helping me enumerate and exploit security vulnerabilities even on big shared-hosts I focused all my research into .htaccess files, meaning I was reading the venerable Apache HTTP Source code 24/7!  I compiled every released version of the Apache Web Server, ever, even NCSA's, and focused on enumerating the most powerful htaccess directives. Good times! Because my focus was on protocol/file/network vulnerabilites instead of web dev I built up a nice toolbox of htaccess tricks to do unusual things.  When I switched over to webdev in 2005 I started using htaccess for websites, not research.  I documented most of my favorites and rewrote the htaccess guide for webdevelopers.  After some great encouragement on various forums and nets I decided to start a blog to share my work with everyone, AskApache.com was registered, I published my guide, and it was quickly plagiarized and scraped all over the net.  Information is freedom, and freedom is information, so this blog has the least restrictive copyright for you.  Feel free to modify, copy, republish, sell, or use anything on this site ;)</p>



<h2 class="htaccess" id="h21adf" style="font-weight:bold;">Htaccess - Evolved</h2>
<p>The Hyper Text Transfer Protocol (HTTP) was initiated at the CERN in Geneve (Switzerland), where it emerged (together with the HTML presentation language) from the need to exchange scientific information on a computer network in a simple manner. The first public HTTP implementation only allowed for plain text information, and almost instantaneously became a replacement of the GOPHER service. One of the first text-based browsers was LYNX which still exists today; a graphical HTTP client appeared very quickly with the name NCSA Mosaic. Mosaic was a popular browser back in 1994. Soon the need for a more rich multimedia experience was born, and the markup language provided support for a growing multitude of media types.</p>
<p>Htaccess file know-how will do several things for you:</p>
<ul><li>Make your website noticeably faster.</li><li>Allow you to debug your server with ease.</li><li>Make your life easier and more rewarding.</li><li>Allow you to work faster and more productively.</li></ul>


<h3>What Is .htaccess</h3>
<p>Specifically, <kbd>.htaccess</kbd> is the default file name of a special configuration file that provides a number of <a href="#htaccess-directives">directives</a> (commands) for controlling and configuring the <a href="http://httpd.apache.org/" title="open-source HTTP server running the WWW">Apache Web Server</a>, and also to control and configure <a href="#htaccess-modules">modules</a> that can be built into the Apache installation, or included at run-time like mod_rewrite (for htaccess rewrite), mod_alias (for htaccess redirects), and mod_ssl (for controlling SSL connections).</p>
<p><strong>Htaccess</strong> allows for decentralized management of Web Server configurations which makes life very easy for web hosting companies and especially their savvy consumers.  They set up and run "server farms" where many hundreds and thousands of web hosting customers are all put on the same Apache Server.  This type of hosting is called "virtual hosting" and without .htaccess files would mean that every customer must use the same exact settings as everyone else on their segment.  So that is why any half-decent web host allows/enables <em>(DreamHost, Powweb, MediaTemple, GoDaddy) .htaccess files</em>, though few people are aware of it.  Let's just say that if I was a customer on your server-farm, and .htaccess files were enabled, my websites would be a LOT faster than yours, as these configuration files allow you to fully take advantage of and utilize the resources allotted to you by your host.  If even 1/10 of the sites on a server-farm took advantage of what they are paying for, the providers would go out of business.</p>

<blockquote cite="http://httpd.apache.org/docs/1.3/misc/API.html">
<p>One of the design goals for this server was to maintain external compatibility with the NCSA 1.3 server --- that is, to read the same configuration files, to process all the directives therein correctly, and in general to be a drop-in replacement for NCSA. On the other hand, another design goal was to move as much of the server's functionality into modules which have as little as possible to do with the monolithic server core. The only way to reconcile these goals is to move the handling of most commands from the central server into the modules.</p>
<p>However, just giving the modules command tables is not enough to divorce them completely from the server core. The server has to remember the commands in order to act on them later. That involves maintaining data which is private to the modules, and which can be either per-server, or per-directory. Most things are per-directory, including in particular access control and authorization information, but also information on how to determine file types from suffixes, which can be modified by AddType and DefaultType directives, and so forth. In general, the governing philosophy is that anything which can be made configurable by directory should be; per-server information is generally used in the standard set of modules for information like Aliases and Redirects which come into play before the request is tied to a particular place in the underlying file system.</p>
<p>Another requirement for emulating the NCSA server is being able to handle the <strong>per-directory configuration files, generally called .htaccess files</strong>, though even in the NCSA server they can contain directives which have nothing at all to do with access control. Accordingly, after URI -> filename translation, but before performing any other phase, the server walks down the directory hierarchy of the underlying filesystem, following the translated pathname, to read any .htaccess files which might be present. The information which is read in then has to be merged with the applicable information from the server's own config files (either from the <code>&lt;directory&gt;</code> sections in access.conf, or from defaults in srm.conf, which actually behaves for most purposes almost exactly like <code>&lt;directory /&gt;</code>).</p>
<p>Finally, after having served a request which involved <strong>reading .htaccess files</strong>, we need to discard the storage allocated for handling them. That is solved the same way it is solved wherever else similar problems come up, by tying those structures to the per-transaction resource pool.</p>
</blockquote>


<h4 class="tic">Creating Htaccess Files</h4>
<p><a class="IFL" href="http://uploads.askapache.com/2009/01/htaccess-explorer.png"><img src="http://uploads.askapache.com/2009/01/htaccess-explorer.png" alt="What an Htaccess File Looks Like in Windows Explorer" title="What an Htaccess File Looks Like in Windows Explorer" width="243" height="322" /></a>Htaccess files use the default filename "<code>.htaccess</code>" but any unix-style file name can be specified from the <a href="#httpd-config-examples">main server config</a> using the <code>AccessFileName</code> directive.  The file isn't <code>.htaccess.txt</code>, its literally just named <code>.htaccess</code>.<br class="C" /></p>
<p><a class="IFR" href="http://uploads.askapache.com/2009/01/viewing-htaccess-files.png"><img src="http://uploads.askapache.com/2009/01/viewing-htaccess-files.png" alt="View .htaccess files" title="View .htaccess files" width="386" height="287" /></a>In a Windows Environment like the one I use for work, you can change how Windows opens and views .htaccess files by modifying the Folder Options in explorer.  As you can see, on my computer files ending in .htaccess are recognized as having the HTACCESS extension and are handled/opened by Adobe Dreamweaver CS4.<br class="C" /></p>

<h4>Htaccess Scope</h4>
<p>Unlike the main server configuration files like <a href="#httpd-config-examples">httpd.conf</a>, <strong>Htaccess files are read on every request</strong> therefore changes in these files take immediate effect.  Apache searches all directories and subdirectories that are htaccess-enabled for an .htaccess file which results in performance loss due to file accesses. I've never noticed a performance loss but OTOH, I know how to use them.  If you do have access to your main server configuration file, you should of course use that instead, and lucky for you ALL the .htaccess tricks and examples can be used there as well (just not vice versa).</p>


<h3>Htaccess File Syntax</h3>
<p>Htaccess files follow the same syntax as the main Apache configuration files, for powerusers here's an <a href='http://uploads.askapache.com/2009/01/apache.vim'>apache.vim</a> for VI. The one main difference is the <dfn title="Whether the directive is allowed in .htaccess files">context</dfn> of the directive, which means whether or not that directive is ALLOWED to be used inside of an .htaccess file.  Htaccess files are incredibly powerful, and can also be very dangerous as some directives allowed in the main configuration files would allow users/customers to completely bypass security/bandwidth-limits/resource-limits/file-permissions, etc..  About 1/4 of all Apache directives cannot be used inside an .htaccess file (also known as a per-directory context config).  The Apache Developers are well-regarded throughout the world as being among some of the best programmers, ever.  To enable a disallowed directive inside a .htaccess file would require modifying the source code and re-compiling the server (which they allow and encourage if you are the owner/admin).  Here's a taste of that famous Apache source code that builds the directives allowed in .htaccess file context, the key that tells whether its enabled in .htaccess context is the DIR_CMD_PERMS and then the OR_FILEINFO, which means a directive is enabled dependent on the AllowOverride directive that is only allowed in the main config.  First Apache 1.3.0, then Apache 2.2.10</p>

<h5>mod_autoindex</h5>
<pre>
AddIcon, add_icon, BY_PATH, DIR_CMD_PERMS, an icon URL followed by one or more filenames
AddIconByType, add_icon, BY_TYPE, DIR_CMD_PERMS, an icon URL followed by one or more MIME types
AddIconByEncoding, add_icon, BY_ENCODING, DIR_CMD_PERMS, an icon URL followed by one or more content encodings
AddAlt, add_alt, BY_PATH, DIR_CMD_PERMS, alternate descriptive text followed by one or more filenames
AddAltByType, add_alt, BY_TYPE, DIR_CMD_PERMS, alternate descriptive text followed by one or more MIME types
AddAltByEncoding, add_alt, BY_ENCODING, DIR_CMD_PERMS, alternate descriptive text followed by one or more content encodings
IndexOptions, add_opts, DIR_CMD_PERMS, RAW_ARGS, one or more index options
IndexIgnore, add_ignore, DIR_CMD_PERMS, ITERATE, one or more file extensions
AddDescription, add_desc, BY_PATH, DIR_CMD_PERMS, Descriptive text followed by one or more filenames
HeaderName, add_header, DIR_CMD_PERMS, TAKE1, a filename
ReadmeName, add_readme, DIR_CMD_PERMS, TAKE1, a filename
FancyIndexing, fancy_indexing, DIR_CMD_PERMS, FLAG, Limited to &#039;on&#039; or &#039;off&#039; (superseded by IndexOptions FancyIndexing)
DefaultIcon, ap_set_string_slot, (void *) XtOffsetOf(autoindex_config_rec, default_icon), DIR_CMD_PERMS, TAKE1, an icon URL
</pre>

<h5>mod_rewrite</h5>
<pre>
// mod_rewrite
RewriteEngine, cmd_rewriteengine, OR_FILEINFO, On or Off to enable or disable (default)
RewriteOptions, cmd_rewriteoptions, OR_FILEINFO, List of option strings to set
RewriteBase, cmd_rewritebase, OR_FILEINFO, the base URL of the per-directory context
RewriteCond, cmd_rewritecond, OR_FILEINFO, an input string and a to be applied regexp-pattern
RewriteRule, cmd_rewriterule, OR_FILEINFO, an URL-applied regexp-pattern and a substitution URL
RewriteMap, cmd_rewritemap, RSRC_CONF, a mapname and a filename
RewriteLock, cmd_rewritelock, RSRC_CONF, the filename of a lockfile used for inter-process synchronization
RewriteLog, cmd_rewritelog, RSRC_CONF, the filename of the rewriting logfile
RewriteLogLevel, cmd_rewriteloglevel, RSRC_CONF, the level of the rewriting logfile verbosity (0=none, 1=std, .., 9=max)
RewriteLog, fake_rewritelog, RSRC_CONF, [DISABLED] the filename of the rewriting logfile
RewriteLogLevel, fake_rewritelog, RSRC_CONF, [DISABLED] the level of the rewriting logfile verbosity
</pre>



<h3>Htaccess Directives</h3>
<p><strong>Don't ask why</strong>, but I personally downloaded each major/beta release of the Apache HTTPD source code from version 1.3.0 to version 2.2.10 (<dfn title="1.3.0, 1.3.1, 1.3.11, 1.3.12, 1.3.14, 1.3.17, 1.3.19, 1.3.2, 1.3.20, 1.3.22, 1.3.23, 1.3.24, 1.3.27, 1.3.28, 1.3.29, 1.3.3, 1.3.31, 1.3.32, 1.3.33, 1.3.34, 1.3.35, 1.3.36, 1.3.37, 1.3.39, 1.3.4, 1.3.41, 1.3.6, 1.3.9, 2.0.35, 2.0.36, 2.0.39, 2.0.40, 2.0.42, 2.0.43, 2.0.44, 2.0.45, 2.0.46, 2.0.47, 2.0.48, 2.0.49, 2.0.50, 2.0.51, 2.0.52, 2.0.53, 2.0.54, 2.0.55, 2.0.58, 2.0.59, 2.0.61, 2.0.63, 2.1.3-beta, 2.1.6-alpha, 2.1.7-beta, 2.1.8-beta, 2.1.9-beta, 2.2.0, 2.2.2, 2.2.3, 2.2.4, 2.2.6, 2.2.8, 2.2.9, 2.2.10">all 63 Apache versions</dfn>!), then I <strong>configured and compiled each version for a custom HTTPD installation built from source</strong>. This allowed me to find <strong><a href="#htaccess-directives-list">every directive allowed in .htaccess files</a></strong> for each particular version, which has never been done before, or since. <strong>YES!</strong> <em>I think that is so cool..</em></p>
<p><strong>An .htaccess directive</strong> is basically a command that is specific to a module or builtin to the core that performs a specific task or sets a specific setting for how Apache serves your WebSite.  Directives placed in Htaccess files <strong>apply to the directory they are in, and all sub-directories</strong>.  Here's the 3 top links (<em>official Apache Docs</em>) you will repeatedly use, bookmark/print/save them.</p>
<p><a href="http://uploads.askapache.com/2008/08/htaccess-up1.png"><img src="http://uploads.askapache.com/2008/08/htaccess-up1-350x178.png" alt="htaccess Context Legend" title="htaccess-up1" width="350" height="178" /></a></p>
<ol><li><a href="http://httpd.apache.org/docs/trunk/mod/directive-dict.html">Terms Used to Describe Directives</a></li><li><a href="http://httpd.apache.org/docs/trunk/mod/directives.html">Official List of Apache Directives</a></li><li><a href="http://httpd.apache.org/docs/trunk/mod/quickreference.html">Directive Quick-Reference -- with Context</a></li></ol>
<hr class="C" />


<h3>Litespeed Htaccess support</h3>
<p>Unlike other lightweight web servers, Apache compatible per-directory configuration overridden is fully supported by <a href="http://www.litespeedtech.com/">LiteSpeed Web Server</a>. With .htacess you can change configurations for any directory under document root on-the-fly, which in most cases is a mandatory feature in shared hosting environment.   It is worth noting that <em>enabling .htaccess support in LiteSpeed</em> Web Server will not degrade server's performance, comparing to Apache's 40% drop in performance. </p>







<h2>Main Server Config Examples</h2>
<p>Now lets take a look at some htaccess examples to get a feel for the syntax and some general ideas at the capabilities.  Some of the best examples for .htaccess files are included with Apache for <a href="http://httpd.apache.org/docs/trunk/configuring.html">main server config</a> files, so lets take a quick look at a couple of them on our way down to the actual .htaccess examples further down the page (this site has thousands, take your time).  As you can see, the basic syntax is a line starting with # is a comment, everything else are directives followed by the directive argument.</p>
<p><strong><a href="http://uploads.askapache.com/2008/08/httpd-multilang-errordocconf.in">httpd-multilang-errordoc.conf</a></strong>: The configuration below implements multi-language error documents through content-negotiation</p>
<pre>
Options IncludesNoExec
AddOutputFilter Includes html
AddHandler type-map var
LanguagePriority en cs de es fr it ja ko nl pl pt-br ro sv tr
ForceLanguagePriority Prefer Fallback
ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var
ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var
ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var
</pre>
<p><strong><a href="http://uploads.askapache.com/2008/08/httpd-manualconf.in">httpd-manual.conf</a></strong>: Provide local access to the server documentation on your server</p>
<pre>
SetEnvIf Request_URI ^/manual/(de|en|es|fr|ja|ko|pt-br|ru|tr)/ prefer-language=$1
RedirectMatch 301 ^/manual(?:/(de|en|es|fr|ja|ko|pt-br|ru|tr)){2, }(/.*)?$ /manual/$1$2
LanguagePriority en de es fr ja ko pt-br ru tr
ForceLanguagePriority Prefer Fallback
</pre>
<p><strong><a href="http://uploads.askapache.com/2008/08/httpd-languagesconf.in">httpd-languages.conf</a></strong>: Settings for hosting different languages.</p>
<pre>
DefaultLanguage en
AddLanguage ca .ca
# Just list the languages in decreasing order of preference.
LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv tr zh-CN zh-TW
# Commonly used filename extensions to character sets.
AddCharset us-ascii.ascii .us-ascii
AddCharset ISO-8859-1  .iso8859-1  .latin1
</pre>
<p><strong><a href="http://uploads.askapache.com/2008/08/httpd-autoindexconf.in">httpd-autoindex.conf</a></strong>: Directives controlling the display of server-generated directory listings.</p>
<pre>
# IndexOptions: Controls the appearance of server-generated directory listings.
IndexOptions FancyIndexing HTMLTable VersionSort
# AddIcon* directives tell the server which icon to show for different files or filename extensions.
AddIconByEncoding (CMP, /icons/compressed.gif) x-compress x-gzip
AddIconByType (TXT, /icons/text.gif) text/*
AddIcon /icons/folder.gif ^^DIRECTORY^^
# DefaultIcon is which icon to show for files which do not have an icon explicitly set.
DefaultIcon /icons/unknown.gif
# AddDescription allows you to place a short description after a file in server-generated indexes.
AddDescription "GZIP compressed document" .gz
# ReadmeName is the name of the README file the server will look for by default, and append to directory listings.
ReadmeName README.html
# HeaderName is the name of a file which should be prepended to directory indexes.
HeaderName HEADER.html
</pre>
<p>Here are the rest of them if you wanna take a look.  (<a href="http://uploads.askapache.com/2008/08/httpd-mpmconf.in" title="Server-Pool Management (MPM specific)">httpd-mpm.conf</a>, <a href="http://uploads.askapache.com/2008/08/httpd-defaultconf.in" title="This configuration file reflects default settings for Apache HTTP Server">httpd-default.conf</a>, <a href="http://uploads.askapache.com/2008/08/httpd-sslconf.in" title="Contains the configuration directives to instruct the server how to serve pages over an https connection">httpd-ssl.conf</a>, <a href="http://uploads.askapache.com/2008/08/httpd-infoconf.in" title="Get information about the requests being processed by the server and the configuration of the server">httpd-info.conf</a>, <a href="http://uploads.askapache.com/2008/08/httpd-vhostsconf.in" title="If you want to maintain multiple domains/hostnames on your machine">httpd-vhosts.conf</a>, <a href="http://uploads.askapache.com/2008/08/httpd-davconf.in" title="Distributed authoring and versioning (WebDAV)">httpd-dav.conf</a>)</p>
<hr class="C" />







<h2>Example .htaccess Files</h2>
<p>Here are some samples and examples taken from different .htaccess files I've used over the years.  Specific solutions are farther down on this page and throughout the site.</p>
<pre>
# Set the Time Zone of your Server
SetEnv TZ America/Indianapolis
# ServerAdmin:  This address appears on some server-generated pages, such as error documents.
SetEnv SERVER_ADMIN webmaster@askapache.com
# Possible values for the Options directive are "None", "All", or any combination of:
#  Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
Options -ExecCGI -MultiViews -Includes -Indexes FollowSymLinks
# DirectoryIndex: sets the file that Apache will serve if a directory is requested.
DirectoryIndex index.html index.php /index.php
#
# 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
#
# 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 .inc
# Commonly used filename extensions to character sets.
AddDefaultCharset UTF-8
# AddType allows you to add to or override the MIME configuration
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
# AddEncoding allows you to have certain browsers uncompress information on the fly. Note: Not all browsers support this.
AddEncoding x-compress .Z
AddEncoding x-gzip .gz .tgz
# DefaultType: the default MIME type the server will use for a document.
DefaultType text/html
#
# 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
</pre>
<pre>
## MAIN DEFAULTS
Options +ExecCGI -Indexes
DirectoryIndex index.html index.htm index.php
DefaultLanguage en-US
AddDefaultCharset UTF-8
ServerSignature Off
## ENVIRONMENT VARIABLES
SetEnv PHPRC /webroot/includes
SetEnv TZ America/Indianapolis
&nbsp;
SetEnv SERVER_ADMIN webmaster@askapache.com
## MIME TYPES
AddType video/x-flv .flv
AddType application/x-shockwave-flash .swf
AddType image/x-icon .ico
## FORCE FILE TO DOWNLOAD INSTEAD OF APPEAR IN BROWSER
# http://www.htaccesselite.com/addtype-addhandler-action-vf6.html
AddType application/octet-stream .mov .mp3 .zip
## ERRORDOCUMENTS
# http://askapache.com/htaccess/apache-status-code-headers-errordocument.html
ErrorDocument 400 /e400/
ErrorDocument 401 /e401/
ErrorDocument 402 /e402/
ErrorDocument 403 /e403/
ErrorDocument 404 /e404/
#
# Handlers be builtin, included in a module, or added with Action directive
# default-handler: default, handles static content (core)
#   send-as-is: Send file with HTTP headers (mod_asis)
#   cgi-script: treat file as CGI script (mod_cgi)
#    imap-file: Parse as an imagemap rule file (mod_imap)
#   server-info: Get server config info (mod_info)
#  server-status: Get server status report (mod_status)
#    type-map: type map file for content negotiation (mod_negotiation)
#  fastcgi-script: treat file as fastcgi script (mod_fastcgi)
#
# http://www.askapache.com/php/custom-phpini-tips-and-tricks.html
## PARSE AS CGI
AddHandler cgi-script .cgi .pl .spl
## RUN PHP AS APACHE MODULE
AddHandler application/x-httpd-php .php .htm
## RUN PHP AS CGI
AddHandler php-cgi .php .htm
## CGI PHP WRAPPER FOR CUSTOM PHP.INI
AddHandler phpini-cgi .php .htm
Action phpini-cgi /cgi-bin/php5-custom-ini.cgi
## FAST-CGI SETUP WITH PHP-CGI WRAPPER FOR CUSTOM PHP.INI
AddHandler fastcgi-script .fcgi
AddHandler php-cgi .php .htm
Action php-cgi /cgi-bin/php5-wrapper.fcgi
## CUSTOM PHP CGI BINARY SETUP
AddHandler php-cgi .php .htm
Action php-cgi /cgi-bin/php.cgi
## PROCESS SPECIFIC FILETYPES WITH CGI-SCRIPT
Action image/gif /cgi-bin/img-create.cgi
## CREATE CUSTOM HANDLER FOR SPECIFIC FILE EXTENSIONS
AddHandler custom-processor .ssp
Action custom-processor /cgi-bin/myprocessor.cgi
### HEADER CACHING
# http://www.askapache.com/htaccess/speed-up-sites-with-htaccess-caching.html
&lt;FilesMatch "\.(flv|gif|jpg|jpeg|png|ico)$"&gt;
Header set Cache-Control "max-age=2592000"
&lt;/FilesMatch&gt;
&lt;FilesMatch "\.(js|css|pdf|swf)$"&gt;
Header set Cache-Control "max-age=604800"
&lt;/FilesMatch&gt;
&lt;FilesMatch "\.(html|htm|txt)$"&gt;
Header set Cache-Control "max-age=600"
&lt;/FilesMatch&gt;
&lt;FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$"&gt;
Header unset Cache-Control
&lt;/FilesMatch&gt;
## ALTERNATE EXPIRES CACHING
# htaccesselite.com/d/use-htaccess-to-speed-up-your-site-discussion-vt67.html
ExpiresActive On
ExpiresDefault A604800
ExpiresByType image/x-icon A2592000
ExpiresByType application/x-javascript A2592000
ExpiresByType text/css A2592000
ExpiresByType text/html A300
&lt;FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$"&gt;
ExpiresActive Off
&lt;/FilesMatch&gt;
## META HTTP-EQUIV REPLACEMENTS
&lt;FilesMatch "\.(html|htm|php)$"&gt;
Header set imagetoolbar "no"
&lt;/FilesMatch&gt;
</pre>
<p>Here are some default MOD_REWRITE code examples.</p>
<pre>
## REWRITE DEFAULTS
RewriteEngine On
RewriteBase /
## REQUIRE SUBDOMAIN
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^subdomain\.askapache\.com$ [NC]
RewriteRule ^/(.*)$ http://subdomain.askapache.com/$1 [L,R=301]
## SEO REWRITES
RewriteRule ^(.*)/ve/(.*)$ $1/voluntary-employee/$2 [L,R=301]
RewriteRule ^(.*)/hsa/(.*)$ $1/health-saving-account/$2 [L,R=301]
## WORDPRESS
RewriteCond %{REQUEST_FILENAME} !-f  # Existing File
RewriteCond %{REQUEST_FILENAME} !-d  # Existing Directory
RewriteRule . /index.php [L]
## ALTERNATIVE ANTI-HOTLINKING
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(subdomain\.)?askapache.com/.*$ [NC]
RewriteRule ^.*\.(bmp|tif|gif|jpg|jpeg|jpe|png)$ - [F]
## REDIRECT HOTLINKERS
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(subdomain\.)?askapache.com/.*$ [NC]
RewriteRule ^.*\.(bmp|tif|gif|jpg|jpeg|jpe|png)$ http://google.com [R]
## DENY REQUEST BASED ON REQUEST METHOD
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK|OPTIONS|HEAD)$ [NC]
RewriteRule ^.*$ - [F]
## REDIRECT UPLOADS
RewriteCond %{REQUEST_METHOD} ^(PUT|POST)$ [NC]
RewriteRule ^(.*)$ /cgi-bin/form-upload-processor.cgi?p=$1 [L,QSA]
## REQUIRE SSL EVEN WHEN MOD_SSL IS NOT LOADED
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
### ALTERNATATIVE TO USING ERRORDOCUMENT
# http://www.htaccesselite.com/d/htaccess-errordocument-examples-vt11.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /error.php [L]
## SEO REDIRECTS
Redirect 301 /2006/oldfile.html http://subdomain.askapache.com/newfile.html
RedirectMatch 301 /o/(.*)$ http://subdomain.askapache.com/s/dl/$1
</pre>
<p>Examples of protecting your files and securing with password protection.</p>
<pre>
#
# Require (user|group|valid-user) (username|groupname)
#
## BASIC PASSWORD PROTECTION
AuthType basic
AuthName "prompt"
AuthUserFile /.htpasswd
AuthGroupFile /dev/null
Require valid-user
## ALLOW FROM IP OR VALID PASSWORD
Require valid-user
Allow from 192.168.1.23
Satisfy Any
## PROTECT FILES
&lt;FilesMatch "\.(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$"&gt;
Order Allow,Deny
Deny from all
&lt;/FilesMatch&gt;
## PREVENT HOTLINKING
SetEnvIfNoCase Referer "^http://subdomain.askapache.com/" good
SetEnvIfNoCase Referer "^$" good
&lt;FilesMatch "\.(png|jpg|jpeg|gif|bmp|swf|flv)$"&gt;
Order Deny,Allow
Deny from all
Allow from env=good
ErrorDocument 403 http://www.google.com/intl/en_ALL/images/logo.gif
ErrorDocument 403 /images/you_bad_hotlinker.gif
&lt;/FilesMatch&gt;
## LIMIT UPLOAD FILE SIZE TO PROTECT AGAINST DOS ATTACK
#bytes, 0-2147483647(2GB)
LimitRequestBody 10240000
## MOST SECURE WAY TO REQUIRE SSL
# http://www.askapache.com/htaccess/apache-ssl-in-htaccess-examples.html
SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "askapache.com"
ErrorDocument 403 https://askapache.com
## COMBINED DEVELOPER HTACCESS CODE-USE THIS
&lt;FilesMatch "\.(flv|gif|jpg|jpeg|png|ico|js|css|pdf|swf|html|htm|txt)$"&gt;
Header set Cache-Control "max-age=5"
&lt;/FilesMatch&gt;
AuthType basic
AuthName "Ooops! Temporarily Under Construction..."
AuthUserFile /.htpasswd
AuthGroupFile /dev/null
Require valid-user      # password prompt for everyone else
Order Deny,Allow
Deny from all
Allow from 192.168.64.5   # Your, the developers IP address
Allow from w3.org      # css/xhtml check jigsaw.w3.org/css-validator/
Allow from googlebot.com   # Allows google to crawl your pages
Satisfy Any        # no password required if host/ip is Allowed
## DONT HAVE TO EMPTY CACHE OR RELOAD TO SEE CHANGES
ExpiresDefault A5 #If using mod_expires
&lt;FilesMatch "\.(flv|gif|jpg|jpeg|png|ico|js|css|pdf|swf|html|htm|txt)$"&gt;
Header set Cache-Control "max-age=5"
&lt;/FilesMatch&gt;
## ALLOW ACCESS WITH PASSWORD OR NO PASSWORD FOR SPECIFIC IP/HOSTS
AuthType basic
AuthName "Ooops! Temporarily Under Construction..."
AuthUserFile /.htpasswd
AuthGroupFile /dev/null
Require valid-user      # password prompt for everyone else
Order Deny,Allow
Deny from all
Allow from 192.168.64.5   # Your, the developers IP address
Allow from w3.org      # css/xhtml check jigsaw.w3.org/css-validator/
Allow from googlebot.com   # Allows google to crawl your pages
Satisfy Any        # no password required if host/ip is Allowed
</pre>
<hr class="C" />






<h2>Example .htaccess Code Snippets</h2>
<p>Here are some specific examples, this is the most popular section of this page.  Updated frequently.</p>

<h4>Redirect Everyone Except IP address to alternate page</h4>
<pre>
ErrorDocument 403 http://www.yahoo.com/
Order deny,allow
Deny from all
Allow from 208.113.134.190
</pre>

<h4>When developing sites</h4>
<p>This lets google crawl the page, lets me access  without a password, and lets my client access the page WITH a password.  It also allows for XHTML and CSS validation! (w3.org)</p>
<pre>
AuthName "Under Development"
AuthUserFile /home/sitename.com/.htpasswd
AuthType basic
Require valid-user
Order deny,allow
Deny from all
Allow from 208.113.134.190 w3.org htmlhelp.com googlebot.com
Satisfy Any
</pre>

<h4>Fix double-login prompt</h4>
<p>Redirect non-https requests to https server and ensure that <strong>.htpasswd authorization</strong> can only be entered across HTTPS</p>
<pre>
SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "askapache.com"
ErrorDocument 403 https://askapache.com
</pre>

<h4>Set Timezone of the Server (GMT)</h4>
<pre>
SetEnv TZ America/Indianapolis
</pre>

<h4>Administrator Email for ErrorDocument</h4>
<pre>
SetEnv SERVER_ADMIN webmaster@google.com
</pre>

<h4><code>ServerSignature</code> for <code>ErrorDocument</code></h4>
<pre>
ServerSignature off | on | email
</pre>

<h4>Charset and Language headers</h4>
<p>Article: <a href="/htaccess/setting-charset-in-htaccess.html">Setting Charset in htaccess</a>, and <a href="http://www.w3.org/International/questions/qa-htaccess-charset">article by <cite>Richard Ishida</cite></a></p>
<pre>
AddDefaultCharset UTF-8
DefaultLanguage en-US
</pre>

<h4>Disallow Script Execution</h4>
<pre>
Options -ExecCGI
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
</pre>

<h4>Deny Request Methods</h4>
<pre>
RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|OPTIONS|POST|PUT)
RewriteRule .* - [F]
</pre>

<h4>Force "File Save As" Prompt</h4>
<pre>
AddType application/octet-stream .avi .mpg .mov .pdf .xls .mp4
</pre>

<h4>Show CGI Source Code</h4>
<pre>
RemoveHandler cgi-script .pl .py .cgi
AddType text/plain .pl .py .cgi
</pre>

<h4>Serve all .pdf files on your site using .htaccess and mod_rewrite with the php script.</h4>
<pre>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.+)\.pdf$  /cgi-bin/pdf.php?file=$1 [L,NC,QSA]
</pre>

<h4>Rewrite to www</h4>
<pre>
RewriteCond %{REQUEST_URI} !^/(robots\.txt|favicon\.ico|sitemap\.xml)$
RewriteCond %{HTTP_HOST} !^www\.askapache\.com$ [NC]
RewriteRule ^(.*)$ http://www.askapache.com/$1 [R=301,L]
</pre>

<h4>Rewrite to www dynamically</h4>
<pre>
RewriteCond %{REQUEST_URI} !^/robots\.txt$ [NC]
RewriteCond %{HTTP_HOST} !^www\.[a-z-]+\.[a-z]{2,6} [NC]
RewriteCond %{HTTP_HOST} ([a-z-]+\.[a-z]{2,6})$   [NC]
RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]
</pre>

<h4>301 Redirect Old File</h4>
<pre>
Redirect 301 /old/file.html http://www.askapache.com/new/file.html
</pre>

<h4>301 Redirect Entire Directory</h4>
<pre>
RedirectMatch 301 /blog(.*) http://www.askapache.com/$1
</pre>

<h4>Protecting your php.cgi</h4>
<pre>
&lt;FilesMatch "^php5?\.(ini|cgi)$"&gt;
Order Deny,Allow
Deny from All
Allow from env=REDIRECT_STATUS
&lt;/FilesMatch&gt;
</pre>

<h4>Set Cookie based on Request</h4>
<p>This code sends the <code>Set-Cookie</code> header to create a cookie on the client with the value of a matching item in 2nd parantheses.</p>
<pre>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)(de|es|fr|it|ja|ru|en)/$ - [co=lang:$2:.askapache.com:7200:/]
</pre>

<h4>Set Cookie with env variable</h4>
<pre>
Header set Set-Cookie "language=%{lang}e; path=/;" env=lang
</pre>

<h4>Custom ErrorDocuments</h4>
<pre>
ErrorDocument 100 /100_CONTINUE
ErrorDocument 101 /101_SWITCHING_PROTOCOLS
ErrorDocument 102 /102_PROCESSING
ErrorDocument 200 /200_OK
ErrorDocument 201 /201_CREATED
ErrorDocument 202 /202_ACCEPTED
ErrorDocument 203 /203_NON_AUTHORITATIVE
ErrorDocument 204 /204_NO_CONTENT
ErrorDocument 205 /205_RESET_CONTENT
ErrorDocument 206 /206_PARTIAL_CONTENT
ErrorDocument 207 /207_MULTI_STATUS
ErrorDocument 300 /300_MULTIPLE_CHOICES
ErrorDocument 301 /301_MOVED_PERMANENTLY
ErrorDocument 302 /302_MOVED_TEMPORARILY
ErrorDocument 303 /303_SEE_OTHER
ErrorDocument 304 /304_NOT_MODIFIED
ErrorDocument 305 /305_USE_PROXY
ErrorDocument 307 /307_TEMPORARY_REDIRECT
ErrorDocument 400 /400_BAD_REQUEST
ErrorDocument 401 /401_UNAUTHORIZED
ErrorDocument 402 /402_PAYMENT_REQUIRED
ErrorDocument 403 /403_FORBIDDEN
ErrorDocument 404 /404_NOT_FOUND
&nbsp;
ErrorDocument 405 /405_METHOD_NOT_ALLOWED
ErrorDocument 406 /406_NOT_ACCEPTABLE
ErrorDocument 407 /407_PROXY_AUTHENTICATION_REQUIRED
ErrorDocument 408 /408_REQUEST_TIME_OUT
ErrorDocument 409 /409_CONFLICT
ErrorDocument 410 /410_GONE
ErrorDocument 411 /411_LENGTH_REQUIRED
ErrorDocument 412 /412_PRECONDITION_FAILED
ErrorDocument 413 /413_REQUEST_ENTITY_TOO_LARGE
ErrorDocument 414 /414_REQUEST_URI_TOO_LARGE
ErrorDocument 415 /415_UNSUPPORTED_MEDIA_TYPE
ErrorDocument 416 /416_RANGE_NOT_SATISFIABLE
ErrorDocument 417 /417_EXPECTATION_FAILED
ErrorDocument 422 /422_UNPROCESSABLE_ENTITY
ErrorDocument 423 /423_LOCKED
ErrorDocument 424 /424_FAILED_DEPENDENCY
ErrorDocument 426 /426_UPGRADE_REQUIRED
ErrorDocument 500 /500_INTERNAL_SERVER_ERROR
ErrorDocument 501 /501_NOT_IMPLEMENTED
ErrorDocument 502 /502_BAD_GATEWAY
ErrorDocument 503 /503_SERVICE_UNAVAILABLE
ErrorDocument 504 /504_GATEWAY_TIME_OUT
ErrorDocument 505 /505_VERSION_NOT_SUPPORTED
ErrorDocument 506 /506_VARIANT_ALSO_VARIES
ErrorDocument 507 /507_INSUFFICIENT_STORAGE
ErrorDocument 510 /510_NOT_EXTENDED
</pre>

<h4>Implementing a Caching Scheme with .htaccess</h4>
<pre>
# year
&lt;FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$"&gt;
Header set Cache-Control "public"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
Header unset Last-Modified
&lt;/FilesMatch&gt;
#2 hours
&lt;FilesMatch "\.(html|htm|xml|txt|xsl)$"&gt;
Header set Cache-Control "max-age=7200, must-revalidate"
&lt;/FilesMatch&gt;
&lt;FilesMatch "\.(js|css)$"&gt;
SetOutputFilter DEFLATE
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
&lt;/FilesMatch&gt;
</pre>

<h4>Password Protect single file</h4>
<pre>
&lt;Files login.php&gt;
AuthName "Prompt"
AuthType Basic
AuthUserFile /home/askapache.com/.htpasswd
Require valid-user
&lt;/Files&gt;
</pre>

<h4>Password Protect multiple files</h4>
<pre>
&lt;FilesMatch "^(private|phpinfo)\.*$"&gt;
AuthName "Development"
AuthUserFile /.htpasswd
AuthType basic
Require valid-user
&lt;/FilesMatch&gt;
</pre>

<h4>Send Custom Headers</h4>
<pre>
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"
</pre>

<h4>Blocking based on User-Agent Header</h4>
<pre>
SetEnvIfNoCase ^User-Agent$ .*(craftbot|download|extract|stripper|sucker|ninja|clshttp|webspider|leacher|collector|grabber|webpictures) HTTP_SAFE_BADBOT
SetEnvIfNoCase ^User-Agent$ .*(libwww-perl|aesop_com_spiderman) HTTP_SAFE_BADBOT
Deny from env=HTTP_SAFE_BADBOT
</pre>

<h4>Blocking with RewriteCond</h4>
<pre>
RewriteCond %{HTTP_USER_AGENT} ^.*(craftbot|download|extract|stripper|sucker|ninja|clshttp|webspider|leacher|collector|grabber|webpictures).*$ [NC]
RewriteRule . - [F,L]
</pre>

<h4>.htaccess for mod_php</h4>
<pre>
SetEnv PHPRC /location/todir/containing/phpinifile
</pre>

<h4>.htaccess for php as cgi</h4>
<pre>
AddHandler php-cgi .php .htm
Action php-cgi /cgi-bin/php5.cgi
</pre>

<h4>Shell wrapper for custom php.ini</h4>
<pre>
#!/bin/sh
export PHP_FCGI_CHILDREN=3
exec php5.cgi -c /abs/php5/php.ini
</pre>

<h4>Add values from HTTP Headers</h4>
<pre>
SetEnvIfNoCase ^If-Modified-Since$ "(.+)" 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 ^Cookie$ "(.+)" HTTP_MY_COOKIE=$1
</pre>

<h4>Stop hotlinking</h4>
<pre>
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?askapache.com/.*$ [NC]
RewriteRule \.(gif|jpg|swf|flv|png)$ http://www.askapache.com/feed.gif [R=302,L]
</pre>

<h4>Turn logging off for IP</h4>
<pre>
SecFilterSelective REMOTE_ADDR "208\.113\.183\.103" "nolog,noauditlog,pass"
</pre>

<h4>Turn logging on for IP</h4>
<pre>
SecFilterSelective REMOTE_ADDR "!^208\.113\.183\.103" "nolog,noauditlog,pass"
SecFilterSelective REMOTE_ADDR "208\.113\.183\.103" "log,auditlog,pass"
</pre>
<hr class="C" />






<h2>Advanced Mod_Rewrite Examples</h2>






<h2>Best .htaccess Articles</h2>

<h3><a title="Apache HTTP Web Server htaccess tips and tricks" rel="chapter" href="http://www.askapache.com/htaccess/htaccess-for-webmasters.html">.htaccess for Webmasters</a></h3><ul><li><a title="htaccess trick to run requests through a cgi script" href="/htaccess/htaccess-for-webmasters.html#process-file-through-cgi">Process certain requests for files using a cgi script</a></li><li><a title="htaccess security for apache hacking" href="/htaccess/htaccess-for-webmasters.html#process-request-methods-with-script">Process Requests with certain Request Methods</a></li><li><a title="Apache ForceType Directive in htaccess process file" href="/htaccess/htaccess-for-webmasters.html#force-filetype-with-forcetype">Make any file be a certain filetype</a></li><li><a title="Using the IfModule Directive in Apache htaccess files." href="/htaccess/htaccess-for-webmasters.html#ifmodule-in-apache">Use IfModule directive for robust code</a></li></ul>

<h3><a title="mod_rewrite RewriteRule, RewriteCond help" rel="chapter" href="http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html">Mod_Rewrite URL Rewriting</a></h3><p><a class="hs hs13" href="/htaccess/crazy-advanced-mod_rewrite-tutorial.html#decoded"></a>Undocumented techniques and methods will allow you to utilize mod_rewrite at an  "expert level" by showing you how to <a href="/htaccess/crazy-advanced-mod_rewrite-tutorial.html#decoded">unlock its secrets</a>.</p><ul><li><a title="Search query string at QUERY_STRING" href="/htaccess/mod_rewrite-tips-and-tricks.html#check-for-key-in-query-string">Check for a key in QUERY_STRING</a></li><li><a title="Deny access using htaccess during certain time" href="/htaccess/mod_rewrite-tips-and-tricks.html#time-based-access">Block access to files during certain hours of the day</a></li><li><a title="Change underscores to hyphens for SEO URL" href="/htaccess/mod_rewrite-tips-and-tricks.html#convert-underscore-hyphen">Rewrite underscores to hyphens for SEO URL</a></li><li><a title="Rewriting WordPress RSS feeds to Feedburner in SEO friendly method" href="/htaccess/mod_rewrite-tips-and-tricks.html#redirect-wordpress-feed">Redirecting WordPress Feeds to Feedburner</a></li></ul>

<h3><a title="301 Redirects" rel="chapter" href="http://www.askapache.com/htaccess/seo-search-engine-friendly-redirects-without-mod_rewrite.html">301 Redirects without mod_rewrite</a></h3><ul><li><a title="301 Redirect single file" href="/htaccess/seo-search-engine-friendly-redirects-without-mod_rewrite.html#seo-301-redirect-single-file">Redirect single url</a></li><li><a title="301 Redirect new domain" href="/htaccess/seo-search-engine-friendly-redirects-without-mod_rewrite.html#seo-301-redirect-new-domain">Redirect to new Domain</a></li></ul>

<h3><a href="/htaccess/php-cgi-redirect_status.html">Secure PHP with .htaccess</a></h3>
<p><a class="IFL" title="Locking down your php.ini and php cgi with .htaccess" href="/htaccess/php-cgi-redirect_status.html"><img src="http://uploads.askapache.com/2008/01/jail-bars-1.png" alt="Locking down your php.ini and php cgi with .htaccess" title="jail bars 1 htaccess" /></a>If you have a php.cgi or php.ini file in your /cgi-bin/ directory or other pub directory, try requesting them from your web browser.  If your php.ini shows up or worse you are able to execute your php cgi, you'll need to secure it ASAP.  This shows several ways to secure these files, and other interpreters like perl, fastCGI, bash, csh, etc.<br class="C" /></p>

<h3><a href="/htaccess/htaccess-fresh.html">.htaccess Cookie Manipulation</a></h3><p><a class="IFL" title="Cookie Manipulation in .htaccess with RewriteRule" href="/htaccess/htaccess-fresh.html"><img src="http://uploads.askapache.com/2007/10/cookies.png" alt="Cookie Manipulation in .htaccess with RewriteRule" title="cookies htaccess" /></a><strong>Fresh <a href="/htaccess/htaccess.html">.htaccess</a> code</strong> for you!  Check out the Cookie Manipulation and environment variable usage with mod_rewrite!  I also included a couple Mod_Security .htaccess examples. <strong>Enjoy!</strong><br class="C" /></p><ul><li><a href="/htaccess/htaccess-fresh.html#modrewrite1">Mod_Rewrite .htaccess Examples</a></li><li><a href="/htaccess/htaccess-fresh.html#modrewrite2">Cookie Manipulation and Tests with mod_rewrite</a></li><li><a href="/htaccess/htaccess-fresh.html#modrewrite3">Setting Environment Variables</a></li><li><a href="/htaccess/htaccess-fresh.html#modrewrite4">Using the Environment Variable</a></li><li><a href="/htaccess/htaccess-fresh.html#modrewrite5">Mod_Security .htaccess Examples</a></li></ul>

<h3><a title="htaccess Caching" rel="chapter" href="http://www.askapache.com/htaccess/speed-up-your-site-with-caching-and-cache-control.html">.htaccess Caching</a></h3><ul><li><a href="/htaccess/speed-up-sites-with-htaccess-caching.html">Speed Up Sites with htaccess Caching</a></li><li><a title="htaccess time cheatsheet" href="/htaccess/speed-up-your-site-with-caching-and-cache-control.html#htaccess-time-cheatsheet">htaccess time cheat sheet</a></li></ul>

<h3><a title="401, 403 htpasswd authentication" rel="chapter" href="http://www.askapache.com/htaccess/apache-authentication-in-htaccess.html">Password Protection and Authentication</a></h3><ul><li><a title="Requiring a password for single file" href="/htaccess/apache-authentication-in-htaccess.html#require-password-for-single-file">Require password for single file</a></li><li><a title="A comprehensive default Apache .htaccess example file" href="/htaccess/apache-authentication-in-htaccess.html#skeleton-htaccess">Example .htaccess file for password protection</a></li></ul>

<h3><a title="Creating and using HTTP Headers with htaccess" rel="chapter" href="http://www.askapache.com/htaccess/using-http-headers-with-htaccess.html">Control HTTP Headers</a></h3><ul><li><a title="Prevent Browsers and Proxies from caching" href="/htaccess/using-http-headers-with-htaccess.html#prevent-caching-with-htaccess">Prevent Caching 100%</a></li><li><a title="Remove Internet Explorer imagetoolbar" href="/htaccess/using-http-headers-with-htaccess.html#remove-ie-imagetoolbar">Remove IE imagetoolbar without meta tag</a></li><li><a title="How To use Apache to send P3P Privacy Header for website" href="/htaccess/using-http-headers-with-htaccess.html#privacy-p3p-header-in-apache">Add Privacy (P3P) Header to your site</a></li><li><a title="Language header, Charset header without meta" href="/htaccess/using-http-headers-with-htaccess.html#language-and-content-header-in-htaccess">Add language and charset headers without meta tags</a></li></ul>

<h3><a href="/htaccess/blocking-bad-bots-and-scrapers-with-htaccess.html">Blocking Spam and bad Bots</a></h3><p><a class="IFR" href="/htaccess/blocking-bad-bots-and-scrapers-with-htaccess.html"><img title="Block Bad Robot" src="http://uploads.askapache.com/2008/04/bad_robot1.png" alt="Block Bad Robot" height="100" /></a>Want to block a bad robot or web scraper using .htaccess files?  Here are 2 methods that illustrate blocking 436 various user-agents.  You can block them using either SetEnvIf methods, or by using Rewrite Blocks.<br class="C" /></p>

<h3><a title="php htaccess tips, htaccess php tricks" rel="chapter" href="http://www.askapache.com/htaccess/php-htaccess-tips-and-tricks.html">PHP htaccess tips</a></h3><p>By using some cool .htaccess tricks we can control PHP to be run as a cgi or a module.  If php is run as a cgi then we need to compile it ourselves or use .htaccess to force php to use a local php.ini file.  If it is running as a module then we can use various directives supplied by that modules in .htaccess</p><ul><li><a title=".htaccess for php as cgi" href="/htaccess/php-htaccess-tips-and-tricks.html#php-run-as-cgi">When php run as CGI</a></li><li><a title="custom php.ini with Apache htaccess using PHPRC" href="/htaccess/php-htaccess-tips-and-tricks.html#htaccess-php-ini">Use a custom php.ini with mod_php or php as a cgi</a></li><li><a title="htaccess tips for mod_php php running as Apache module" href="/htaccess/php-htaccess-tips-and-tricks.html#sub-mod_php">When php run as Apache Module (mod_php)</a></li><li><a title="Apache FastCGI wrapper for php cgi" href="/htaccess/php-htaccess-tips-and-tricks.html#php-and-fastcgi-in-htaccess">When cgi php is run with wrapper (FastCGI)</a></li></ul>

<h3><a href="/htaccess/http-https-rewriterule-redirect.html">HTTP to HTTPS Redirects with mod_rewrite</a></h3><p><a href="/htaccess/http-https-rewriterule-redirect.html"><img class="IFL" src="http://uploads.askapache.com/2007/11/security.png" alt="HTTP to HTTPS Redirects with mod_rewrite" title="security htaccess" /></a>This is freaking sweet if you use SSL I promise you!  Basically instead of having to check for HTTPS using a <code>RewriteCond %{HTTPS} =on</code> for every redirect that can be either HTTP or HTTPS, I set an environment variable once with the value "http" or "https" if HTTP or HTTPS is being used for that request, and use that env variable in the RewriteRule.<br class="C" /></p>

<h3><a title="Apache SSL examples" rel="chapter" href="http://www.askapache.com/htaccess/ssl-example-usage-in-htaccess.html">SSL in .htaccess</a></h3><ul><li><a title="Redirecting non-SSL to SSL in Apache" href="/htaccess/ssl-example-usage-in-htaccess.html#redirect-http-to-https">Redirect non-https requests to https server</a></li><li><a title="redirect HTTP to HTTPS without mod_ssl!" href="/htaccess/ssl-example-usage-in-htaccess.html#rewrite-http-to-https-no-mod_ssl">Rewrite non-https to HTTPS without mod_ssl!</a></li><li><a title="Redirect HTTP to HTTPS by port" href="/htaccess/ssl-example-usage-in-htaccess.html#redirect-port-80-to-https">Redirect everything served on port 80 to HTTPS URI</a></li></ul>

<h3><a title="Conditionally setting variables in Apache .htaccess" rel="chapter" href="http://www.askapache.com/htaccess/setenvif.html">SetEnvIf and SetEnvIfNoCase in .htaccess</a></h3><ul><li><a title="Unique mod_setenvif Variables" href="/htaccess/setenvif.html#setenvif-variables">Unique mod_setenvif Variables</a></li><li><a title="Populates HTTP_MY_ Variables with mod_setenvif variable values" href="/htaccess/setenvif.html#http-headers">Populates HTTP_MY_ Variables with mod_setenvif variable values</a></li><li><a title="Allows only if HOST Header is present in request" href="/htaccess/setenvif.html#allow-host">Allows only if HOST Header is present in request</a></li><li><a title="Add values from HTTP Headers" href="/htaccess/setenvif.html#header-copy">Add values from HTTP Headers</a></li></ul>

<h3><a title="htaccess security and hacking" rel="chapter" href="http://www.askapache.com/htaccess/security-with-htaccess.html">Site Security with .htaccess</a></h3>
<p>chmod .htpasswd files 640, chmod .htaccess 644, php files 600, and chmod files that you really dont want people to see as 400. (NEVER chmod 777, try 766)</p>
<ul><li><a title="CHMOD .htaccess, chmod .htpasswd, chmodding files" href="/htaccess/security-with-htaccess.html#chmod-htaccess-info">CHMOD your files</a></li><li><a title="Deny access for htaccess/htpasswd file" href="/htaccess/security-with-htaccess.html#deny-htaccess-htpasswd-access">Prevent access to .htaccess and .htpasswd files</a></li><li><a title="Show source code in browser, prevent executing file" href="/htaccess/security-with-htaccess.html#show-source-code">Show Source Code instead of executing</a></li><li><a title="Remove execution privileges" href="/htaccess/security-with-htaccess.html#securing-directories-with-htaccess">Securing directories: Remove ability to execute scripts</a></li><li><a title="ErrorDocument usage in htaccess files" href="/htaccess/security-with-htaccess.html#errordocument-usage-in-htaccess">.htaccess ErrorDocuments</a></li></ul>

<h3><a title="mod_security Guide and sample mod_Security diretive usage in .htaccess" rel="chapter" href="http://www.askapache.com/htaccess/mod_security-htaccess-tricks.html">.htaccess Security with MOD_SECURITY</a></h3><ul><li><a href="/htaccess/mod_security-htaccess-tricks.html#mod_security-mod_rewrite">mod_security + mod_rewrite</a></li><li><a href="/htaccess/mod_security-htaccess-tricks.html#block-post-spam">Block Spam by examining POST form fields</a></li><li><a href="/htaccess/mod_security-htaccess-tricks.html#disable-mod_security">Disabling mod_security conditionally per IP</a></li><li><a href="/htaccess/mod_security-htaccess-tricks.html#mod_security-authorization">Disabling mod_security with .htaccess Authorization</a></li><li><a href="/htaccess/mod_security-htaccess-tricks.html#block-wordpress-spam">Block WordPress Spam Forever!</a></li><li><a href="/htaccess/mod_security-htaccess-tricks.html#pause-connections">Force Any Connections to be Paused a set number of ms</a></li><li><a href="/htaccess/mod_security-htaccess-tricks.html#mod_security-debugging">ModSecurity Debugging and Logging</a></li><li><a href="/htaccess/mod_security-htaccess-tricks.html#conditional-logging">Turn Off/On Logging JUST for your IP Address</a></li><li><a href="/htaccess/mod_security-htaccess-tricks.html#mod_security-directives">Mod_Security Directives for DreamHost</a></li><li><a href="/htaccess/mod_security-htaccess-tricks.html#httpdconf-rules">Example httpd.conf mod_security rule files</a></li></ul>
<hr class="C" />





<h3>Merging Notes</h3>
<p>The order of merging is:</p>
<ol>
<li><code>&lt;Directory&gt;</code> (except regular expressions) and .htaccess done simultaneously (with .htaccess, if allowed, overriding <code>&lt;Directory&gt;</code>)</li>
<li><code>&lt;DirectoryMatch&gt;</code> (and <code>&lt;Directory ~&gt;</code>)</li>
<li><code>&lt;Files&gt;</code> and <code>&lt;FilesMatch&gt;</code> done simultaneously</li>
<li><code>&lt;Location&gt;</code> and <code>&lt;LocationMatch&gt;</code> done simultaneously</li>
</ol>
<p>Below is an artificial example to show the order of merging. Assuming they all apply to the request, the directives in this example will be applied in the order:</p>
<p><code>A &gt; B &gt; C &gt; D &gt; E</code></p>.
<pre>
&lt;Location /&gt;
E
&lt;/Location&gt;
&lt;Files askapache.txt&gt;
D
&lt;/Files&gt;
&lt;VirtualHost *&gt;
&lt;Directory /a/b&gt;
B
&lt;/Directory&gt;
&lt;/VirtualHost&gt;
&lt;DirectoryMatch "^.*b$"&gt;
C
&lt;/DirectoryMatch&gt;
&lt;Directory /a/b&gt;
A
&lt;/Directory&gt;
</pre>





<h2>My Favorite .htaccess Links</h2>
<p class="anote">These are just some of my favorite <a href="http://www.google.com/Top/Computers/Internet/Web_Design_and_Development/Authoring/FAQs,_Help,_and_Tutorials/Access_Control/">.htaccess resources</a>.  I'm really into doing your own hacking to get knowledge and these links are all great resources in that respect.  I'm really interested in new or unusual htaccess solutions or htaccess hacks using .htaccess files, so let me know if you find one.</p>
<p><strong>NCSA HTTPd Tutorials</strong><br /></p>
<p><strong>Robert Hansen</strong><br />Here's a great <a href="http://www.securityfocus.com/infocus/1368">Hardening HTAccess part 1</a>, <a href="http://www.securityfocus.com/infocus/1369">part 2</a>, <a href="http://www.securityfocus.com/infocus/1370">part 3</a> article that goes into detail about some of the rarer security applications for .htaccess files.</p>
<p><strong>SAMAXES</strong><br />Some very detailed and helpful .htaccess articles, such as the <a href="http://www.samaxes.com/2008/04/20/htaccess-gzip-and-cache-your-site-for-faster-loading-and-bandwidth-saving/">".htaccess - gzip and cache your site for faster loading and bandwidth saving."</a></p>
<p><strong>PerishablePress</strong><br /><a href="http://perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/">Stupid .htaccess tricks</a> is probably the <strong>best explanation online</strong> for many of the best .htaccess solutions, including many from this page. Unlike me they are fantastic writers, even for technical stuff they are very readable, so its a good blog to kick back on and read.  They also have a <a title="Eight Ways to Blacklist with Apache's mod_rewrite" href="http://perishablepress.com/press/2009/02/03/eight-ways-to-blacklist-with-apaches-mod_rewrite/">fantastic article</a> detailing how to block/deny specific requests using mod_rewrite.</p>
<p><strong>BlogSecurity</strong><br />Mostly a site for... blog security (which is really any web-app security) this blog has a few really impressive articles full of solid information for <a href="http://blogsecurity.net/wordpress/article-210607/">Hardening WordPress with .htaccess</a> among more advanced topics that can be challenging but effective.  This is a good site to subscribe to their feed, they publish plugin exploits and wordpress core vulnerabilities quite a bit.</p>
<p><strong>Check-These</strong><br />Oldschool security/unix dude with some incredibly detailed mod_rewrite tutorials, helped me the most when I first got into this, and a great guy too. See: <a href="http://check-these.info/mod_rewrite-basic.html">Basic Mod_Rewrite Guide</a>, and <a href="http://check-these.info/RewriteRule.html">Advanced Mod_Rewrite Tutorial</a></p>
<p><strong>Reaper-X</strong><br />Alot of .htaccess tutorials and code.  See: <a href="http://www.reaper-x.com/2007/09/01/hardening-wordpress-with-mod-rewrite-and-htaccess/">Hardening WordPress with Mod Rewrite and htaccess</a></p>
<p><strong>jdMorgan</strong><br /><a href="http://www.webmasterworld.com/profilev4.cgi?action=view&amp;member=jdMorgan">jdMorgan</a> is the Moderator of the <a href="http://www.webmasterworld.com/apache/">Apache Forum</a> at WebmasterWorld, a great place for answers.  In my experience he can answer any tough question pertaining to advanced .htaccess usage, haven't seen him stumped yet.</p>
<p><strong>The W3C</strong><br /><a href="http://www.w3.org/International/questions/qa-htaccess-charset">Setting Charset in .htaccess</a> is very informative.<br /></p>
<p><strong>Holy Shmoly!</strong><br />A great blogger with analysis of attacks and spam.  See: More ways to stop spammers and unwanted traffic.</p>
<p><strong>Apache Week</strong><br />A partnership with Red Hat back in the 90's that produced some <a href="http://www.apacheweek.com/features/userauth">excellent documentation</a>.</p>
<p><strong>Corz</strong><br />Here's a resource that I consider to have some of the most creative and ingenious ideas for .htaccess files, although the author is somewhat of a character ;) Its a trip trying to navigate around the site, a fun trip. Its like nothing I've ever seen. There are only a few articles on the site, but the htaccess articles are very original and well-worth a look. See: <a rel="nofollow" href="http://corz.org/serv/tricks/htaccess.php">htaccess tricks and tips</a>.</p>
<hr class="C" />







<h2>Htaccess Directives</h2>
<p class="anote">This is an AskApache.com exclusive <em>you won't find this anywhere else</em>.</p>
<p>Directory, DirectoryMatch, Files, FilesMatch, IfDefine, IfVersion, IfModule, Limit, LimitExcept, Location, LocationMatch, Proxy, ProxyMatch, VirtualHost, AcceptMutex, AcceptPathInfo, AccessFileName, Action, AddCharset, AddDefaultCharset, AddDescription, AddEncoding, AddHandler, AddInputFilter, AddLanguage, AddOutputFilter, AddOutputFilterByType, AddType, Alias, AliasMatch, AllowCONNECT, AllowOverride, Anonymous, Anonymous_Authoritative, Anonymous_LogEmail, Anonymous_MustGiveEmail, Anonymous_NoUserId, Anonymous_VerifyEmail, AuthAuthoritative, AuthDBMAuthoritative, AuthDBMGroupFile, AuthDBMType, AuthDBMUserFile, AuthDigestAlgorithm, AuthDigestDomain, AuthDigestFile, AuthDigestGroupFile, AuthDigestNcCheck, AuthDigestNonceFormat, AuthDigestNonceLifetime, AuthDigestQop, AuthDigestShmemSize, AuthGroupFile, AuthName, AuthType, AuthUserFile, BS2000Account, BrowserMatch, BrowserMatchNoCase, CacheNegotiatedDocs, CharsetDefault, CharsetOptions, CharsetSourceEnc, CheckSpelling, ContentDigest, CookieDomain, CookieExpires, CookieName, CookieStyle, CookieTracking, CoreDumpDirectory, DAV, DAVDepthInfinity, DAVMinTimeout, DefaultIcon, DefaultLanguage, DefaultType, DocumentRoot, ErrorDocument, ErrorLog, ExtFilterDefine, ExtFilterOptions, FancyIndexing, FileETag, ForceLanguagePriority, ForceType, GprofDir, Header, HeaderName, HostnameLookups, IdentityCheck, ImapBase, ImapDefault, ImapMenu, Include, IndexIgnore, LanguagePriority, LimitRequestBody, LimitRequestFields, LimitRequestFieldsize, LimitRequestLine, LimitXMLRequestBody, LockFile, LogLevel, MaxRequestsPerChild, MultiviewsMatch, NameVirtualHost, NoProxy, Options, PassEnv, PidFile, Port, ProxyBlock, ProxyDomain, ProxyErrorOverride, ProxyIOBufferSize, ProxyMaxForwards, ProxyPass, ProxyPassReverse, ProxyPreserveHost, ProxyReceiveBufferSize, ProxyRemote, ProxyRemoteMatch, ProxyRequests, ProxyTimeout, ProxyVia, RLimitCPU, RLimitMEM, RLimitNPROC, ReadmeName, Redirect, RedirectMatch, RedirectPermanent, RedirectTemp, RemoveCharset, RemoveEncoding, RemoveHandler, RemoveInputFilter, RemoveLanguage, RemoveOutputFilter, RemoveType, RequestHeader, Require, RewriteCond, RewriteRule, SSIEndTag, SSIErrorMsg, SSIStartTag, SSITimeFormat, SSIUndefinedEcho, Satisfy, ScoreBoardFile, Script, ScriptAlias, ScriptAliasMatch, ScriptInterpreterSource, ServerAdmin, ServerAlias, ServerName, ServerPath, ServerRoot, ServerSignature, ServerTokens, SetEnv, SetEnvIf, SetEnvIfNoCase, SetHandler, SetInputFilter, SetOutputFilter, Timeout, TypesConfig, UnsetEnv, UseCanonicalName, XBitHack, allow, deny, order, CGIMapExtension, EnableMMAP, ISAPIAppendLogToErrors, ISAPIAppendLogToQuery, ISAPICacheFile, ISAPIFakeAsync, ISAPILogNotSupported, ISAPIReadAheadBuffer, SSLLog, SSLLogLevel, MaxMemFree, ModMimeUsePathInfo, EnableSendfile, ProxyBadHeader, AllowEncodedSlashes, LimitInternalRecursion, EnableExceptionHook, TraceEnable, ProxyFtpDirCharset, AuthBasicAuthoritative, AuthBasicProvider, AuthDefaultAuthoritative, AuthDigestProvider, AuthLDAPAuthzEnabled, AuthLDAPBindDN, AuthLDAPBindPassword, AuthLDAPCharsetConfig, AuthLDAPCompareDNOnServer, AuthLDAPDereferenceAliases, AuthLDAPGroupAttribute, AuthLDAPGroupAttributeIsDN, AuthLDAPRemoteUserIsDN, AuthLDAPURL, AuthzDBMAuthoritative, AuthzDBMType, AuthzDefaultAuthoritative, AuthzGroupFileAuthoritative, AuthzLDAPAuthoritative, AuthzOwnerAuthoritative, AuthzUserAuthoritative, BalancerMember, DAVGenericLockDB, FilterChain, FilterDeclare, FilterProtocol, FilterProvider, FilterTrace, IdentityCheckTimeout, IndexStyleSheet, ProxyPassReverseCookieDomain, ProxyPassReverseCookiePath, ProxySet, ProxyStatus, ThreadStackSize, AcceptFilter, Protocol, AuthDBDUserPWQuery, AuthDBDUserRealmQuery, UseCanonicalPhysicalPort, CheckCaseOnly, AuthLDAPRemoteUserAttribute, ProxyPassMatch, SSIAccessEnable, Substitute, ProxyPassInterpolateEnv</p>
<hr class="C" />







<h2>Htaccess Modules</h2>
<p>Here are most of the modules that come with Apache.  Each one can have new commands that can be used in .htaccess file scopes.</p>
<p><a href="/servers/mod_actions.c.html">mod_actions</a>, <a href="/servers/mod_alias.c.html">mod_alias</a>, <a href="/servers/mod_asis.c.html">mod_asis</a>, <a href="/servers/mod_auth_basic.c.html">mod_auth_basic</a>, <a href="/servers/mod_auth_digest.c.html">mod_auth_digest</a>, <a href="/servers/mod_authn_anon.c.html">mod_authn_anon</a>, <a href="/servers/mod_authn_dbd.c.html">mod_authn_dbd</a>, <a href="/servers/mod_authn_dbm.c.html">mod_authn_dbm</a>, <a href="/servers/mod_authn_default.c.html">mod_authn_default</a>, <a href="/servers/mod_authn_file.c.html">mod_authn_file</a>, <a href="/servers/mod_authz_dbm.c.html">mod_authz_dbm</a>, <a href="/servers/mod_authz_default.c.html">mod_authz_default</a>, <a href="/servers/mod_authz_groupfile.c.html">mod_authz_groupfile</a>, <a href="/servers/mod_authz_host.c.html">mod_authz_host</a>, <a href="/servers/mod_authz_owner.c.html">mod_authz_owner</a>, <a href="/servers/mod_authz_user.c.html">mod_authz_user</a>, <a href="/servers/mod_autoindex.c.html">mod_autoindex</a>, <a href="/servers/mod_cache.c.html">mod_cache</a>, <a href="/servers/mod_cern_meta.c.html">mod_cern_meta</a>, <a href="/servers/mod_cgi.c.html">mod_cgi</a>, <a href="/servers/mod_dav.c.html">mod_dav</a>, <a href="/servers/mod_dav_fs.c.html">mod_dav_fs</a>, <a href="/servers/mod_dbd.c.html">mod_dbd</a>, <a href="/servers/mod_deflate.c.html">mod_deflate</a>, <a href="/servers/mod_dir.c.html">mod_dir</a>, <a href="/servers/mod_disk_cache.c.html">mod_disk_cache</a>, <a href="/servers/mod_dumpio.c.html">mod_dumpio</a>, <a href="/servers/mod_env.c.html">mod_env</a>, <a href="/servers/mod_expires.c.html">mod_expires</a>, <a href="/servers/mod_ext_filter.c.html">mod_ext_filter</a>, <a href="/servers/mod_file_cache.c.html">mod_file_cache</a>, <a href="/servers/mod_filter.c.html">mod_filter</a>, <a href="/servers/mod_headers.c.html">mod_headers</a>, <a href="/servers/mod_ident.c.html">mod_ident</a>, <a href="/servers/mod_imagemap.c.html">mod_imagemap</a>, <a href="/servers/mod_include.c.html">mod_include</a>, <a href="/servers/mod_info.c.html">mod_info</a>, <a href="/servers/mod_log_config.c.html">mod_log_config</a>, <a href="/servers/mod_log_forensic.c.html">mod_log_forensic</a>, <a href="/servers/mod_logio.c.html">mod_logio</a>, <a href="/servers/mod_mem_cache.c.html">mod_mem_cache</a>, <a href="/servers/mod_mime.c.html">mod_mime</a>, <a href="/servers/mod_mime_magic.c.html">mod_mime_magic</a>, <a href="/servers/mod_negotiation.c.html">mod_negotiation</a>, <a href="/servers/mod_proxy.c.html">mod_proxy</a>, <a href="/servers/mod_proxy_ajp.c.html">mod_proxy_ajp</a>, <a href="/servers/mod_proxy_balancer.c.html">mod_proxy_balancer</a>, <a href="/servers/mod_proxy_connect.c.html">mod_proxy_connect</a>, <a href="/servers/mod_proxy_ftp.c.html">mod_proxy_ftp</a>, <a href="/servers/mod_proxy_http.c.html">mod_proxy_http</a>, <a href="/servers/mod_rewrite.c.html">mod_rewrite</a>, <a href="/servers/mod_setenvif.c.html">mod_setenvif</a>, <a href="/servers/mod_speling.c.html">mod_speling</a>, <a href="/servers/mod_ssl.c.html">mod_ssl</a>, <a href="/servers/mod_status.c.html">mod_status</a>, <a href="/servers/mod_substitute.c.html">mod_substitute</a>, <a href="/servers/mod_unique_id.c.html">mod_unique_id</a>, <a href="/servers/mod_userdir.c.html">mod_userdir</a>, <a href="/servers/mod_usertrack.c.html">mod_usertrack</a>, <a href="/servers/mod_version.c.html">mod_version</a>, <a href="/servers/mod_vhost_alias.c.html">mod_vhost_alias</a></p>
<hr class="C" />





<h2>Htaccess Software</h2>
<p>Apache HTTP Server comes with the following <a href="http://httpd.apache.org/docs/trunk/programs/">programs</a>.</p>
<dl><dt><code>httpd</code></dt><dd>Apache hypertext transfer protocol server</dd><dt><code>apachectl</code></dt><dd>Apache HTTP server control interface</dd><dt><code>ab</code></dt><dd>Apache HTTP server benchmarking tool</dd><dt><code>apxs</code></dt><dd>APache eXtenSion tool</dd><dt><code>dbmmanage</code></dt><dd>Create and update user authentication files in DBM format for basic authentication</dd><dt><code>fcgistarter</code></dt><dd>Start a FastCGI program</dd><dt><code>htcacheclean</code></dt><dd>Clean up the disk cache</dd><dt><code>htdigest</code></dt><dd>Create and update user authentication files for digest authentication</dd><dt><code>htdbm</code></dt><dd>Manipulate DBM password databases.</dd><dt><code>htpasswd</code></dt><dd>Create and update user authentication files for basic authentication</dd><dt><code>httxt2dbm</code></dt><dd>Create dbm files for use with RewriteMap</dd><dt><code>logresolve</code></dt><dd>Resolve hostnames for IP-addresses in Apache logfiles</dd><dt>log_server_status</dt><dd>Periodically log the server's status</dd><dt><code>rotatelogs</code></dt><dd>Rotate Apache logs without having to kill the server</dd><dt>split-logfile</dt><dd>Split a multi-vhost logfile into per-host logfiles</dd><dt><code>suexec</code></dt><dd>Switch User For Exec</dd></dl>




















<h2>Technical Look at .htaccess</h2>
<p><a href="http://httpd.apache.org/docs/1.3/misc/API.html">Source: Apache API notes</a></p>
<h3>Per-directory configuration structures</h3>
<p>Let's look out how all of this plays out in mod_mime.c, which defines the file typing handler which emulates the NCSA server's behavior of determining file types from suffixes. What we'll be looking at, here, is the code which implements the AddType and AddEncoding commands. These commands can appear in .htaccess files, so they must be handled in the module's private per-directory data, which in fact, consists of two separate tables for MIME types and encoding information, and is declared as follows:</p>

<pre>
table *forced_types;      /* Additional AddTyped stuff */
table *encoding_types;    /* Added with AddEncoding... */
mime_dir_config;
</pre>

<p>When the server is reading a configuration file, or &lt;Directory&gt; section, which includes one of the MIME module's commands, it needs to create a mime_dir_config structure, so those commands have something to act on. It does this by invoking the function it finds in the module's `create per-dir config slot', with two arguments: the name of the directory to which this configuration information applies (or NULL for srm.conf), and a pointer to a resource pool in which the allocation should happen.</p>

<p>(If we are reading a .htaccess file, that resource pool is the per-request resource pool for the request; otherwise it is a resource pool which is used for configuration data, and cleared on restarts. Either way, it is important for the structure being created to vanish when the pool is cleared, by registering a cleanup on the pool if necessary).</p>

<p>For the MIME module, the per-dir config creation function just ap_pallocs the structure above, and a creates a couple of tables to fill it. That looks like this:</p>

<pre>
void *create_mime_dir_config (pool *p, char *dummy)
mime_dir_config *new = (mime_dir_config *) ap_palloc (p, sizeof(mime_dir_config));
&nbsp;
new-&gt;forced_types = ap_make_table (p, 4);
new-&gt;encoding_types = ap_make_table (p, 4);
</pre>


<p>Now, suppose we've just read in a .htaccess file. We already have the per-directory configuration structure for the next directory up in the hierarchy. If the .htaccess file we just read in didn't have any AddType or AddEncoding commands, its per-directory config structure for the MIME module is still valid, and we can just use it. Otherwise, we need to merge the two structures somehow.</p>

<p>To do that, the server invokes the module's per-directory config merge function, if one is present. That function takes three arguments: the two structures being merged, and a resource pool in which to allocate the result. For the MIME module, all that needs to be done is overlay the tables from the new per-directory config structure with those from the parent:</p>

<pre>
void *merge_mime_dir_configs (pool *p, void *parent_dirv, void *subdirv)
mime_dir_config *parent_dir = (mime_dir_config *)parent_dirv;
mime_dir_config *subdir = (mime_dir_config *)subdirv;
mime_dir_config *new =  (mime_dir_config *)ap_palloc (p, sizeof(mime_dir_config));
new-&gt;forced_types = ap_overlay_tables (p, subdir-&gt;forced_types, parent_dir-&gt;forced_types);
new-&gt;encoding_types = ap_overlay_tables (p, subdir-&gt;encoding_types, parent_dir-&gt;encoding_types);
</pre>


<p>As a note --- if there is no per-directory merge function present, the server will just use the subdirectory's configuration info, and ignore the parent's. For some modules, that works just fine (e.g., for the includes module, whose per-directory configuration information consists solely of the state of the XBITHACK), and for those modules, you can just not declare one, and leave the corresponding structure slot in the module itself NULL.</p>

<h3>Command handling</h3>
<p>Now that we have these structures, we need to be able to figure out how to fill them. That involves processing the actual AddType and AddEncoding commands. To find commands, the server looks in the module's command table. That table contains information on how many arguments the commands take, and in what formats, where it is permitted, and so forth. That information is sufficient to allow the server to invoke most command-handling functions with pre-parsed arguments. Without further ado, let's look at the AddType command handler, which looks like this (the AddEncoding command looks basically the same, and won't be shown here):</p>
<pre>
char *add_type(cmd_parms *cmd, mime_dir_config *m, char *ct, char *ext)
if (*ext == &#039;.&#039;) ++ext;
ap_table_set (m-&gt;forced_types, ext, ct);
</pre>

<p>This command handler is unusually simple. As you can see, it takes four arguments, two of which are pre-parsed arguments, the third being the per-directory configuration structure for the module in question, and the fourth being a pointer to a cmd_parms structure. That structure contains a bunch of arguments which are frequently of use to some, but not all, commands, including a resource pool (from which memory can be allocated, and to which cleanups should be tied), and the (virtual) server being configured, from which the module's per-server configuration data can be obtained if required.</p>

<p>Another way in which this particular command handler is unusually simple is that there are no error conditions which it can encounter. If there were, it could return an error message instead of NULL; this causes an error to be printed out on the server's stderr, followed by a quick exit, if it is in the main config files; for a .htaccess file, the syntax error is logged in the server error log (along with an indication of where it came from), and the request is bounced with a server error response (HTTP error status, code 500).</p>

<p>The MIME module's command table has entries for these commands, which look like this:</p>
<pre>
command_rec mime_cmds[] =
{ "AddType", add_type, NULL, OR_FILEINFO, TAKE2, "a mime type followed by a file extension" },
{ "AddEncoding", add_encoding, NULL, OR_FILEINFO, TAKE2, "an encoding (e.g., gzip), followed by a file extension" },
</pre>


<p>The entries in these tables are:</p>
<ul>
<li>The name of the command</li>
<li>The function which handles it a (void *) pointer, which is passed in the cmd_parms structure to the command handler --- this is useful in case many similar commands are handled by the same function.</li>
<li>A bit mask indicating where the command may appear. There are mask bits corresponding to each AllowOverride option, and an additional mask bit, RSRC_CONF, indicating that the command may appear in the server's own config files, but not in any .htaccess file.</li>
<li>A flag indicating how many arguments the command handler wants pre-parsed, and how they should be passed in. TAKE2 indicates two pre-parsed arguments. Other options are TAKE1, which indicates one pre-parsed argument, FLAG, which indicates that the argument should be On or Off, and is passed in as a boolean flag, RAW_ARGS, which causes the server to give the command the raw, unparsed arguments (everything but the command name itself). There is also ITERATE, which means that the handler looks the same as TAKE1, but that if multiple arguments are present, it should be called multiple times, and finally ITERATE2, which indicates that the command handler looks like a TAKE2, but if more arguments are present, then it should be called multiple times, holding the first argument constant.</li>
<li>Finally, we have a string which describes the arguments that should be present. If the arguments in the actual config file are not as required, this string will be used to help give a more specific error message. (You can safely leave this NULL).</li>
</ul>

<p>Finally, having set this all up, we have to use it. This is ultimately done in the module's handlers, specifically for its file-typing handler, which looks more or less like this; note that the per-directory configuration structure is extracted from the request_rec's per-directory configuration vector by using the ap_get_module_config function.</p>

<h3>Side notes --- per-server configuration, virtual servers, etc.</h3>
<p>The basic ideas behind per-server module configuration are basically the same as those for per-directory configuration; there is a creation function and a merge function, the latter being invoked where a virtual server has partially overridden the base server configuration, and a combined structure must be computed. (As with per-directory configuration, the default if no merge function is specified, and a module is configured in some virtual server, is that the base configuration is simply ignored).</p>

<p>The only substantial difference is that when a command needs to configure the per-server private module data, it needs to go to the cmd_parms data to get at it. Here's an example, from the alias module, which also indicates how a syntax error can be returned (note that the per-directory configuration argument to the command handler is declared as a dummy, since the module doesn't actually have per-directory config data):</p>




<p><a href="/htaccess/htaccess-rewrite.html">Continue Reading Page 2</a></p><p><a href="http://www.askapache.com/htaccess/htaccess.html"></a><a href="http://www.askapache.com/htaccess/htaccess.html">THE Ultimate Htaccess</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/htaccess.html/feed</wfw:commentRss>
		<slash:comments>88</slash:comments>
		</item>
	</channel>
</rss>

