<?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;  mp3</title>
	<atom:link href="http://www.askapache.com/search/mp3/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.askapache.com</link>
	<description>Advanced Web Development</description>
	<lastBuildDate>Mon, 06 Sep 2010 11:40:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Advanced Windows Batch File Scripting</title>
		<link>http://www.askapache.com/windows/advanced-batch-scripting.html</link>
		<comments>http://www.askapache.com/windows/advanced-batch-scripting.html#comments</comments>
		<pubDate>Fri, 03 Sep 2010 18:14:02 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Server Administration]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[.bat]]></category>
		<category><![CDATA[Advanced]]></category>
		<category><![CDATA[batch file]]></category>
		<category><![CDATA[cmd.exe]]></category>
		<category><![CDATA[Notepad]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[SSH Tunnels]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=4577</guid>
		<description><![CDATA[<p><a class="IFL" href="http://www.askapache.com/windows/advanced-batch-scripting.html"><img src="http://uploads.askapache.com/2010/09/windows-batch-file-example-116x45.png" alt="Windows Batch Programming Example" title="Windows Batch Programming Example" width="116" height="45" /></a>If for some reason you need to use windows .bat batch file scripting to do some task, or you just want to learn the most universal batch programming language on Windows machines, you lucked out and found the AskApache example.  My expertise is the shell, in this article the shell is Windows <code>cmd.exe</code>.  It has some pretty advanced windows shell usage, including pipes and redirection, but it's the modular linux-like coding approach that earns this script it's "advanced" title.</p>
<pre>:SETPROMPT
set PROMPT=$_[%USERNAME%@%USERDOMAIN%]$S[$P]$_$M$G &#38;&#38; EXIT /B</pre>

<p><a class="IFL" href="http://uploads.askapache.com/2010/09/Untitled-1.png"><img src="http://uploads.askapache.com/2010/09/Untitled-1-116x38.png" alt="Create an AT job to run as system in Notepad++ IDE" title="Create an AT job to run as system in Notepad++ IDE" width="116" height="38" class="size-thumbnail wp-image-4618" /></a>My favorite tool (and I've tried sooo many) for editing most Windows files and especially .bat files is the free and open-source <a href="http://notepad-plus-plus.org/">Notepad++</a>.  Set that up and you will have a color-syntax-highlighted editor for Batch Scripting that works very very well.<br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<div class='images'><a href='http://uploads.askapache.com/2010/09/Untitled-1.png'><img src="http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?fltr=usm&src=http://uploads.askapache.com/2010/09/Untitled-1.png&w=400" title=" featured" alt="Advanced Windows Batch File Scripting" /></a><a href='http://uploads.askapache.com/2010/09/windows-batch-file-example-116x45.png'><img src="http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?fltr=usm&src=http://uploads.askapache.com/2010/09/windows-batch-file-example-116x45.png&w=400" title=" featured" alt="Advanced Windows Batch File Scripting" /></a><a href='http://uploads.askapache.com/2010/09/Untitled-1-116x38.png'><img src="http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?fltr=usm&src=http://uploads.askapache.com/2010/09/Untitled-1-116x38.png&w=400" title=" featured" alt="Advanced Windows Batch File Scripting" /></a><a href='http://uploads.askapache.com/2010/09/windows-batch-file.png'><img src="http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?fltr=usm&src=http://uploads.askapache.com/2010/09/windows-batch-file.png&w=400" title=" featured" alt="Advanced Windows Batch File Scripting" /></a></div><p><a href="http://www.askapache.com/windows/advanced-batch-scripting.html/untitled-1/" rel="attachment wp-att-4618"><!-- IMAGE REMOVED BY wp-image-resizer HERE --></a></p>
<p><a class="IFL" href="http://uploads.askapache.com/2010/09/windows-batch-file-example.png"><!-- IMAGE REMOVED BY wp-image-resizer HERE --></a>First off, this is a single windows <code>.bat</code> file that I have written to do advanced batch scripting the easy way, meaning it&#8217;s mostly a series of functions you can call from the script or within other functions for extremely modular code.  Before you get all bent out of shape by my choice of words (&#8220;easy, modular&#8221;), when I say this is advanced I mean for Windows .bat files, one of the worlds worst scripting languages, but it works on all windows versions so it&#8217;s ideal for things like autorun, autoplay, custom startups, usb drives, etc..  If you are looking for information on how to use and program windows .bat files to do anything cool, this is the right place!  I tried my best to mimic linux shell-scripting, so it&#8217;s likely different than other batch files you have seen.<br class="C" /></p>
<h2>Batch File IDE and Script Source</h2>
<p><a class="IFL" href="http://uploads.askapache.com/2010/09/Untitled-1.png"><!-- IMAGE REMOVED BY wp-image-resizer HERE --></a>My favorite tool (and I&#8217;ve tried sooo many) for editing most Windows files and especially .bat files is the free and open-source <a href="http://notepad-plus-plus.org/">Notepad++</a>.  Set that up and you will have a color-syntax-highlighted editor for Batch Scripting that works very very well.<br class="C" /></p>
<p><a class="IFL" href='http://uploads.askapache.com/2010/09/advanced-batch-askapache.txt'><!-- IMAGE REMOVED BY wp-image-resizer HERE --></a>The next thing to do is <a href='http://uploads.askapache.com/2010/09/advanced-batch-askapache.txt'>download the source code</a>, which includes comments and formatting I had to remove for this online article.  Then rename from <code>.txt</code> to <code>.bat</code> and open in your IDE/text-editor of choice.<br class="C" /></p>
<h2>Quick Batch File Example</h2>
<p>This is a simple batch file named ping-check.bat that I use when rebooting remote servers.  The reboot is issued from an SSH session and causes the server to go down and then come back up.  When the server goes down the network goes down too so I fire this script up to continually ping the remote server until it responds, at which point I can ssh back in.</p>
<p>One of the first hacks for batch files is line 1, the PUSHD command cd&#8217;s the scripts working environment to the directory of the script itself.</p>
<pre>@ECHO OFF &amp;&amp; PUSHD &quot;%~dp0&quot; &amp;&amp; SETLOCAL
&nbsp;
CALL :PINGCHECK &quot;%~1&quot;
&nbsp;
nircmd.exe speak text &quot;PING RECEIVED.  HOST BACK ONLINE&quot; 7 60
ENDLOCAL &amp;&amp; POPD &amp;&amp; GOTO :EOF
&nbsp;
:PINGCHECK
ECHO CHECKING %~1
ping.exe -n 1 %~1 -w 5000 | FIND /C &quot;Reply from %~1&quot; | FIND &quot;1&quot; &gt;nul 2&gt;&amp;1
IF ERRORLEVEL 1 CALL :PINGCHECK &quot;%~1&quot; ELSE EXIT /B</pre>
<h2>Super-hero like even</h2>
<p>Just added this as an after thought, moving the main example further down this page.  This is an easier file to understand the scope of.  It effectively creates SSH-encrypted SOCK5 tunnels that stay connected and auto-reconnect if the link goes down.  I wanted to try and write a pure batch method to do that.   I wrote this to run automatically from a USB key so that I could keep my tools with me portably.  The thing of this script that is the most revolutionary is the method it uses to create auto-reconnecting <em>SSH-encrypted SOCKS5 tunnels</em> using the windows SYSTEM account to do it all in the background with plink.exe.  The hack to run it as a system account is by using the built-in <strong>AT</strong> command to run interactively, which lets you interactively do whatever you want as the builtin <code>NT AUTHORITY/SYSTEM</code> account.  The other part I am proud of with this is how lean I got the code, specifically how lean the function is that creates the at job to run every 5 minutes, while still doing connection-testing, all by parsing the cmd.exe processors builtin in DATE and TIME variables.  Do a google search for &#8220;windows batch file date and time&#8221; and you will appreciate just how lean this sucker is.</p>
<p>Almost forgot, check out the ways to keep a plink.exe (putty.exe for cmd.exe) SOCKS5 tunnel hidden and safe and continuously connected to a remote server in minimal lines od code.  This was a fun one to work on!  Enjoy (and remember this is just the warm-up example to glance at).</p>
<pre>@ECHO OFF &amp;&amp; PUSHD &quot;%~dp0&quot; &amp;&amp; SETLOCAL &amp;&amp; SETLOCAL ENABLEDELAYEDEXPANSION &amp;&amp; SETLOCAL ENABLEEXTENSIONS
&nbsp;
SET _CRYPTDRIVE=%~d0\
SET PATH=%_CRYPTDRIVE%PP;%_CRYPTDRIVE%PP\bin;%PATH%
SET _PUTTYBIN=%_CRYPTDRIVE%P\PP\putty.exe
&nbsp;
SET _PSERVER=solar.power.com
SET _PPORT=22
SET _PSESSION=newclean-tunnel
&nbsp;
SET _ADMINUSER=admin
SET _RUNUSER=life
&nbsp;
REM SAY CHECKING PLINK OUT LOUD
CALL :SPEAK &quot;Checking Putty&quot;
ECHO &quot;CHECKING PUTTY&quot;
&nbsp;
REM
IF NOT EXIST &quot;%_CRYPTDRIVE%&quot; (
  CALL :SPEAK &quot;Crypt Not Mounted&quot;
  AT|FOR /F &quot;tokens=1&quot; %%i IN (&#039;FIND /I &quot;%~f0&quot;&#039;) DO AT %%i /delete /yes &gt;nul 2&gt;&amp;1
  pskill.exe -t putty &gt;nul 2&gt;&amp;1
  pskill.exe -t thunderbird &gt;nul 2&gt;&amp;1
  pskill.exe -t ThunderbirdPortable &gt;nul 2&gt;&amp;1
  pskill.exe -t Firefox &gt;nul 2&gt;&amp;1
  pskill.exe -t FirefoxPortable &gt;nul 2&gt;&amp;1
  pskill.exe -t GC &gt;nul 2&gt;&amp;1
  EXIT
)
&nbsp;
REM CREATE AT JOB TO RUN THIS SCRIPT EVERY 5 MINUTES
CALL :CREATEATJOB
&nbsp;
pslist putty &gt;nul 2&gt;&amp;1
IF ERRORLEVEL 1 psexec.exe -i 0 -e -d -u %_RUNUSER% %_PUTTYBIN% -load %_PSESSION%
&nbsp;
REM KILL MULTIPLE PSEXEC&#039;s
CALL :KILLDUPES &quot;psexec.exe&quot;
&nbsp;
REM KILL MULTIPLE CMD.EXE&#039;s
CALL :KILLDUPES &quot;cmd.exe&quot;
&nbsp;
REM REACHABLE SERVER CHECK
CALL :PINGCHECK %_PSERVER%
&nbsp;
REM CHECK FOR INACTIVE PUTTY
CALL :PUTTYCHECK
&nbsp;
REM CHECK PORT IS LISTENING (FOR SOCKISFIED TUNNEL)
CALL :PORTCHECK %_PPORT%
&nbsp;
REM CALL :SPEAK &quot;OK&quot;
SLEEP 100 &amp;&amp; ECHO &quot;OK&quot; &amp;&amp; SLEEP 1 &amp;&amp; ENDLOCAL &amp;&amp; POPD &amp;&amp; EXIT
&nbsp;
REM =======================================================================================
REM =   SPEAK - Speak text
REM =======================================================================================
:SPEAK
nircmd.exe speak text &quot;%~1&quot; 5 60
ECHO &quot;%~1&quot;
EXIT /B
&nbsp;
REM =======================================================================================
REM =   RESTARTPLINK - Sleeps for %1 number of seconds
REM =======================================================================================
:RESTARTPLINK
CALL :SPEAK &quot;%~1 ReSTARTing Plink&quot;
REM runas /savecred /user:admin &quot;%_PUTTYBIN% -load %_PSESSION%&quot;
psexec.exe -i 0 -e -d -u %_RUNUSER% %_PUTTYBIN% -load %_PSESSION%
EXIT
EXIT /B
&nbsp;
REM =======================================================================================
REM =   PORTCHECK - Check that Port is being used (for tunnels)
REM =======================================================================================
:PORTCHECK
netstat.exe -n -v -a -p TCP | FIND &quot;ESTABLISHED&quot; | FIND &quot;:%~1&quot; &gt;nul 2&gt;&amp;1
IF ERRORLEVEL 1 CALL :RESTARTPLINK &quot;PORT CHECK FAILED&quot;
EXIT /B
&nbsp;
REM =======================================================================================
REM =   INACTIVEPUTTYCHECK - Check for inactive putty windows
REM =======================================================================================
:PUTTYCHECK
tasklist.exe /V /NH /FI &quot;WINDOWTITLE eq PuTTY (inactive)&quot; 2&gt;nul|FIND &quot;INFO: &quot; &gt;nul 2&gt;&amp;1
IF ERRORLEVEL 1 taskkill.exe /T /F /FI &quot;WINDOWTITLE eq PuTTY (inactive)&quot; &gt;nul 2&gt;&amp;1
&nbsp;
:: MAKE SURE ONLY 1 putty is running that is connected to the remote server
netstat.exe -n -a -o -p TCP | FIND &quot;:%_PPORT%&quot; | FIND /C &quot;:%_PPORT%&quot; | FIND &quot;1&quot; &gt;nul 2&gt;&amp;1
IF ERRORLEVEL 1 (
  tasklist.exe /V /FO TABLE /NH /FI &quot;IMAGENAME eq putty.exe&quot; 2&gt;nul | FIND /C &quot;Running&quot; | FIND &quot;1&quot; &gt;nul 2&gt;&amp;1
  IF ERRORLEVEL 1 (
    REM kill all running puttys (owned by system)
    FOR /F &quot;usebackq tokens=2 skip=2&quot; %%p IN (`tasklist.exe /V /FO TABLE /NH /FI &quot;IMAGENAME eq putty.exe&quot;`) DO taskkill.exe /F /PID %%p /T &gt;nul 2&gt;&amp;1
    CALL :RESTARTPLINK &quot;EXTRA PUTTY FOUND&quot;
  )
)
EXIT /B
&nbsp;
REM =======================================================================================
REM =   PINGCHECK - PING address to make sure it is reachable
REM =======================================================================================
:PINGCHECK
PING %~1 -n 1 -w 5000 | FIND &quot;TTL=&quot; &gt;nul 2&gt;&amp;1
IF ERRORLEVEL 1 (
  PING google.com -n 1 -w 500 | FIND &quot;TTL=&quot; &gt;nul 2&gt;&amp;1
  IF ERRORLEVEL 1 ( CALL :SPEAK &quot;CHECK INTERNET CONNECTION&quot; &amp;&amp; SLEEP 60 )

  PING google.com -n 1 -w 5000 | FIND &quot;TTL=&quot; &gt;nul 2&gt;&amp;1
  IF ERRORLEVEL 1 ( CALL :SPEAK &quot;CHECK INTERNET CONNECTION&quot; &amp;&amp; SLEEP 60 )
&nbsp;
  PING google.com -n 1 -w 5000 | FIND &quot;TTL=&quot; &gt;nul 2&gt;&amp;1
  IF ERRORLEVEL 1 (
    CALL :SPEAK &quot;KILL SOCKS PROGRAMS&quot;
  SLEEP 100
  pskill.exe -t putty &gt;nul 2&gt;&amp;1
  pskill.exe -t thunderbird &gt;nul 2&gt;&amp;1
  pskill.exe -t ThunderbirdPortable &gt;nul 2&gt;&amp;1
  )
)
EXIT /B
&nbsp;
REM =======================================================================================
REM =   KILLDUPES - kills duplicate processes, except for the one with lowest pid
REM =======================================================================================
:KILLDUPES
REM Check that more than 1 process is running
tasklist.exe /V /NH /FI &quot;IMAGENAME eq %~1&quot; /FI &quot;USERNAME eq SYSTEM&quot; 2&gt;nul | FIND /C &quot;K Running&quot; | FIND &quot;1&quot; &gt;nul 2&gt;&amp;1
IF NOT ERRORLEVEL 1 EXIT /B
&nbsp;
REM Create Filename in current dir (of this script)
SET _T=%TIME: =0%&amp;&amp;SET _T=!_T::=-!&amp;&amp;SET _T=%~dp0%!_T:~0,-2!log
&nbsp;
REM Create the file in the same dir as this script named for date and sorted by PID
tasklist.exe /V /NH /FI &quot;IMAGENAME eq %~1&quot; /FI &quot;USERNAME eq SYSTEM&quot; 2&gt;nul | SORT /+29 &gt; &quot;%_T%&quot;

REM Check that the file was created or exit
IF NOT EXIST &quot;%_T%&quot; ( CALL :SPEAK &quot;FILE CREATION FAILED&quot; &amp;&amp; EXIT /B )

REM kill all the processes found except for 1, do not kill the process with the lowest pid number
FOR /F &quot;tokens=2 skip=2&quot; %%p IN (%_T%) DO taskkill.exe /F /PID %%p /T

REM erase the file
REM ERASE /Q &quot;%_T%&quot; &gt;nul 2&gt;&amp;1

REM check that the file was erased
REM IF EXIST &quot;%_T%&quot; ( CALL :SPEAK &quot;ERASE FILE FAILED&quot; &amp;&amp; EXIT /B )
&nbsp;
EXIT /B
&nbsp;
REM =======================================================================================
REM =   CREATEATJOB - runs job (START this file) every 5 minutes
REM =======================================================================================
:CREATEATJOB
:: delete all putty AT jobs
AT | FIND /C &quot;%~f0&quot; | FIND &quot;1&quot; &gt;nul 2&gt;&amp;1
IF ERRORLEVEL 1 ( AT|FOR /F &quot;tokens=1&quot; %%i IN (&#039;FIND /I &quot;%~f0&quot;&#039;) DO AT %%i /delete /yes &gt;nul 2&gt;&amp;1 )
SET /A H=!TIME:~0,2!&amp;&amp; SET M=!TIME:~3,2!
SET Y=%H%:%M%&amp;&amp; SET /A M+=5
IF !M! GEQ 61 ( SET /A H+=1&amp;&amp;SET /A M-=61 )
IF !H! GEQ 24 SET /A H-=24
SET M=0!M!&amp;&amp; SET H=0!H!
:: create AT job
AT %H:~-2%:%M:~-2% /INTERACTIVE %ComSpec% /E:ON /D /Q /C START /B /MIN %ComSpec% /E:ON /D /Q /C &quot;%~f0&quot; &gt;nul
EXIT /B</pre>
<h2>Advanced Batch File</h2>
<p>This is the main batch file example which you can <a href="http://uploads.askapache.com/2010/09/advanced-batch-askapache.txt">download here</a>.  Other than some minor changes this is the actual script I use at work when I logon to my PC.  The first thing it does is mount an encrypted TrueCrypt Drive where all of my files and settings are located.  It also starts a putty session named &#8220;1&#8243; that I configured to start a few encrypted tunnels and socks proxies so that my email Thunderbird and Website IDE Dreamweaver and other network apps can communicate 100% encrypted and my real location becomes hidden (thanks socks!).</p>
<p>I might come back later and add comments if I get any kind of response for this article, and because it&#8217;s such a unique and low-traffic topic, I will try to answer any questions added with the comment form.</p>
<h2>Starting the Script</h2>
<p>The first line is of my own design and is perhaps the coolest hack in the script.  I use this 1 line to start pretty much all of my .bat files.</p>
<pre>@ECHO OFF&amp;&amp; SETLOCAL&amp;&amp; PUSHD &quot;%~dp0&quot;&amp;&amp; SETLOCAL ENABLEDELAYEDEXPANSION&amp;&amp; SETLOCAL ENABLEEXTENSIONS&amp;&amp; SET V=5&amp;&amp; IF NOT &quot;!V!&quot;==&quot;5&quot; (ECHO DelayedExpansion Failed&amp;&amp; GOTO :EOF)</pre>
<h2>SCRIPT VARIABLES</h2>
<p>These are all local to this script thanks to the SETLOCAL above, so they won&#8217;t exist outside the scripts execution environment.</p>
<pre>REM ** Various vars for output used by functions
SET P1=^^^&gt;^^^&gt;^^^&gt;
SET P2=++
SET P3=::
SET L1=+==============================================================================================================+
SET L2=+&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;&#45;&#45;-+
&nbsp;
REM ** administrator username, unless changed for more security, its Administrator
SET ADMINUSER=admin
&nbsp;
REM ** runuser is the username you use when running this script
SET RUNUSER=bill
&nbsp;
REM ** Custom COMSPEC for running cmd.exe
SET _SCOM=%COMSPEC% /E:ON /F:ON /D /Q /T:0C /C
&nbsp;
REM ** Custom START command
SET _START=START /WAIT /MIN /B %_SCOM%</pre>
<h2>MAIN PROGRAM EXECUTION</h2>
<p>This is where the main code starts, note how small it is thanks to the use of functions (labels/call/goto).  Read the comments in this area (start with :: or REM ) to see the extent of this script.  The gold is in the functions.</p>
<pre>:: Only allow certain users to run this script or die (prevents global STARTup or service running it)
CALL :CHECKUSERVALID %RUNUSER% %ADMINUSER%
&nbsp;
:: Mount the truecrypt container
CALL :CRYPTMOUNT &quot;L&quot; &quot;%SYSTEMDRIVE%\CRYPT\LEONARDO&quot; &quot;%SYSTEMDRIVE%\CRYPT\LEONARDO_KEY&quot;
&nbsp;
:: Start Mozilla Firefox
CALL :RUNONE &quot;C:\Program Files\Mozilla Firefox\firefox.exe&quot;
&nbsp;
:: Start Thunderbird Portable
CALL :RUNONE &quot;L:\P\PP\putty.exe&quot; &quot;/MIN&quot; -load 1
&nbsp;
:: Start Thunderbird Portable
CALL :RUNONE &quot;L:\P\TB\ThunderbirdPortable.exe&quot; &quot;/MIN&quot;
&nbsp;
:: Start Adobe Dreamweaver CS4
CALL :RUNONE &quot;C:\Program Files\Adobe\Adobe Dreamweaver CS4\Dreamweaver.exe&quot; &quot;/MIN&quot;
&nbsp;
:: Start LightScreen Portable
CALL :RUNONE &quot;L:\P\LP\LightscreenPortable.exe&quot; /B /B
&nbsp;
:: Start Google Chrome Portable ( GREAT to use for pandora/last.fm as its so low mem )
CALL :RUNONE &quot;L:\P\GC\GC.exe&quot; &quot;/NORMAL&quot;
&nbsp;
:: Start Adobe Photoshop CS4
CALL :RUNONE &quot;%ProgramFiles%\Adobe\Adobe Photoshop CS4\Photoshop.exe&quot; &quot;/MAX&quot;</pre>
<h3>Exit Script</h3>
<p>This is the last line executed in the Main, it forces the script to exit cleanly at this point, otherwise the functions below would all get executed.  This is what allows the use of all the functions below.  I end all my scripts MAIN with this.</p>
<pre>REM ** EXIT Script
CALL :MDYE &quot;EOF&quot; &amp;&amp; POPD &amp;&amp; ENDLOCAL &amp;&amp; GOTO :EOF</pre>
<h2>SCRIPT FUNCTIONS</h2>
<p>Now then, onto the MEAT of the script, all the functions.  These functions are designed for global use in other batch files, so that the only modification when you make a new batch is the above variables and main execution..  If you know much about batch files you will realize that creating these functions was a very painful process in some cases.. I freakin hate windows!  Anyway, enjoy!</p>
<h3>CRYPTMOUNT &#8211; mounts a truecrypt container and returns to CALLer. On fail, quit</h3>
<pre>REM
REM     CALL :CRYPTMOUNT &quot;%LEONARDO%&quot; &quot;%LEONARDO_FILE%&quot; &quot;%LEONARDO_KEY%&quot;
REM     CALL :CRYPTMOUNT &quot;L&quot; &quot;%SYSTEMDRIVE%\CRYPT\LEONARDO&quot; &quot;%SYSTEMDRIVE%\CRYPT\LEONARDO_KEY&quot;
REM
REM :: print the settings
REM :: CALL :MP 3 &quot;DRIVE: %DRIVE%&quot;&amp;&amp;CALL :MP 3 &quot; FILE: %FILE%&quot;&amp;&amp;CALL :MP 3 &quot;  KEY: %KEY%&quot;&amp;&amp;CALL :MP 3 &quot;  VOL: %VOL%&quot;</pre>
<pre>:CRYPTMOUNT
SET DRIVE=%~1&amp;&amp; SET FILE=%~2&amp;&amp; SET KEY=%~3&amp;&amp; SET VOL=!FILE:~0,3!
CALL :MP 1 &quot;Mounting TrueCrypt on %DRIVE% from %FILE%&quot;
&nbsp;
:: Check for Truecrypt or die
CALL :EXISTORQUIT &quot;%ProgramFiles%\TrueCrypt\TrueCrypt.exe&quot; &amp;&amp; CALL :EXISTORQUIT &quot;%FILE%&quot; &amp;&amp; CALL :EXISTORQUIT &quot;%KEY%&quot;
&nbsp;
:: checks that MOUNTVOL works and the drive containing the truecrypt container file is present or dies
MOUNTVOL %VOL% /L 2&gt;NUL | FIND &quot;\\?\Volume{&quot; &gt;NUL 2&gt;&amp;1
IF ERRORLEVEL 1 CALL :MDYE &quot;%VOL% NOT FOUND&quot;
&nbsp;
REM ** Converts G:\ to its \\?\Volume{234234}\ equivalent for greater portability
FOR /F %%i IN (&#039;MOUNTVOL %VOL% /L&#039;) DO @SET VOL=%%i%FILE:~3%
&nbsp;
:: IF the drive is already mounted then continue, otherwise try to mount
MOUNTVOL %DRIVE%:\ /L &gt;NUL 2&gt;&amp;1
IF NOT ERRORLEVEL 1 (
  CALL :MP 2 &quot;%DRIVE% ALREADY MOUNTED&quot; &amp;&amp; EXIT /B
) ELSE (
  START &quot;Mounting TrueCrypt&quot; /D&quot;%ProgramFiles%\TrueCrypt&quot; /MIN /B TrueCrypt.exe /c n /b /q background /h n /k %KEY% /l %DRIVE% /p /v %VOL% &amp;&amp; SLEEP 10
)
&nbsp;
:: try again in case of bad password and accidental keypress
MOUNTVOL %DRIVE%:\ /L &gt;NUL 2&gt;&amp;1
IF ERRORLEVEL 1 (START &quot;Mounting TrueCrypt&quot; /D&quot;%ProgramFiles%\TrueCrypt&quot; /MIN /B TrueCrypt.exe /c n /b /q background /h n /k %KEY% /l %DRIVE% /p /v %VOL% &amp;&amp; SLEEP 10)
&nbsp;
:: IF it still doesnt exist then quit
MOUNTVOL %DRIVE%:\ /L &gt;NUL 2&gt;&amp;1
IF ERRORLEVEL 1 CALL :MDYE &quot;Failed to mount %FILE% on %DRIVE%&quot;
&nbsp;
CALL :MF &amp;&amp; ENDLOCAL &amp;&amp; EXIT /B
EXIT /B</pre>
<h3>RUNONE &#8211; Starts one instance of executable after verifying it exists and is not already running.</h3>
<pre>REM     %~1 is location of executatable
REM     %~2 is optional (unless %~3 is used) START parameters
REM     %~3 is optional parameters for executable
REM
REM     CALL :RUNONE &quot;L:\P\LP\LightscreenPortable.exe&quot; &quot;/MAX&quot; &quot;/HIDE&quot;</pre>
<pre>:RUNONE
SETLOCAL
CALL :MP 1 &quot;Starting %~n1&quot;
&nbsp;
:: SLEEP FOR NICENESS, LOCAL VARS _P2 and _P3
SLEEP 2 &amp;&amp; SETLOCAL
&nbsp;
SET P=%~1
ECHO %P%|FIND &quot; &quot; &gt;NUL 2&gt;&amp;1
IF NOT ERRORLEVEL 1 ( PUSHD &quot;%~dp1&quot; &amp;&amp; SET P=%~nx1 )
&nbsp;
:: SET _P2 TO DEFAULT TO &quot;/MIN&quot; IF EMPTY
SET _P2=/MIN
IF NOT &quot; %~2&quot; == &quot; &quot; SET _P2=%~2
IF NOT &quot; %~3&quot; == &quot; &quot; SET _P3=%~3
IF NOT &quot; %~4&quot; == &quot; &quot; SET _P4=%~4
&nbsp;
:: CHECK THAT EXECUTABLE EXISTS
CALL :EXISTORQUIT &quot;%~1&quot;
&nbsp;
REM ECHO START %_P2% /D&quot;%~dp1&quot; %P% %_P3% %_P4%&amp;&amp; PAUSE&amp;&amp;
:: CHECK FOR EXISTING PROCESSNAME ( %~n1 is file name without ext, %~nx1 is the file name and extension. )
pslist.exe /e %~n1 &gt;NUL 2&gt;&amp;1
IF ERRORLEVEL 1 (START %_P2% /D&quot;%~dp1&quot; %P% %_P3% %_P4% ) ELSE (CALL :MP 2 &quot;%~n1 already running!&quot; )
&nbsp;
ENDLOCAL &amp;&amp; EXIT /B</pre>
<h3>ADMINRUNONE &#8211; Runs %1 with admin rights IF neccessary</h3>
<pre>:ADMINRUNONE
CALL :MP 3 &quot;Exec %~1 as %ADMINUSER%&quot;
&nbsp;
:: Check that file exists
CALL :EXISTORQUIT &quot;%~1&quot;
&nbsp;
:: test for rights to the task scheduler
:: %SYSTEMDRIVE%\WINDOWS\system32\cmd.exe /E:ON /D /Q /T:0C /C START /WAIT /MIN /B %SYSTEMDRIVE%\WINDOWS\system32\cmd.exe /E:ON /D /Q /T:0C /C %~1
AT &gt;NUL 2&gt;&amp;1
IF ERRORLEVEL 1 (
  RUNAS /noprofile /user:%USERDOMAIN%\%ADMINUSER% &quot;%~1&quot;
) ELSE (
  %COMSPEC% /E:ON /D /Q /T:0C /C &quot;%~1&quot;
)
SLEEP 2 &amp;&amp; CALL :MF &amp;&amp; EXIT /B</pre>
<h3>CHECKUSERVALID &#8211; checks that defined username equals %ADMINUSER% or %RUNUSER%, then returns to CALLer</h3>
<pre>:CHECKUSERVALID
:: EXIT IF USERNAME IS NOT DEFINED, CATCHES SYSTEM ACCOUNTS TRYING TO RUN WHEN IN GLOBAL STARTUP
IF NOT DEFINED USERNAME EXIT
&nbsp;
SETLOCAL
SET UP=no
SET _P1= %~1
SET _P2= %~2
IF NOT &quot;%_P1%&quot; == &quot; &quot; ( IF /I &quot;%~1&quot; == &quot;%USERNAME%&quot; SET UP=yes)
IF NOT &quot;%_P1%&quot; == &quot; &quot; ( IF /I &quot;%~1&quot; == &quot;%USERNAME%&quot; SET UP=yes)
IF NOT &quot;%_P1%&quot; == &quot; &quot; ( IF /I &quot;%~1&quot; == &quot;%USERNAME%&quot; SET UP=yes)
IF /I &quot;bill&quot; == &quot;%USERNAME%&quot; SET UP=yes
IF /I &quot;newbill&quot; == &quot;%USERNAME%&quot; SET UP=yes
IF /I &quot;max&quot; == &quot;%USERNAME%&quot; SET UP=yes
IF /I NOT &quot;%UP%&quot; == &quot;yes&quot; EXIT
ENDLOCAL
EXIT /B</pre>
<h3>SETPROMPT &#8211; sets prompt, then returns to CALLer</h3>
<pre>REM =   [user@MACHINE] [C:\DR\PEPPER\SCRIPTS]
REM =   &gt; REG /?</pre>
<pre>:SETPROMPT
set PROMPT=$_[%USERNAME%@%USERDOMAIN%]$S[$P]$_$M$G &amp;&amp; EXIT /B</pre>
<h3>BEEP &#8211; beeps once, then returns to CALLer</h3>
<p>The character after the echo is the actual BEL char, so unless you have my source file, you will need to copy a literal BEL char here to make it beep.</p>
<pre>:BEEP
@ECHO  &amp;&amp; EXIT /B</pre>
<h3>MSETCOLOR &#8211; SET colors for screen, then returns to CALLer</h3>
<pre>REM
REM     0 = Black       8 = Gray
REM     1 = Blue        9 = Light Blue
REM     2 = Green       A = Light Green
REM     3 = Aqua        B = Light Aqua
REM     4 = Red         C = Light Red
REM     5 = Purple      D = Light Purple
REM     6 = Yellow      E = Light Yellow
REM     7 = White       F = Bright White
REM</pre>
<pre>:MSETCOLOR
COLOR %~1 &amp;&amp; EXIT /B</pre>
<h3>MSETCONSOLE &#8211; sets the cols and lines of current screen buffer, then returns to CALLer</h3>
<pre>:MSETCONSOLE
MODE CON COLS=%~1 LINES=%~2 &amp;&amp; EXIT /B</pre>
<h3>PARAMTEST &#8211; tests params, then returns to CALLer</h3>
<pre>:PARAMTEST
ECHO. &amp;&amp; CALL :MP 1 &quot;PARAMTEST CALLED WITH: %*&quot; &amp;&amp; ECHO %L1%
SET _P= %~1
IF NOT &quot;%_P%&quot; == &quot; &quot; ( ECHO %%1          = %1 &amp;&amp; ECHO %%~f1        = %~f1 &amp;&amp; ECHO %%~d1        = %~d1 &amp;&amp; ECHO %%~p1        = %~p1
  ECHO %%~n1        = %~n1 &amp;&amp; ECHO %%~x1        = %~x1 &amp;&amp; ECHO %%~s1        = %~s1 &amp;&amp; ECHO %%~dp1       = %~dp1
  ECHO %%~nx1       = %~nx1 &amp;&amp; ECHO %%~$PATH:1   = %~$PATH:1 &amp;&amp; ECHO %%~dp$PATH:1 = %~dp$PATH:1 &amp;&amp; ECHO %L1% )
SET _P= %~2
IF NOT &quot;%_P%&quot; == &quot; &quot; ( ECHO %%2          = %2 &amp;&amp; ECHO %%~f2        = %~f2 &amp;&amp; ECHO %%~d2        = %~d2 &amp;&amp; ECHO %%~p2        = %~p2
  ECHO %%~n2        = %~n2 &amp;&amp; ECHO %%~x2        = %~x2 &amp;&amp; ECHO %%~s2        = %~s2 &amp;&amp; ECHO %%~dp2       = %~dp2
  ECHO %%~nx2       = %~nx2 &amp;&amp; ECHO %%~$PATH:2   = %~$PATH:2 &amp;&amp; ECHO %%~dp$PATH:2 = %~dp$PATH:2 &amp;&amp; ECHO %L1% )
SET _P= %~3
IF NOT &quot;%_P%&quot; == &quot; &quot; ( ECHO %%3          = %3 &amp;&amp; ECHO %%~f3        = %~f3 &amp;&amp; ECHO %%~d3        = %~d3 &amp;&amp; ECHO %%~p3        = %~p3
  ECHO %%~n3        = %~n3 &amp;&amp; ECHO %%~x3        = %~x3 &amp;&amp; ECHO %%~s3        = %~s3 &amp;&amp; ECHO %%~dp3       = %~dp3
  ECHO %%~nx3       = %~nx3 &amp;&amp; ECHO %%~$PATH:3   = %~$PATH:3 &amp;&amp; ECHO %%~dp$PATH:3 = %~dp$PATH:3 &amp;&amp; ECHO %L1% )
SET _P= %~4
IF NOT &quot;%_P%&quot; == &quot; &quot; ( ECHO %%4          = %4 &amp;&amp; ECHO %%~f4        = %~f4 &amp;&amp; ECHO %%~d4        = %~d4 &amp;&amp; ECHO %%~p4        = %~p4
  ECHO %%~n4        = %~n4 &amp;&amp; ECHO %%~x4        = %~x4 &amp;&amp; ECHO %%~s4        = %~s4 &amp;&amp; ECHO %%~dp4       = %~dp4
  ECHO %%~nx4       = %~nx4 &amp;&amp; ECHO %%~$PATH:4   = %~$PATH:4 &amp;&amp; ECHO %%~dp$PATH:4 = %~dp$PATH:4 &amp;&amp; ECHO %L1% )
SET _P= %~5
IF NOT &quot;%_P%&quot; == &quot; &quot; ( ECHO %%5          = %5 &amp;&amp; ECHO %%~f5        = %~f5 &amp;&amp; ECHO %%~d5        = %~d5 &amp;&amp; ECHO %%~p5        = %~p5
  ECHO %%~n5        = %~n5 &amp;&amp; ECHO %%~x5        = %~x5 &amp;&amp; ECHO %%~s5        = %~s5 &amp;&amp; ECHO %%~dp5       = %~dp5
  ECHO %%~nx5       = %~nx5 &amp;&amp; ECHO %%~$PATH:5   = %~$PATH:5 &amp;&amp; ECHO %%~dp$PATH:5 = %~dp$PATH:5 &amp;&amp; ECHO %L1% )
SET _P= %~6
IF NOT &quot;%_P%&quot; == &quot; &quot; ( ECHO %%6          = %6 &amp;&amp; ECHO %%~f6        = %~f6 &amp;&amp; ECHO %%~d6        = %~d6 &amp;&amp; ECHO %%~p6        = %~p6
  ECHO %%~n6        = %~n6 &amp;&amp; ECHO %%~x6        = %~x6 &amp;&amp; ECHO %%~s6        = %~s6 &amp;&amp; ECHO %%~dp6       = %~dp6
  ECHO %%~nx6       = %~nx6 &amp;&amp; ECHO %%~$PATH:6   = %~$PATH:6 &amp;&amp; ECHO %%~dp$PATH:6 = %~dp$PATH:6 &amp;&amp; ECHO %L1% )
SET _P= %~7
IF NOT &quot;%_P%&quot; == &quot; &quot; ( ECHO %%7          = %7 &amp;&amp; ECHO %%~f7        = %~f7 &amp;&amp; ECHO %%~d7        = %~d7 &amp;&amp; ECHO %%~p7        = %~p7
  ECHO %%~n7        = %~n7 &amp;&amp; ECHO %%~x7        = %~x7 &amp;&amp; ECHO %%~s7        = %~s7 &amp;&amp; ECHO %%~dp7       = %~dp7
  ECHO %%~nx7       = %~nx7 &amp;&amp; ECHO %%~$PATH:7   = %~$PATH:7 &amp;&amp; ECHO %%~dp$PATH:7 = %~dp$PATH:7 &amp;&amp; ECHO %L1% )
SLEEP 3
CALL :MF
EXIT /B</pre>
<h3>PARAMTESTHELP &#8211; show params help, then returns to CALLer</h3>
<pre>:PARAMTESTHELP
ECHO %%~1 Expands %%1 and removes any surrounding quotation marks
ECHO %%~f1 Expands %%1 to a fully qualified path name.
ECHO %%~d1 Expands %%1 to a drive letter.
ECHO %%~p1 Expands %%1 to a path.
ECHO %%~n1 Expands %%1 to a file name.
ECHO %%~x1 Expands %%1 to a file extension.
ECHO %%~s1 Expanded path contains short names only.
ECHO %%~a1 Expands %%1 to file attributes.
ECHO %%~t1 Expands %%1 to date and time of file.
ECHO %%~z1 Expands %%1 to size of file.
ECHO %%~dp1 Expands %%1 to a drive letter and path.
ECHO %%~nx1 Expands %%1 to a file name and extension.
ECHO %%~ftza1 Expands %%1 to a dir-like output line.
ECHO %%~$PATH:1 Searches the dirs in PATH expanding %%1 to fully qualified name of first found. If var name isn&#039;t defined or the files not found, expands to empty string.
ECHO %%~dp$PATH:1 Searches the directories listed in the PATH environment variable for %%1 and expands to the drive letter and path of the first one found.
CALL :MF
EXIT /B</pre>
<h3>EXAMINEFILE &#8211; FINDs useful strings in file, then returns to CALLer</h3>
<pre>:EXAMINEFILE
CALL :MP 1 &quot;Examine File %~1&quot;
CALL :EXISTORQUIT &quot;%~1&quot;
STRINGS &quot;%~1&quot; | FINDSTR /R /C:&quot;[A-Z][A-Z]\=&quot;
CALL :MF
EXIT /B</pre>
<h3>ADMINSHELL &#8211; sets prompt, then returns to CALLer</h3>
<pre>:ADMINSHELL
CALL :MP 1 &quot;Creating Admin Shell&quot;
CALL :EXISTORQUIT &quot;%SYSTEMROOT%\system32\runas.exe&quot;
START %SYSTEMROOT%\system32\runas.exe /profile /savecred /user:%ADMINUSER% &quot;%COMSPEC% /T:0C /E:ON /F:ON /K cmd.exe /K cd C:\CRYPT\BIN&quot;
CALL :MF
EXIT /B</pre>
<h3>EXISTORQUIT &#8211; checks %~1 exists, IF it does returns to CALLer, otherwise, quit</h3>
<pre>:EXISTORQUIT
:: CALL :MP 1 &quot;Checking for %~1&quot;
IF NOT EXIST &quot;%~1&quot; CALL :MDYE &quot;%~1 NOT FOUND&quot;
EXIT /B</pre>
<h3>RR &#8211; IF file %1 EXISTs then :MT &#8220;Removing %1&#8243; then :MF, then ( or IF %1 not EXISTs)  returns to CALLer</h3>
<pre>:RR
CALL :MP 1 &quot;Removing %~1&quot;
IF EXIST &quot;%~1&quot; ERASE /q &quot;%~1&quot;
CALL :MF &amp;&amp; EXIT /B</pre>
<h3>LOCKDOWN  &#8211; locks workstation, then returns to CALLer (pointless)</h3>
<pre>:LOCKDOWN
RUNDLL32 USER32.DLL,LockWorkStation &amp;&amp; EXIT /B</pre>
<h3>SHUTDOWNIN &#8211; initiates shutdown, then returns to CALLer (pointless)</h3>
<pre>REM shutdown /a aborts</pre>
<pre>:SHUTDOWNIN
SHUTDOWN -r -t &quot;%~1&quot; &amp;&amp; EXIT /B</pre>
<h3>LISTSERVICES &#8211; lists services, then returns to CALLer</h3>
<pre>:LISTSERVICES
SC query state= all type= all | FOR /F &quot;tokens=2&quot; %%i IN (&#039;FIND /I &quot;SERVICE_NAME&quot;&#039;) DO @ECHO %%i
SC query | FOR /F &quot;tokens=2&quot; %%i IN (&#039;FIND /I &quot;SERVICE_NAME&quot;&#039;) DO @ECHO %%i
EXIT /B</pre>
<h3>TASKS &#8211; Advanced Tasklisting</h3>
<pre>:TASKS
SET _P=%~1
SET _PP= %~1
IF &quot;%_PP%&quot; == &quot; &quot; EXIT /B
&nbsp;
REM SORTABLES
IF /I &quot;%_P%&quot; == &quot;pid&quot; ( tasklist.exe /V /NH | SORT /+29 &amp;&amp; EXIT /B )
IF /I &quot;%_P%&quot; == &quot;size&quot; ( tasklist.exe /V /NH | SORT /+59 &amp;&amp; EXIT /B )
IF /I &quot;%_P%&quot; == &quot;user&quot; ( tasklist.exe /V /NH | SORT /+89 &amp;&amp; EXIT /B )
IF /I &quot;%_P%&quot; == &quot;time&quot; ( tasklist.exe /V /NH | SORT /+138 &amp;&amp; EXIT /B )
IF /I &quot;%_P%&quot; == &quot;window&quot; ( tasklist.exe /V /NH | SORT /+152 &amp;&amp; EXIT /B )
&nbsp;
REM FILTERS
IF /I &quot;%_P%&quot; == &quot;image&quot; ( tasklist.exe /V /NH /FI &quot;IMAGENAME eq %~2&quot; &amp;&amp; EXIT /B )
IF /I &quot;%_P%&quot; == &quot;username&quot; ( tasklist.exe /V /NH /FI &quot;USERNAME eq %~2&quot; &amp;&amp; EXIT /B )
IF /I &quot;%_P%&quot; == &quot;running&quot; ( tasklist.exe /V /NH /FI &quot;STATUS eq Running&quot; &amp;&amp; EXIT /B )
IF /I &quot;%_P%&quot; == &quot;status&quot; ( tasklist.exe /V /NH /FI &quot;STATUS eq %~2&quot; &amp;&amp; EXIT /B )
CALL :MF
EXIT /B</pre>
<h3>SPEAK &#8211; Speak text</h3>
<pre>:SPEAK
REM ECHO &quot;%~1&quot;
nircmd.exe speak text &quot;%~1&quot; 5 60 &amp;&amp; EXIT /B</pre>
<h3>MF &#8211; SLEEPs for 1 second, then prints out completed message, followed by 2 blank lines, then returns to CALLer</h3>
<pre>:MF
SLEEP 1 &amp;&amp; ECHO  [COMPLETED] &amp;&amp; ECHO. &amp;&amp; ECHO. &amp;&amp; EXIT /B</pre>
<h3>MM &#8211; prints blank line, L1, changes title of the interpreter window to %~1, prints >>> %~1&#8230;, L2, blank line, then returns to CALLer</h3>
<pre>:MM
SLEEP 1 &amp;&amp; ECHO. &amp;&amp; ECHO %L1% &amp;&amp; title +++ %~1&#46;.. &amp;&amp; ECHO %P1% %~1&#46;.. &amp;&amp; ECHO %L2% &amp;&amp; ECHO. &amp;&amp; EXIT /B</pre>
<h3>MT &#8211; prints blank line, L1, changes title of the interpreter window to %~1, prints >>> %~1&#8230;, L2, blank line, then returns to CALLer</h3>
<pre>:MT
CALL :MM &quot;%~1&quot; &amp;&amp; CALL :SPEAK &quot;%~1&quot; &amp;&amp; EXIT /B</pre>
<h3>MP &#8211; Print Output, then returns to CALLer</h3>
<pre>:MP
IF &quot;%~1&quot; == &quot;1&quot; ECHO %P1% %~2 &amp;&amp; EXIT /B
IF &quot;%~1&quot; == &quot;2&quot; ECHO %P2% %~2 &amp;&amp; ECHO. &amp;&amp; EXIT /B
IF &quot;%~1&quot; == &quot;3&quot; ECHO %P3% %~2 &amp;&amp; EXIT /B
EXIT /B</pre>
<h3>MP3 &#8211; ECHO %~1, speak %~1 with nircmd.exe, then returns to CALLer</h3>
<pre>:MP3
CALL :MP 1 &quot;%~1&quot; &amp;&amp; CALL :SPEAK &quot;%~1&quot; &amp;&amp; EXIT /B</pre>
<h3>MDYE &#8211; exit script with message %~1, then returns to CALLer</h3>
<pre>:MDYE
SETLOCAL
SET _M= %~1
IF NOT &quot;%_M%&quot; == &quot; &quot; SET _M=REASON: %~1
CALL :MP 1 &quot;EXITING SCRIPT&#46;..  %_M%&quot; &amp;&amp; ECHO. &amp;&amp; ECHO.
ENDLOCAL &amp;&amp; EXIT /B</pre>
<h3>MKILL &#8211; exit cmd processor with message %~1</h3>
<pre>:MKILL
SETLOCAL
SET _M= %~1
IF NOT &quot;%_M%&quot; == &quot; &quot; SET _M=REASON: %~1
ECHO. &amp;&amp; ECHO. &amp;&amp; CALL :MP 1 &quot;EXITING CMD WINDOW IN 3 SECONDS&#46;..  %_M%&quot; &amp;&amp; ECHO. &amp;&amp; ECHO. &amp;&amp; SLEEP 3
ENDLOCAL &amp;&amp; EXIT &amp;&amp; EXIT &amp;&amp; EXIT</pre>
<h2>EOF: Thoughts</h2>
<p>So what did you think?  I have around 20 batch scripts that utilize these and other functions to do all sorts of cool things.  One takes a screenshot of my desktop every 10 minutes and saves it for a real-cool archive of my activity.  Another lets me edit a boot.ini file with 1 command.. And another runs when I insert a USB drive to automatically mount a truecrypt volume and create SSH tunnels in the background by using Plink, AT, and the runas.exe command.</p>
<p>If you want to program, please use linux&#8230;  If you need to write a Windows batch file, I hope this helps.</p>
<div class='presskit'><h3>High Resolution Press Images:</h3>[+] <a href='http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?src=http://uploads.askapache.com/2010/09/Untitled-1.png&down=true'>Untitled-1.png</a><br />[+] <a href='http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?src=http://uploads.askapache.com/2010/09/windows-batch-file-example-116x45.png&down=true'>windows-batch-file-example-116x45.png</a><br />[+] <a href='http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?src=http://uploads.askapache.com/2010/09/Untitled-1-116x38.png&down=true'>Untitled-1-116x38.png</a><br />[+] <a href='http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?src=http://uploads.askapache.com/2010/09/windows-batch-file.png&down=true'>windows-batch-file.png</a><br /></div><p><a href="http://www.askapache.com/windows/advanced-batch-scripting.html"></a><a href="http://www.askapache.com/windows/advanced-batch-scripting.html">Advanced Windows Batch File Scripting</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/windows/advanced-batch-scripting.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Real-Life 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[Apache]]></category>
		<category><![CDATA[Apache Modules]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[DreamHost]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[Linux Unix BSD]]></category>
		<category><![CDATA[Mod_Rewrite]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Server Administration]]></category>
		<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[Webmaster]]></category>
		<category><![CDATA[AddHandler]]></category>
		<category><![CDATA[Backups]]></category>
		<category><![CDATA[Block IP]]></category>
		<category><![CDATA[Cache-Control]]></category>
		<category><![CDATA[cheatsheets]]></category>
		<category><![CDATA[developers]]></category>
		<category><![CDATA[errordocument]]></category>
		<category><![CDATA[etag]]></category>
		<category><![CDATA[htaccess tricks]]></category>
		<category><![CDATA[http cookie]]></category>
		<category><![CDATA[indexes]]></category>
		<category><![CDATA[Mod_Security]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[password protection]]></category>
		<category><![CDATA[real world]]></category>
		<category><![CDATA[rewritecond]]></category>
		<category><![CDATA[rewriterule]]></category>
		<category><![CDATA[Source Code]]></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[<div class='images'></div><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&#8217;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&#8217;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&#8217;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&#8217;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 &quot;\.(gif|png|jpg)$&quot; &quot;-&quot; [ENV=proxied_image:1]
RewriteCond &quot;%{ENV:proxied_image}&quot; &quot;!1&quot;
RewriteRule &quot;^&quot; &quot;-&quot; [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 &quot;\.(js|css)$&quot;&gt;
Header unset Pragma
FileETag None
Header set Cache-Control &quot;public&quot;
Header set Expires &quot;Thu, 15 Apr 2010 20:00:00 GMT&quot;
Header unset Last-Modified
Header unset Last-Modified
Header unset ETag
&nbsp;
SetOutputFilter DEFLATE
Header set Cache-Control &quot;public&quot;
Header set Expires &quot;Thu, 15 Apr 2010 20:00:00 GMT&quot;
&lt;/FilesMatch&gt;
SecFilterEngine Off
&nbsp;
# 1 YEAR
&lt;FilesMatch &quot;\.(js|css)$&quot;&gt;
Header unset Pragma
FileETag None
Header set Cache-Control &quot;public&quot;
Header set Expires &quot;Thu, 15 Apr 2010 20:00:00 GMT&quot;
Header unset Last-Modified
Header unset Last-Modified
Header unset ETag
&nbsp;
SetOutputFilter DEFLATE
Header set Cache-Control &quot;public&quot;
Header set Expires &quot;Thu, 15 Apr 2010 20:00:00 GMT&quot;
&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 &quot;Protected By AskApache&quot;
AuthDigestDomain / http://www.askapache.com/
AuthDigestFile /home/.greer/askapache/sites/askapache.com/.htpasswda3
Require valid-user
&lt;FilesMatch &quot;\.(ico|pdf|flv|jpg|jpeg|mp3|mpg|mp4|mov|wav|wmv|png|gif|swf|css|js)$&quot;&gt;
Allow from All
&lt;/FilesMatch&gt;
&lt;FilesMatch &quot;(async-upload|admin-ajax)\.php$&quot;&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 &quot;nolog,noauditlog,pass&quot;
SecAuditEngine Off
SecFilterInheritance Off
SecFilter modsecuritytest &quot;deny,nolog,noauditlog,status:503&quot;
Deny from All
&lt;/IfModule&gt;
&lt;/Files&gt;
&lt;Files basic_auth_test.gif&gt;
AuthType Basic
AuthName &quot;askapache test&quot;
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 &quot;askapache test&quot;
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 &quot;askapache test&quot;
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 &quot;askapache test&quot;
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 &quot;AskApache Pro&quot;
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 &quot;%{INFO_API_VERSION}e&quot;
RequestHeader set INFO_AUTH_TYPE &quot;%{INFO_AUTH_TYPE}e&quot;
RequestHeader set INFO_CONTENT_LENGTH &quot;%{INFO_CONTENT_LENGTH}e&quot;
RequestHeader set INFO_CONTENT_TYPE &quot;%{INFO_CONTENT_TYPE}e&quot;
RequestHeader set INFO_DOCUMENT_ROOT &quot;%{INFO_DOCUMENT_ROOT}e&quot;
RequestHeader set INFO_GATEWAY_INTERFACE &quot;%{INFO_GATEWAY_INTERFACE}e&quot;
RequestHeader set INFO_HTTPS &quot;%{INFO_HTTPS}e&quot;
RequestHeader set INFO_HTTP_ACCEPT &quot;%{INFO_HTTP_ACCEPT}e&quot;
RequestHeader set INFO_HTTP_ACCEPT_LANGUAGE &quot;%{INFO_HTTP_ACCEPT_LANGUAGE}e&quot;
RequestHeader set INFO_HTTP_ACCEPT_ENCODING &quot;%{INFO_HTTP_ACCEPT_ENCODING}e&quot;
RequestHeader set INFO_HTTP_ACCEPT_CHARSET &quot;%{INFO_HTTP_ACCEPT_CHARSET}e&quot;
RequestHeader set INFO_HTTP_CACHE_CONTROL &quot;%{INFO_HTTP_CACHE_CONTROL}e&quot;
RequestHeader set INFO_HTTP_CONNECTION &quot;%{INFO_HTTP_CONNECTION}e&quot;
RequestHeader set INFO_HTTP_COOKIE &quot;%{INFO_HTTP_COOKIE}e&quot;
RequestHeader set INFO_HTTP_FORWARDED &quot;%{INFO_HTTP_FORWARDED}e&quot;
RequestHeader set INFO_HTTP_HOST &quot;%{INFO_HTTP_HOST}e&quot;
RequestHeader set INFO_HTTP_KEEP_ALIVE &quot;%{INFO_HTTP_KEEP_ALIVE}e&quot;
RequestHeader set INFO_HTTP_PROXY_CONNECTION &quot;%{INFO_HTTP_PROXY_CONNECTION}e&quot;
RequestHeader set INFO_HTTP_REFERER &quot;%{INFO_HTTP_REFERER}e&quot;
RequestHeader set INFO_HTTP_USER_AGENT &quot;%{INFO_HTTP_USER_AGENT}e&quot;
RequestHeader set INFO_IS_SUBREQ &quot;%{INFO_IS_SUBREQ}e&quot;
RequestHeader set INFO_ORIG_PATH_INFO &quot;%{INFO_ORIG_PATH_INFO}e&quot;
RequestHeader set INFO_ORIG_PATH_TRANSLATED &quot;%{INFO_ORIG_PATH_TRANSLATED}e&quot;
RequestHeader set INFO_ORIG_SCRIPT_FILENAME &quot;%{INFO_ORIG_SCRIPT_FILENAME}e&quot;
RequestHeader set INFO_ORIG_SCRIPT_NAME &quot;%{INFO_ORIG_SCRIPT_NAME}e&quot;
RequestHeader set INFO_PATH &quot;%{INFO_PATH}e&quot;
RequestHeader set INFO_PATH_INFO &quot;%{INFO_PATH_INFO}e&quot;
RequestHeader set INFO_QUERY_STRING &quot;%{INFO_QUERY_STRING}e&quot;
RequestHeader set INFO_REDIRECT_QUERY_STRING &quot;%{INFO_REDIRECT_QUERY_STRING}e&quot;
RequestHeader set INFO_REDIRECT_REMOTE_USER &quot;%{INFO_REDIRECT_REMOTE_USER}e&quot;
RequestHeader set INFO_REDIRECT_STATUS &quot;%{INFO_REDIRECT_STATUS}e&quot;
RequestHeader set INFO_REDIRECT_URL &quot;%{INFO_REDIRECT_URL}e&quot;
RequestHeader set INFO_REMOTE_ADDR &quot;%{INFO_REMOTE_ADDR}e&quot;
RequestHeader set INFO_REMOTE_HOST &quot;%{INFO_REMOTE_HOST}e&quot;
RequestHeader set INFO_REMOTE_IDENT &quot;%{INFO_REMOTE_IDENT}e&quot;
RequestHeader set INFO_REMOTE_PORT &quot;%{INFO_REMOTE_PORT}e&quot;
RequestHeader set INFO_REMOTE_USER &quot;%{INFO_REMOTE_USER}e&quot;
RequestHeader set INFO_REQUEST_FILENAME &quot;%{INFO_REQUEST_FILENAME}e&quot;
RequestHeader set INFO_REQUEST_METHOD &quot;%{INFO_REQUEST_METHOD}e&quot;
RequestHeader set INFO_REQUEST_URI &quot;%{INFO_REQUEST_URI}e&quot;
RequestHeader set INFO_REQUEST_URI &quot;%{INFO_REQUEST_URI}e&quot;
RequestHeader set INFO_SCRIPT_FILENAME &quot;%{INFO_SCRIPT_FILENAME}e&quot;
RequestHeader set INFO_SCRIPT_GROUP &quot;%{INFO_SCRIPT_GROUP}e&quot;
RequestHeader set INFO_SCRIPT_NAME &quot;%{INFO_SCRIPT_NAME}e&quot;
RequestHeader set INFO_SCRIPT_URI &quot;%{INFO_SCRIPT_URI}e&quot;
RequestHeader set INFO_SCRIPT_URL &quot;%{INFO_SCRIPT_URL}e&quot;
RequestHeader set INFO_SCRIPT_USER &quot;%{INFO_SCRIPT_USER}e&quot;
RequestHeader set INFO_SERVER_ADDR &quot;%{INFO_SERVER_ADDR}e&quot;
RequestHeader set INFO_SERVER_ADMIN &quot;%{INFO_SERVER_ADMIN}e&quot;
RequestHeader set INFO_SERVER_NAME &quot;%{INFO_SERVER_NAME}e&quot;
RequestHeader set INFO_SERVER_PORT &quot;%{INFO_SERVER_PORT}e&quot;
RequestHeader set INFO_SERVER_PROTOCOL &quot;%{INFO_SERVER_PROTOCOL}e&quot;
RequestHeader set INFO_SERVER_SIGNATURE &quot;%{INFO_SERVER_SIGNATURE}e&quot;
RequestHeader set INFO_SERVER_SOFTWARE &quot;%{INFO_SERVER_SOFTWARE}e&quot;
RequestHeader set INFO_THE_REQUEST &quot;%{INFO_THE_REQUEST}e&quot;
RequestHeader set INFO_TIME &quot;%{INFO_TIME}e&quot;
RequestHeader set INFO_TIME_DAY &quot;%{INFO_TIME_DAY}e&quot;
RequestHeader set INFO_TIME_HOUR &quot;%{INFO_TIME_HOUR}e&quot;
RequestHeader set INFO_TIME_MIN &quot;%{INFO_TIME_MIN}e&quot;
RequestHeader set INFO_TIME_MON &quot;%{INFO_TIME_MON}e&quot;
RequestHeader set INFO_TIME_SEC &quot;%{INFO_TIME_SEC}e&quot;
RequestHeader set INFO_TIME_WDAY &quot;%{INFO_TIME_WDAY}e&quot;
RequestHeader set INFO_TIME_YEAR &quot;%{INFO_TIME_YEAR}e&quot;
RequestHeader set INFO_TZ &quot;%{INFO_TZ}e&quot;
RequestHeader set INFO_UNIQUE_ID &quot;%{INFO_UNIQUE_ID}e&quot;
&nbsp;
Options +FollowSymLinks +ExecCGI
DirectoryIndex /cgi-bin/rewrite-test/index.php
&nbsp;
Header echo ^.*
&nbsp;
AuthType Digest
AuthName &quot;AskApache Pro&quot;
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 &quot;(.+)&quot; HTTP_WWW_AUTHORIZATION=$1
SetEnvIfNoCase ^If &quot;(.+)&quot; HTTP_IF_MODIFIED_SINCE=$1
SetEnvIfNoCase ^If-None-Match$ &quot;(.+)&quot; HTTP_IF_NONE_MATCH=$1
SetEnvIfNoCase ^Cache-Control$ &quot;(.+)&quot; HTTP_CACHE_CONTROL=$1
SetEnvIfNoCase ^Connection$ &quot;(.+)&quot; HTTP_CONNECTION=$1
SetEnvIfNoCase ^Keep-Alive$ &quot;(.+)&quot; HTTP_KEEP_ALIVE=$1
SetEnvIfNoCase ^Authorization$ &quot;(.+)&quot; HTTP_AUTHORIZATION=$1
SetEnvIfNoCase ^Authorization$ &quot;.+username=\&quot;(.+)\&quot;.+&quot; HTTP_REMOTE_USER=$1
SetEnvIfNoCase ^Content-Type$ &quot;(.+)&quot; HTTP_CONTENT_TYPE=$1
SetEnvIfNoCase ^Content-Length$ &quot;(.+)&quot; HTTP_CONTENT_LENGTH=$1
SetEnvIfNoCase Server_Addr &quot;(.+)&quot; SERVER_ADDR=$1
SetEnvIfNoCase Request_Method &quot;(.+)&quot; REQUEST_METHOD=$1
SetEnvIfNoCase Request_Protocol &quot;(.+)&quot; REQUEST_PROTOCOL=$1
SetEnvIfNoCase Request_URI &quot;(.+)&quot; 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 &quot;%{IN_AUTH_TYPE}e&quot;
RequestHeader set CONTENT_LENGTH &quot;%{IN_CONTENT_LENGTH}e&quot;
RequestHeader set CONTENT_TYPE &quot;%{IN_CONTENT_TYPE}e&quot;
RequestHeader set DATE_GMT &quot;%{IN_DATE_GMT}e&quot;
RequestHeader set DATE_LOCAL &quot;%{IN_DATE_LOCAL}e&quot;
RequestHeader set DOCUMENT_NAME &quot;%{IN_DOCUMENT_NAME}e&quot;
RequestHeader set DOCUMENT_PATH_INFO &quot;%{IN_DOCUMENT_PATH_INFO}e&quot;
RequestHeader set DOCUMENT_ROOT &quot;%{IN_DOCUMENT_ROOT}e&quot;
RequestHeader set DOCUMENT_URI &quot;%{IN_DOCUMENT_URI}e&quot;
RequestHeader set GATEWAY_INTERFACE &quot;%{IN_GATEWAY_INTERFACE}e&quot;
RequestHeader set LAST_MODIFIED &quot;%{IN_LAST_MODIFIED}e&quot;
RequestHeader set PATH_INFO &quot;%{IN_PATH_INFO}e&quot;
RequestHeader set PATH_TRANSLATED &quot;%{IN_PATH_TRANSLATED}e&quot;
RequestHeader set QUERY_STRING &quot;%{IN_QUERY_STRING}e&quot;
RequestHeader set QUERY_STRING_UNESCAPED &quot;%{IN_QUERY_STRING_UNESCAPED}e&quot;
RequestHeader set REMOTE_ADDR &quot;%{IN_REMOTE_ADDR}e&quot;
RequestHeader set REMOTE_HOST &quot;%{IN_REMOTE_HOST}e&quot;
RequestHeader set REMOTE_IDENT &quot;%{IN_REMOTE_IDENT}e&quot;
RequestHeader set REMOTE_PORT &quot;%{IN_REMOTE_PORT}e&quot;
RequestHeader set REMOTE_USER &quot;%{IN_REMOTE_USER}e&quot;
RequestHeader set REDIRECT_HANDLER &quot;%{IN_REDIRECT_HANDLER}e&quot;
RequestHeader set REDIRECT_QUERY_STRING &quot;%{IN_REDIRECT_QUERY_STRING}e&quot;
RequestHeader set REDIRECT_REMOTE_USER &quot;%{IN_REDIRECT_REMOTE_USER}e&quot;
RequestHeader set REDIRECT_STATUS &quot;%{IN_REDIRECT_STATUS}e&quot;
RequestHeader set REDIRECT_URL &quot;%{IN_REDIRECT_URL}e&quot;
RequestHeader set REQUEST_METHOD &quot;%{IN_REQUEST_METHOD}e&quot;
RequestHeader set REQUEST_URI &quot;%{IN_REQUEST_URI}e&quot;
RequestHeader set SCRIPT_FILENAME &quot;%{IN_SCRIPT_FILENAME}e&quot;
RequestHeader set SCRIPT_NAME &quot;%{IN_SCRIPT_NAME}e&quot;
RequestHeader set SCRIPT_URI &quot;%{IN_SCRIPT_URI}e&quot;
RequestHeader set SCRIPT_URL &quot;%{IN_SCRIPT_URL}e&quot;
RequestHeader set SERVER_ADMIN &quot;%{IN_SERVER_ADMIN}e&quot;
RequestHeader set SERVER_NAME &quot;%{IN_SERVER_NAME}e&quot;
RequestHeader set SERVER_ADDR &quot;%{IN_SERVER_ADDR}e&quot;
RequestHeader set SERVER_PORT &quot;%{IN_SERVER_PORT}e&quot;
RequestHeader set SERVER_PROTOCOL &quot;%{IN_SERVER_PROTOCOL}e&quot;
RequestHeader set SERVER_SIGNATURE &quot;%{IN_SERVER_SIGNATURE}e&quot;
RequestHeader set SERVER_SOFTWARE &quot;%{IN_SERVER_SOFTWARE}e&quot;
RequestHeader set UNIQUE_ID &quot;%{IN_UNIQUE_ID}e&quot;
RequestHeader set USER_NAME &quot;%{IN_USER_NAME}e&quot;
RequestHeader set TZ &quot;%{IN_TZ}e&quot;
RequestHeader set API_VERSION &quot;%{IN_API_VERSION}e&quot;
RequestHeader set HTTPS &quot;%{IN_HTTPS}e&quot;
RequestHeader set HTTP_ACCEPT &quot;%{IN_HTTP_ACCEPT}e&quot;
RequestHeader set HTTP_ACCEPT_CHARSET &quot;%{IN_HTTP_ACCEPT_CHARSET}e&quot;
RequestHeader set HTTP_ACCEPT_ENCODING &quot;%{IN_HTTP_ACCEPT_ENCODING}e&quot;
RequestHeader set HTTP_ACCEPT_LANGUAGE &quot;%{IN_HTTP_ACCEPT_LANGUAGE}e&quot;
RequestHeader set HTTP_CACHE_CONTROL &quot;%{IN_HTTP_CACHE_CONTROL}e&quot;
RequestHeader set HTTP_CONNECTION &quot;%{IN_HTTP_CONNECTION}e&quot;
RequestHeader set HTTP_COOKIE &quot;%{IN_HTTP_COOKIE}e&quot;
RequestHeader set HTTP_FORWARDED &quot;%{IN_HTTP_FORWARDED}e&quot;
RequestHeader set HTTP_HOST &quot;%{IN_HTTP_HOST}e&quot;
RequestHeader set HTTP_KEEP_ALIVE &quot;%{IN_HTTP_KEEP_ALIVE}e&quot;
RequestHeader set HTTP_PROXY_CONNECTION &quot;%{IN_HTTP_PROXY_CONNECTION}e&quot;
RequestHeader set HTTP_REFERER &quot;%{IN_HTTP_REFERER}e&quot;
RequestHeader set HTTP_USER_AGENT &quot;%{IN_HTTP_USER_AGENT}e&quot;
RequestHeader set IS_SUBREQ &quot;%{IN_IS_SUBREQ}e&quot;
RequestHeader set ORIG_PATH_INFO &quot;%{IN_ORIG_PATH_INFO}e&quot;
RequestHeader set ORIG_PATH_TRANSLATED &quot;%{IN_ORIG_PATH_TRANSLATED}e&quot;
RequestHeader set ORIG_SCRIPT_FILENAME &quot;%{IN_ORIG_SCRIPT_FILENAME}e&quot;
RequestHeader set ORIG_SCRIPT_NAME &quot;%{IN_ORIG_SCRIPT_NAME}e&quot;
RequestHeader set PATH &quot;%{IN_PATH}e&quot;
RequestHeader set PHP_SELF &quot;%{IN_PHP_SELF}e&quot;
RequestHeader set REQUEST_FILENAME &quot;%{IN_REQUEST_FILENAME}e&quot;
RequestHeader set REQUEST_TIME &quot;%{IN_REQUEST_TIME}e&quot;
RequestHeader set SCRIPT_GROUP &quot;%{IN_SCRIPT_GROUP}e&quot;
RequestHeader set SCRIPT_USER &quot;%{IN_SCRIPT_USER}e&quot;
RequestHeader set THE_REQUEST &quot;%{IN_THE_REQUEST}e&quot;
RequestHeader set TIME &quot;%{IN_TIME}e&quot;
RequestHeader set TIME_DAY &quot;%{IN_TIME_DAY}e&quot;
RequestHeader set TIME_HOUR &quot;%{IN_TIME_HOUR}e&quot;
RequestHeader set TIME_MIN &quot;%{IN_TIME_MIN}e&quot;
RequestHeader set TIME_MON &quot;%{IN_TIME_MON}e&quot;
RequestHeader set TIME_SEC &quot;%{IN_TIME_SEC}e&quot;
RequestHeader set TIME_WDAY &quot;%{IN_TIME_WDAY}e&quot;
RequestHeader set TIME_YEAR &quot;%{IN_TIME_YEAR}e&quot;
&nbsp;
SetEnvIfNoCase ^WWW-Auth &quot;(.+)&quot; HTTP_WWW_AUTHORIZATION=$1
SetEnvIfNoCase ^If &quot;(.+)&quot; HTTP_IF_MODIFIED_SINCE=$1
SetEnvIfNoCase ^If-None-Match$ &quot;(.+)&quot; HTTP_IF_NONE_MATCH=$1
SetEnvIfNoCase ^Cache-Control$ &quot;(.+)&quot; HTTP_CACHE_CONTROL=$1
SetEnvIfNoCase ^Connection$ &quot;(.+)&quot; HTTP_CONNECTION=$1
SetEnvIfNoCase ^Keep-Alive$ &quot;(.+)&quot; HTTP_KEEP_ALIVE=$1
SetEnvIfNoCase ^Authorization$ &quot;(.+)&quot; HTTP_AUTHORIZATION=$1
SetEnvIfNoCase ^Content-Type$ &quot;(.+)&quot; HTTP_CONTENT_TYPE=$1
SetEnvIfNoCase ^Content-Length$ &quot;(.+)&quot; HTTP_CONTENT_LENGTH=$1
SetEnvIfNoCase ^Authorization$ &quot;.+username=\&quot;([a-zA-Z0-9]+)\&quot;.+&quot; REMOTE_USER=$1
SetEnvIfNoCase Server_Addr &quot;(.+)&quot; SERVER_ADDR=$1
SetEnvIfNoCase Request_Method &quot;(.+)&quot; REQUEST_METHOD=$1
SetEnvIfNoCase Request_Protocol &quot;(.+)&quot; REQUEST_PROTOCOL=$1
SetEnvIfNoCase Request_URI &quot;(.+)&quot; REQUEST_URI=$1
&nbsp;
RequestHeader set IF_MODIFIED_SINCE &quot;%{HTTP_IF_MODIFIED_SINCE}e&quot;
RequestHeader set IF_NONE_MATCH &quot;%{HTTP_IF_NONE_MATCH}e&quot;
RequestHeader set CACHE_CONTROL &quot;%{HTTP_CACHE_CONTROL}e&quot;
RequestHeader set CONNECTION &quot;%{HTTP_CONNECTION}e&quot;
RequestHeader set KEEP_ALIVE &quot;%{HTTP_KEEP_ALIVE}e&quot;
RequestHeader set AUTHORIZATION &quot;%{HTTP_AUTHORIZATION}e&quot;
RequestHeader set REMOTE_USER &quot;%{REMOTE_USER}e&quot;
RequestHeader set CONTENT_TYPE &quot;%{HTTP_CONTENT_TYPE}e&quot;
RequestHeader set CONTENT_LENGTH &quot;%{HTTP_CONTENT_LENGTH}e&quot;
RequestHeader set SERVER_ADDR &quot;%{SERVER_ADDR}e&quot;
RequestHeader set REQUEST_METHOD &quot;%{REQUEST_METHOD}e&quot;
RequestHeader set REQUEST_PROTOCOL &quot;%{REQUEST_PROTOCOL}e&quot;
RequestHeader set REQUEST_URI &quot;%{REQUEST_URI}e&quot;
&nbsp;
RequestHeader set UNIQUE_ID &quot;%{ENV_UNIQUE_ID}e&quot;
RequestHeader set SCRIPT_URL &quot;%{ENV_SCRIPT_URL}e&quot;
RequestHeader set SCRIPT_URI &quot;%{ENV_SCRIPT_URI}e&quot;
RequestHeader set PATH &quot;%{ENV_PATH}e&quot;
&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 &quot;^multipart/form-data&quot; !MODSEC_NOPOSTBUFFERING
SetEnvIfNoCase Content-Type &quot;^application/x-www-form-urlencoded&quot; !MODSEC_NOPOSTBUFFERING
SetEnv suppress-error-charset
SetEnvIfNoCase Content-Type &quot;^multipart/form-data&quot; !MODSEC_NOPOSTBUFFERING
&nbsp;
SetEnvIf Request_URI &quot;^/(cgi-bin/search\.php|cgi-bin/java\.cgi|wp-admin/.*)&quot; MODSEC_ENABLE=Off
SetEnvIf Request_URI &quot;^/(online-tools/js-compress.*)&quot; &quot;MODSEC_NOPOSTBUFFERING=Do not buffer file uploads&quot;
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 &quot;EMail&quot; 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 &quot;None&quot;, &quot;All&quot;,
# 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 &quot;handlers&quot;:
# 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 &quot;ExecCGI&quot; to the &quot;Options&quot; 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, &quot;text/plain&quot; is
# a good value.  If most of your content is binary, such as applications
# or images, you may want to use &quot;application/octet-stream&quot; 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>
<p>h2></p>
<pre>#
#  HEADERS and CACHING
#
Header unset Pragma
FileETag None
Header unset ETag
&nbsp;
# 1 YEAR
&lt;FilesMatch &quot;\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$&quot;&gt;
Header unset P3P
Header unset Pragma
FileETag None
Header unset ETag
Header set Cache-Control &quot;public,max-age=29030400&quot;
Header set Expires &quot;Thu, 15 Apr 2010 20:00:00 GMT&quot;
Header unset Last-Modified
&lt;/FilesMatch&gt;
&nbsp;
# 2 HOURS
&lt;FilesMatch &quot;\.(html|htm|xml|txt|xsl|rdf|rss)$&quot;&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/web-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 &quot;^(?:1|2(?!00)|5|4(?!04))&quot;
SecAuditLogRelevantStatus &quot;^(1|2(?!00)|4([0-9](0|1|2|5|6|7|8|9))|5)&quot;
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 &quot;deny,severity:6,status:403&quot;
&nbsp;
#SecFilterSelective REQUEST_METHOD &quot;POST&quot; &quot;pass,auditlog,severity:6&quot;
SecFilterSelective REQUEST_URI &quot;^/(xmlrpc|wp-comments-post)\.php&quot; &quot;pass,log,auditlog,severity:6&quot;
#SecFilterSelective REMOTE_ADDR ^$ &quot;pass,log,auditlog,severity:6&quot;
#SecFilterSelective REMOTE_ADDR ^203\.221\.91\.20$ &quot;pass,log,auditlog,severity:6&quot;
&nbsp;
#SecFilterSelective REQUEST_URI &quot;^/htaccess.*&quot; &quot;pass,log,auditlog&quot;
#SecFilterSelective REQUEST_URI &quot;^/feed.*&quot; &quot;pass,log,auditlog&quot;
#SecFilterSelective REQUEST_URI &quot;^/.*trackback.*&quot; &quot;pass,log,auditlog&quot;
#SecFilterSelective REQUEST_URI &quot;^/valid.*&quot; &quot;pass,log,auditlog&quot;
&nbsp;
#Enforce proper HTTP requests
SecFilterSelective SERVER_PROTOCOL &quot;!^HTTP/(0\.9|1\.0|1\.1)$&quot; &quot;id:340000,rev:1,severity:6,msg:&#039;Bad HTTP Protocol&#039;&quot;
&nbsp;
# Only accept request encodings we know how to handle
SecFilterSelective REQUEST_METHOD &quot;!^(GET|HEAD|POST)$&quot; &quot;chain,id:340001,rev:1,severity:6,msg:&#039;Restricted HTTP function,status:405&#039;&quot;
SecFilterSelective HTTP_Content-Type &quot;!(^$|^application/x-www-form-urlencoded$|^multipart/form-data)&quot;
&nbsp;
# Require Content-Length to be provided with every POST request
SecFilterSelective REQUEST_METHOD &quot;^POST$&quot; &quot;chain,id:340003,rev:1,severity:6,msg:&#039;Content Length not provided with POST&#039;,status:411&quot;
SecFilterSelective HTTP_Content-Length &quot;^$&quot;
&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 &quot;!^$&quot; &quot;id:340004,rev:1,severity:6,msg:&#039;Dis-allowed Transfer Encoding&#039;&quot;
&nbsp;
#Generic rule for allowed characters, adjust for your site before activating
##SecFilterSelective REQUEST_URI &quot;!^[a-zA-Z0-9\.\+\_\/\-\?\=\&amp;\%\#]+$&quot; &quot;chain,id:390002,rev:1,severity:4,msg:&#039;Restricted HTTP character set&#039;&quot;
##SecFilterSelective REQUEST_URI &quot;!^/(openid|wp-admin|wp-includes|wp-content|wp-login.php)&quot;
&nbsp;
#HTTP response splitting generic sigs
#SecFilter &quot;Content-Length\:.*Content-Type\:.*Content-Type\:&quot; &quot;id:340005,rev:1,severity:4,msg:&#039;HTTP response splitting&#039;&quot;
&nbsp;
#HTTP response splitting generic sigs
#SecFilter &quot;Content-Length\:&quot; &quot;chain,id:340006,rev:1,severity:4,msg:&#039;HTTP response splitting&#039;&quot;
#SecFilter &quot;Content-Type\:&quot;
&nbsp;
#catch smuggling attacks
#SecFilter &quot;^(GET|POST).*Host:.*^(GET|POST)&quot;  &quot;id:300012,rev:1,severity:4,msg:&#039;catch smuggling attacks&#039;&quot;
&nbsp;
#XSS insertion into Content-Type
#SecFilterSelective THE_REQUEST &quot;Content-Type\:.*(&lt;[[:space:]]*(script|about|applet|activex|chrome)*&gt;.*(script|about|applet|activex|chrome)[[:space:]]*&gt;|onmouseover=|javascript\:)&quot; &quot;id:300002,rev:1,severity:4,msg:&#039;XSS attack in Content-type header&#039;&quot;
&nbsp;
#Code injection via content length
#SecFilterSelective HTTP_Content-Length|HTTP_USER_AGENT &quot;\;(system|passthru|exec)\(&quot; &quot;id:330003,rev:1,severity:4,msg:&#039;Code Injection in Content-Length header&#039;&quot;
&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 &quot;chunked&quot; &quot;id:300003,rev:1,severity:4,msg:&#039;Chunked Transfer Encoding denied&#039;&quot;
&nbsp;
##generic recursion signatures
#SecFilterSelective REQUEST_URI &quot;\.\./\.\./&quot; &quot;id:300004,rev:2,severity:4,msg:&#039;Generic Path Recursion1 denied&#039;&quot;
#SecFilterSelective THE_REQUEST &quot;\.\|\./\.\|\./\.\|&quot; &quot;id:300005,rev:1,severity:4,msg:&#039;Generic Path Recursion2 denied&#039;&quot;
#SecFilterSelective THE_REQUEST &quot;\.\.\./&quot; &quot;id:300006,rev:1,severity:4,msg:&#039;Bogus Path denied&#039;&quot;
&nbsp;
#Generic PHP exploit signatures
#SecFilterSelective REQUEST_URI &quot;&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)\(.*\)\;&quot; &quot;id:330002,rev:1,severity:4,msg:&#039;Generic PHP exploit pattern denied&#039;&quot;
&nbsp;
#Prevent SQL injection in cookies
##SecFilterSelective COOKIE_VALUES &quot;((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)&quot; &quot;id:300011,rev:1,severity:4,msg:&#039;Generic SQL injection in cookie&#039;&quot;
&nbsp;
#Prevent SQL injection in UA
##SecFilterSelective HTTP_USER_AGENT &quot;((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)&quot; &quot;id:300012,rev:1,severity:4,msg:&#039;Generic SQL injection in User Agent header&#039;&quot;
&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 &quot;((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)&quot; &quot;id:300013,rev:1,severity:4,msg:&#039;Generic SQL injection protection&#039;&quot;
&nbsp;
#generic XSS PHP attack types
##SecFilterSelective REQUEST_URI &quot;\.php\?&quot; &quot;chain,id:300010,rev:1,severity:4,msg:&#039;Generic PHP XSS exploit pattern denied&#039;&quot;
#SecFilter &quot;(javascript\:/(.*new\x20ActiveXObject.*Sh\.regwrite|.*window\.opener\.document\.body.\innerHTML=window\.opener\.document\.body\.innerHTML\.replace)|onmouseover=\&#039;javascript)&quot;
&nbsp;
#Generic XSS filter
#please report false positives
##SecFilterSelective REQUEST_URI &quot;!/mt\.cgi&quot; &quot;chain,msg:&#039;XSS2&#039;&quot;
#SecFilter &quot;&lt;[[:space:]]*(script|about|applet|activex|chrome)*&gt;.*(script|about|applet|activex|chrome)[[:space:]]*&gt;&quot;
&nbsp;
#XSS in referrer and UA headers
##SecFilterSelective HTTP_REFERER|HTTP_USER_AGENT &quot;&lt;[[:space:]]*(script|about|applet|activex|chrome)*&gt;.*(script|about|applet|activex|chrome)[[:space:]]*&gt;&quot; &quot;msg:&#039;XSS3&#039;&quot;
&nbsp;
#HTTP header PHP code injection attacks
##SecFilterSelective HTTP_CLIENT_IP|HTTP_USER_AGENT|HTTP_Referer &quot;(&lt;\?php|&lt;[[:space:]]?\?[[:space:]]?php|&lt;\? php)&quot; &quot;msg:&#039;PHP1&#039;&quot;
&nbsp;
#Generic PHP remote file injection
##SecFilterSelective REQUEST_URI &quot;!(/do_command)&quot; &quot;chain,msg:&#039;PHP2&#039;&quot;
##SecFilterSelective REQUEST_URI &quot;\.php\?.*=(https?|ftp)\:/.*(cmd|command)=&quot;
&nbsp;
#script, perl, etc. code in HTTP_Referer string
##SecFilterSelective HTTP_Referer &quot;\#\!.*/&quot; &quot;msg:&#039;perl script1&#039;&quot;
&nbsp;
#remote file inclusion generic attack signature
#SecFilterSelective THE_REQUEST  &quot;\.(dat|gif|jpg|png|bmp|txt|vir|dot)\?&quot; &quot;chain,msg:&#039;remote 1&#039;&quot;
#SecFilter &quot;((name|pm_path|pagina|path|include_location|root|page|open)=(http|https|ftp)|(cmd|command|inc)=)&quot;
&nbsp;
#remote file inclusion generic attack signature
#SecFilterSelective THE_REQUEST  &quot;\.(dat|gif|jpg|png|bmp|txt|vir|dot)\?\&amp;(cmd|command|inc|name)=&quot; &quot;msg:&#039;remote2&#039;&quot;
&nbsp;
#remote file inclusion generic attack signature
#SecFilterSelective ARGS  &quot;\.(dat|gif|jpg|png|bmp|txt|vir|dot)&quot; &quot;chain,msg:&#039;file inclusion1&#039;&quot;
#SecFilter &quot;\?\&amp;(cmd|inc|name)=&quot;
&nbsp;
#remote file inclusion generic attack signature
#SecFilterSelective ARGS  &quot;\.(dat|gif|jpg|png|bmp|txt|vir|dot)\?\&amp;(cmd|inc|name)=&quot; &quot;msg:&#039;file inclusion2&#039;&quot;
&nbsp;
#remote file inclusion generic attack signature
#SecFilterSelective REQUEST_URI  &quot;\.php\?.*=(http|https|ftp)\:/.*\?&amp;cmd=&quot; &quot;msg:&#039;file inclusion3&#039;&quot;
&nbsp;
#Bogus file extensions generic signature
#SecFilterSelective THE_REQUEST  &quot;[A-Za-z0-9]\.(gif|jpg|png|bmp)\.txt&quot; &quot;msg:&#039;file extension&#039;&quot;
&nbsp;
#PHP remote path attach generic signature
#SecFilterSelective REQUEST_URI  &quot;\.ph(p(3|4)?).*path=(http|https|ftp)\:/&quot; &quot;msg:&#039;remote path1&#039;&quot;
#SecFilterSelective REQUEST_URI  &quot;\.php.*path=(http|https|ftp)\:/&quot; &quot;msg:&#039;remote path2&#039;&quot;
&nbsp;
#generic php attack sigs
#SecFilterSelective REQUEST_URI &quot;(&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)=)&quot; &quot;msg:&#039;php attack1&#039;&quot;
&nbsp;
# WEB-MISC apache directory disclosure attempt
#SecFilterSelective THE_REQUEST &quot;////&quot; &quot;msg:&#039;apache directory disclosure&#039;&quot;
&nbsp;
#PHP defenses
##SecFilterSelective ARG_PHPSESSID &quot;!^$&quot; &quot;msg:&#039;something in phpsessid&#039;&quot;
##SecFilterSelective COOKIE_PHPSESSID &quot;!^$&quot; &quot;msg:&#039;something in cookie phpsessid&#039;&quot;
&nbsp;
#PHP defenses
##SecFilterSelective COOKIE_ASKAPACHEID &quot;!^[0-9a-z]*$&quot; &quot;msg:&#039;bad value for cookie&#039;&quot;
&nbsp;
#cross site scripting attempt TYPE + JAVASCRIPT
##SecFilterSelective THE_REQUEST &quot;TYPE\s*=\s*[\&#039;\&quot;]text\/javascript&quot; &quot;msg:&#039;cross-site1&#039;&quot;
&nbsp;
#cross site scripting attempt STYLE + JAVASCRIPT
##SecFilterSelective THE_REQUEST &quot;TYPE\s*=\s*[\&#039;\&quot;]application\/x-javascript&quot; &quot;msg:&#039;cross-site1&#039;&quot;
&nbsp;
#cross site scripting attempt STYLE + JSCRIPT
##SecFilterSelective THE_REQUEST &quot;TYPE\s*=\s*[\&#039;\&quot;]text\/jscript&quot; &quot;msg:&#039;cross-site1&#039;&quot;
&nbsp;
# cross site scripting attempt STYLE + VBSCRIPT
##SecFilterSelective THE_REQUEST &quot;TYPE\s*=\s*[\&#039;\&quot;]text\/vbscript&quot; &quot;msg:&#039;cross-site1&#039;&quot;
&nbsp;
#cross site scripting attempt STYLE + VBSCRIPT
##SecFilterSelective THE_REQUEST &quot;TYPE\s*=\s*[\&#039;\&quot;]application\/x-vbscript&quot; &quot;msg:&#039;cross-site1&#039;&quot;
&nbsp;
#cross site scripting attempt STYLE + ECMACRIPT
##SecFilterSelective THE_REQUEST &quot;TYPE\s*=\s*[\&#039;\&quot;]text\/ecmascript&quot; &quot;msg:&#039;cross-site1&#039;&quot;
&nbsp;
# cross site scripting attempt STYLE + EXPRESSION
##SecFilterSelective THE_REQUEST &quot;STYLE[\s]*=[\s]*[^&gt;]expression[\s]*\(&quot; &quot;msg:&#039;cross-site1&#039;&quot;
&nbsp;
#cross site scripting attempt STYLE + EXPRESSION
##SecFilterSelective THE_REQUEST &quot;[\s]*expression[\s]*\([^}]}[\s]*&lt;\/STYLE&gt;&quot; &quot;msg:&#039;cross-site1&#039;&quot;
&nbsp;
# cross site scripting attempt using XML
##SecFilterSelective THE_REQUEST &quot;&lt;!\[CDATA\[&lt;\]\]&gt;SCRIPT&quot; &quot;msg:&#039;cross-site1&#039;&quot;
&nbsp;
#cross site scripting attempt executing hidden Javascript
##SecFilterSelective THE_REQUEST &quot;eval[\s]*\([\s]*[^\.]\.innerHTML[\s]*\)&quot; &quot;msg:&#039;cross-site1&#039;&quot;
&nbsp;
#cross site scripting attempt executing hidden Javascript
##SecFilterSelective THE_REQUEST &quot;window\.execScript[\s]*\(&quot; &quot;msg:&#039;cross-site1&#039;&quot;
&nbsp;
#cross site scripting attempt to execute Javascript code
###SecFilterSelective THE_REQUEST &quot;/(((URL|SRC|HREF|LOWSRC)[\s]*=)|(url[\s]*[\(]))[\s]*[\&#039;\&quot;]*javascript[\:]&quot; &quot;msg:&#039;cross-site1&#039;&quot;
&nbsp;
#cross site scripting HTML Image tag set to javascript attempt
#SecFilterSelective THE_REQUEST &quot;img src=javascript&quot; &quot;msg:&#039;cross-site1&#039;&quot;
&nbsp;
#Fake image file shell attacvk
#SecFilterSelective HTTP_Content-Type &quot;image/.*&quot; &quot;msg:&#039;image shell 1&#039;&quot;
#SecFilterSelective POST_PAYLOAD &quot;chr\(&quot; &quot;msg:&#039;image shell2&#039;&quot;
&nbsp;
#bogus graphics file
#SecFilterSelective HTTP_Content-Disposition &quot;\.php&quot;  &quot;chain,msg:&#039;bogus graphics&#039;&quot;
#SecFilterSelective HTTP_Content-Type &quot;(image/gif|image/jpg|image/png|image/bmp)&quot;
&nbsp;
# Allow only letters, digits, underscore, and square brackets (for arrays)
# in variable names#
#SecFilterSelective ARGS_NAMES &quot;!^[][a-zA-Z0-9_]+$&quot;
&nbsp;
#&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-
# reject keywords that appear in POST or GET
#=============================================
SecFilterSignatureAction &quot;nolog,auditlog,deny,severity:6,status:403&quot;
&nbsp;
SecFilterSelective REQUEST_URI  &quot;^/.*/wp-comments-post\.php&quot; &quot;id:50200,msg:&#039;WORDPRESS SPAM bad wp-comments-post location&#039;&quot;
&nbsp;
&lt;Files wp-comments-post.php&gt;
# fail for empty comment fields
SecFilterSelective &quot;ARG_comment_post_ID|ARG_submit&quot; &quot;^$&quot; &quot;id:50300,msg:&#039;WORDPRESS SPAM MISSING comment_post_ID&#039;&quot;
SecFilterSelective &quot;ARG_comment_post_ID&quot; &quot;!^[0-9]{1,6}$&quot; &quot;id:50301,msg:&#039;WORDPRESS SPAM BAD comment_post_ID&#039;&quot;
SecFilterSelective &quot;HTTP_Cookie&quot; &quot;^$&quot; &quot;id:50302,msg:&#039;WORDPRESS SPAM No cookie&#039;&quot;
&nbsp;
##SecFilterSelective &quot;comment_post_DI&quot; &quot;^$&quot; &quot;id:50310,msg:&#039;WORDPRESS SPAM MISSING comment_post_DI&#039;&quot;
##SecFilterSelective &quot;comment_post_DI&quot; &quot;!^[0-9]{1,2}$&quot; &quot;id:50311,msg:&#039;WORDPRESS SPAM MISSING comment_post_DI&#039;&quot;
&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 &quot;nolog,noauditlog,deny,severity:6,redirect:http://www.askapache.com/feed/&quot;
SecFilterSelective ARGS|THE_REQUEST &quot;00bp\.com|360\.yahoo|987mb\.com|Ambien|American airline&quot; &quot;id:50010,msg:&#039;SPAM 10&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;Ativan|Caresoprodol|Darvocet|Ephedra|Ephedrine&quot; &quot;id:50011,msg:&#039;SPAM 11&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;Gambling|Lexapro|Tramadol|Venlafaxine&quot; &quot;id:50012,msg:&#039;SPAM 12&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;\[URL=|abgood|acura|acyclovir|adderall&quot; &quot;id:50013,msg:&#039;SPAM 13&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;adipex|alcohol|alprazolam|amateur|amrit&quot; &quot;id:50014,msg:&#039;SPAM 14&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;anal sex|analfinder|angelina jolie|asshole|axspace\.com&quot; &quot;id:50015,msg:&#039;SPAM 15&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;baccarat|bankrupt|bikini|biotic|black jack|blowjob&quot; &quot;id:50016,msg:&#039;SPAM 16&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;blackjack|blog\.360|brutality|buddhism|butalbital&quot; &quot;id:50017,msg:&#039;SPAM 17&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;cadillac|canalis|card credit|card stud|carisoprodol&quot; &quot;id:50018,msg:&#039;SPAM 18&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;carmen|cash advance|cash credit|casino|catch\.com&quot; &quot;id:50019,msg:&#039;SPAM 19&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;celebrex|celexa|cellulite|cheap|cheerleader&quot; &quot;id:50020,msg:&#039;SPAM 20&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;chevrolet|child abuse|cialis|cigarette|cipro&quot; &quot;id:50021,msg:&#039;SPAM 21&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;citroen|claritin|cleavage|clomid|codeine&quot; &quot;id:50022,msg:&#039;SPAM 22&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;consulting23|craps online|credit card|credit debt|crestor&quot; &quot;id:50023,msg:&#039;SPAM 23&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;dealership|debt free|desnudas|diazepam|dick&quot; &quot;id:50024,msg:&#039;SPAM 24&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;dildo|drugstore|earrings|endometrioma|endowment&quot; &quot;id:50025,msg:&#039;SPAM 25&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;erotic|estrogen|fioricet|francaise|freehost\.com&quot; &quot;id:50026,msg:&#039;SPAM 26&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;freehostia|freemb\.com|fuck|geocities\.com|hacking myspace&quot; &quot;id:50027,msg:&#039;SPAM 27&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;holdem|honda|hotels|hydrocodone|hypnotic&quot; &quot;id:50028,msg:&#039;SPAM 28&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;hyundai|implants|incest|instant approval|insurance&quot; &quot;id:50029,msg:&#039;SPAM 29&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;interracial|jaguar|jenny movie|johanson|kasino&quot; &quot;id:50030,msg:&#039;SPAM 30&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;lesbian|levitra|lipitor|loan|lolita&quot; &quot;id:50031,msg:&#039;SPAM 31&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;lorazepam|lorcet|lyrics|madamic|majorette&quot; &quot;id:50032,msg:&#039;SPAM 32&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;malaria|mastercar|masturbate|masturbation|maturewomen&quot; &quot;id:50033,msg:&#039;SPAM 33&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;mazda|medication|medicine|megsfree5\.com|mercedes&quot; &quot;id:50034,msg:&#039;SPAM 34&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;meridia|metformin|mitsubishi|mortgage|myspace profile&quot; &quot;id:50035,msg:&#039;SPAM 35&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;naked|neocool|nexium|nimire\.com|nissan&quot; &quot;id:50036,msg:&#039;SPAM 36&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;nokia|nude|nudism|nymph|open toe&quot; &quot;id:50037,msg:&#039;SPAM 37&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;oprodol|orgasm|oxycodone|oxycontin|packages&quot; &quot;id:50038,msg:&#039;SPAM 38&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;painrelief|pantyhose|paxil|payday|penis&quot; &quot;id:50039,msg:&#039;SPAM 39&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;percocet|pharmacy|phentermine|phetermine|phpbb_root&quot; &quot;id:50040,msg:&#039;SPAM 40&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;pictaboo|pictorial|pills|pissing|play craps&quot; &quot;id:50041,msg:&#039;SPAM 41&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;playgirl|pocker web|poker|pontiac|poquer&quot; &quot;id:50042,msg:&#039;SPAM 42&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;porn|pounder|prescription|preteen|prevacid&quot; &quot;id:50043,msg:&#039;SPAM 43&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;price1|prilosec|propecia|proza|prozac&quot; &quot;id:50044,msg:&#039;SPAM 44&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;puddled|pussy|refinance|rentals|replica&quot; &quot;id:50045,msg:&#039;SPAM 45&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;ringtones|roulette|screensaver|seduced|sexual&quot; &quot;id:50046,msg:&#039;SPAM 46&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;sexy|shemale|shiloh|singulair|site-host&quot; &quot;id:50047,msg:&#039;SPAM 47&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;slot machine|slot maschine|slots machine|solpip\.com|soma&quot; &quot;id:50048,msg:&#039;SPAM 48&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;sperm|starlets|supplier|suzuki|tadalafil&quot; &quot;id:50049,msg:&#039;SPAM 49&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;toyota|tylenol|ultram|valium|viagra&quot; &quot;id:50050,msg:&#039;SPAM 50&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;vigora|vioxx|wallpaper|warez|webcam&quot; &quot;id:50051,msg:&#039;SPAM 51&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;webpages\.com|wellbutrin|whitesluts|wholesale|whore&quot; &quot;id:50052,msg:&#039;SPAM 52&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;windshield|xanax|xenical|y lohan|yourgirls&quot; &quot;id:50053,msg:&#039;SPAM 53&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;youtube\.com|zantac|sex offenders|hotgay|Zoloft|celtic women&quot; &quot;id:50054,msg:&#039;SPAM 54&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;dollhouse|freehot|kardashian|oralsex&quot; &quot;id:50055,msg:&#039;SPAM 55&#039;
SecFilterSelective ARGS|THE_REQUEST &quot;freeimghost&quot; &quot;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&#8217;s not even funny&#8230; like you can run bash as your webserver instead of apache!  (kinda&#8230;)</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)&#8230; </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 &quot;policyref=\&quot;http://www.askapache.com/w3c/p3p.xml\&quot;&quot;
Header set X-Pingback &quot;http://www.askapache.com/xmlrpc.php&quot;
Header set Content-Language &quot;en-US&quot;
Header set Vary &quot;Accept-Encoding,Accept&quot;
&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 &quot;Protection&quot;
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 &quot;Indexes&quot;, 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 &quot;100 Continue&quot; 100* 100/index.html
AddDescription &quot;101 Switching Protocols&quot; 101* 101/index.html
AddDescription &quot;102 Processing&quot; 102* 102/index.html
AddDescription &quot;200 OK&quot; 200* 200/index.html
AddDescription &quot;201 Created&quot; 201* 201/index.html
AddDescription &quot;202 Accepted&quot; 202* 202/index.html
AddDescription &quot;203 Non-Authoritative Information&quot; 203* 203/index.html
AddDescription &quot;204 No Content&quot; 204* 204/index.html
AddDescription &quot;205 Reset Content&quot; 205* 205/index.html
AddDescription &quot;206 Partial Content&quot; 206* 206/index.html
AddDescription &quot;207 Multi-Status&quot; 207* 207/index.html
AddDescription &quot;300 Multiple Choices&quot; 300* 300/index.html
AddDescription &quot;301 Moved Permanently&quot; 301* 301/index.html
AddDescription &quot;302 Found&quot; 302* 302/index.html
AddDescription &quot;303 See Other&quot; 303* 303/index.html
AddDescription &quot;304 Not Modified&quot; 304* 304/index.html
AddDescription &quot;305 Use Proxy&quot; 305* 305/index.html
AddDescription &quot;306 unused&quot; 306* 306/index.html
AddDescription &quot;307 Temporary Redirect&quot; 307* 307/index.html
AddDescription &quot;400 Bad Request&quot; 400* 400/index.html
AddDescription &quot;401 Authorization Required&quot; 401* 401/index.html
AddDescription &quot;402 Payment Required&quot; 402* 402/index.html
AddDescription &quot;403 Forbidden&quot; 403* 403/index.html
AddDescription &quot;404 Not Found&quot; 404* 404/index.html
AddDescription &quot;405 Method Not Allowed&quot; 405* 405/index.html
AddDescription &quot;406 Not Acceptable&quot; 406* 406/index.html
AddDescription &quot;407 Proxy Authentication Required&quot; 407* 407/index.html
AddDescription &quot;408 Request Time-out&quot; 408* 408/index.html
AddDescription &quot;409 Conflict&quot; 409* 409/index.html
AddDescription &quot;410 Gone&quot; 410* 410/index.html
AddDescription &quot;411 Length Required&quot; 411* 411/index.html
AddDescription &quot;412 Precondition Failed&quot; 412* 412/index.html
AddDescription &quot;413 Request Entity Too Large&quot; 413* 413/index.html
AddDescription &quot;414 Request-URI Too Large&quot; 414* 414/index.html
AddDescription &quot;415 Unsupported Media Type&quot; 415* 415/index.html
AddDescription &quot;416 Requested Range Not Satisfiable&quot; 416* 416/index.html
AddDescription &quot;417 Expectation Failed&quot; 417* 417/index.html
AddDescription &quot;418 unused&quot; 418* 418/index.html
AddDescription &quot;419 unused&quot; 419* 419/index.html
AddDescription &quot;420 unused&quot; 420* 420/index.html
AddDescription &quot;421 unused&quot; 421* 421/index.html
AddDescription &quot;422 Unprocessable Entity&quot; 422* 422/index.html
AddDescription &quot;423 Locked&quot; 423* 423/index.html
AddDescription &quot;424 Failed Dependency&quot; 424* 424/index.html
AddDescription &quot;425 No code&quot; 425* 425/index.html
AddDescription &quot;426 Upgrade Required&quot; 426* 426/index.html
AddDescription &quot;500 Internal Server Error&quot; 500* 500/index.html
AddDescription &quot;501 Method Not Implemented&quot; 501* 501/index.html
AddDescription &quot;502 Bad Gateway&quot; 502* 502/index.html
AddDescription &quot;503 Service Temporarily Unavailable&quot; 503* 503/index.html
AddDescription &quot;504 Gateway Time-out&quot; 504* 504/index.html
AddDescription &quot;505 HTTP Version Not Supported&quot; 505* 505/index.html
AddDescription &quot;506 Variant Also Negotiates&quot; 506* 506/index.html
AddDescription &quot;507 Insufficient Storage&quot; 507* 507/index.html
AddDescription &quot;508 unused&quot; 508* 508/index.html
AddDescription &quot;509 unused&quot; 509* 509/index.html
AddDescription &quot;510 Not Extended&quot; 510* 510/index.html
AddDescription &quot;.htaccess ErrorDocuments&quot; *
&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&#8217;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$ &quot;(.*)&quot; HTTP_MY_COOKIE=$1
#SetEnvIfNoCase Remote_Addr &quot;(.*)&quot; HTTP_MY_REMOTE_ADDR=$1
ExpiresActive Off
FileETag None
Header unset Connection
Header set Connection &quot;close&quot;
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 &quot;%D %t&quot;
#Header add Location &quot;http://www.askapache.com/feed/&quot;
#Header add Found &quot;http://askapache.com/feed/&quot;
#Header add Content-Location &quot;http://www.askapache.com/feed/&quot;
#Header add Refresh &quot;http://www.askapache.com/feed/&quot;
#Header set Hi &quot;%{HTTP_MY_REMOTE_ADDR}e&quot;
### 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 &quot;None&quot;, &quot;All&quot;,
# 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 &quot;^\.ht&quot;&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, &quot;text/plain&quot; is
# a good value.  If most of your content is binary, such as applications
# or images, you may want to use &quot;application/octet-stream&quot; 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 &quot;EMail&quot; 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/web-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 &quot;handlers&quot;:
# 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 &quot;ExecCGI&quot; to the &quot;Options&quot; 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 &quot;\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$&quot;&gt;
Header unset P3P
Header set Cache-Control &quot;public&quot;
Header set Expires &quot;Thu, 15 Apr 2010 20:00:00 GMT&quot;
&lt;/FilesMatch&gt;
&nbsp;
# 2 HOURS
&lt;FilesMatch &quot;\.(html|htm|xml|txt|xsl)$&quot;&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">Real-Life 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>4</slash:comments>
		</item>
		<item>
		<title>Optimize a Website for Speed, Security, and Easy Management</title>
		<link>http://www.askapache.com/htaccess/optimize-website-files-cache-security.html</link>
		<comments>http://www.askapache.com/htaccess/optimize-website-files-cache-security.html#comments</comments>
		<pubDate>Fri, 19 Feb 2010 00:45:26 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[DreamHost]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[Linux Unix BSD]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[Webmaster]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[301 Redirect]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[Advanced]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[apache server]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[Backups]]></category>
		<category><![CDATA[Bandwidth]]></category>
		<category><![CDATA[bleeding edge]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[Cache-Control]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[compression]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Dig]]></category>
		<category><![CDATA[DNS]]></category>
		<category><![CDATA[errordocument]]></category>
		<category><![CDATA[Etags]]></category>
		<category><![CDATA[Examples]]></category>
		<category><![CDATA[expires header]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[File Permissions]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[htaccess files]]></category>
		<category><![CDATA[Htpasswd]]></category>
		<category><![CDATA[HTTP Error]]></category>
		<category><![CDATA[HTTP Headers]]></category>
		<category><![CDATA[HTTP Status Codes]]></category>
		<category><![CDATA[HTTPS SSL]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Login]]></category>
		<category><![CDATA[Logs]]></category>
		<category><![CDATA[Mod_Rewrite]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[optimizations]]></category>
		<category><![CDATA[optimized website]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[password protection]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[php.ini]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[real deal]]></category>
		<category><![CDATA[Redirect]]></category>
		<category><![CDATA[Redirection]]></category>
		<category><![CDATA[Rewrite Tricks]]></category>
		<category><![CDATA[Robot]]></category>
		<category><![CDATA[robots]]></category>
		<category><![CDATA[robots.txt]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[search and replace]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[server config]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[SPEED]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[stat]]></category>
		<category><![CDATA[SymLinks]]></category>
		<category><![CDATA[trial and error]]></category>
		<category><![CDATA[trick]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[web server]]></category>
		<category><![CDATA[WordPress Plugins]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=1380</guid>
		<description><![CDATA[<p><a href="http://www.askapache.com/htaccess/optimize-website-files-cache-security.html" class="IFL hs hs37" title="Discover how to setup and manage a website from top to bottom for optimized speed, security, and simplicity"></a>Learn how to setup, configure, secure, optimize, and create a low-maintenance website the AskApache way.  I'm piecing together all the hacks, tricks, methods, and ideas discussed throughout this blog and all across Netdom and glueing them all together to show you how to have the most optimized, crazy fastest, and best website setup I can think of.<br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<div class='images'></div><p><img class="IFL" src="http://uploads.askapache.com/2008/09/computerimg.jpg" alt="optimized server setup" title="optimized server setup" />Over the past 10 or so years I&#8217;ve been directly or indirectly involved in configuring/administrating/hacking thousands of websites, and I realized today that I&#8217;ve actually learned quite a bit about how to really make them work hard for me, instead of the other way around. It came as a mild shock to think of where I was back then vs. now because the improvements and optimizations are hundreds of smaller improvements, but taken together, the  optimization hacks I&#8217;ve found through trial and error and much reading are as Donald would say, <strong>YOOUUGE</strong> compared to a basic website setup.<br class="C" /></p>
<p class="cnote">I use this awesome skeleton setup for all my high-paying clients <em>sorry poor people!</em> and also of course on this blog, which I use as a bleeding-edge dev server for my crazy testing.  So realize that I&#8217;m already past this setup and using it to do cooler stuff.  In order for you to use these more advanced ideas, you first need to get up to speed on what I&#8217;m doing so you know what I&#8217;m talking about.  This article tries to help you accomplish that&#8230; remains to be seen.</p>
<h2>An Optimized Website, The Real Deal</h2>
<p>This first article is to give you some ideas and get you thinking and reading before the first article in this series comes out.  This series details how to setup, configure, secure, optimize, and manage a website the best possible way I can come up with.  It pieces together all the AskApache hacks and tricks and uses methods and ideas discussed all over this blog and all over the net and glues them all together to show you how to have the most optimized, fastest, best website setup I can think of.</p>
<p>Knowing the why and how behind the operation of a Web Server allows us to optimize that operation.  For this example we will be creating the website <code>www.askapache.com</code>, which will be running WordPress and php.  We will also set up <code>static.askapache.com</code> to serve all of our sites uploads, images, css and javascript files, flash files, etc. with advanced caching and security using Apache Server .htaccess files.  So lets get started and take a look at this site structure for a moment.</p>
<pre>/home/askapache.com
|&#45;- /home/askapache.com/backups/
|&#45;- /home/askapache.com/public_html/
|&#45;- /home/askapache.com/inc/
|&#45;- /home/askapache.com/logs/
|&#45;- /home/askapache.com/static/
|&#45;- /home/askapache.com/tmp/
|&#45;- /home/askapache.com/.htpasswd-basic
`&#45;- /home/askapache.com/.htpasswd-digest</pre>
<ul>
<li><code>/backups/</code> &#8211; For <a href="http://www.askapache.com/wordpress/encrypted-wordpress-site-backups.html">encrypted backups of WordPress database and site files</a>. And any other backups.</li>
<li><code>/public_html/</code> &#8211; The document root for <code>www.askapache.com</code></li>
<li><code>/inc/</code> &#8211; Folder to keep your php include files for extra security and easy management.</li>
<li><code>/logs/</code> &#8211; Save your php, apache, and other logs here or create symlinks to them.</li>
<li><code>/static/</code> &#8211; The document root for <code>static.askapache.com</code></li>
<li><code>/tmp/</code> &#8211; Only need this if your host doesn&#8217;t already have a /tmp folder</li>
</ul>
<hr class="HR0" />
<h2>Strong Security, Top to Bottom</h2>
<p><img class="IFL" src="http://uploads.askapache.com/2008/09/1023103_warning_icon_32.jpg" width="150" alt="Optimize a Website for Speed, Security, and Easy Management" title="Site Security with Apache" />Simply by implementing correct access permissions, file permissions, password protection and segmenting various folders and services we are already ahead of the game.  I&#8217;ve always taken security extremely seriously, so you can benefit from alot of the simple solutions I&#8217;m recommending for a really locked down site.<br class="C" /></p>
<p>Indeed, security is a major part of every step of this setup process, as security concerns are what drives a lot of the motivations I have for coming up with this setup in the first place.  We will be doing very simple but very effective site security like the following items, which is a short list compared to everything we will be doing.</p>
<ul>
<li>Fixing file permissions automatically</li>
<li>Searching for modified files on the server</li>
<li>Encrypting your backups</li>
<li>Get alerted to breakin attempts</li>
<li>Block tons of bad clients</li>
<li>Disallowing cgi scripts or any other handlers, just serve files.</li>
<li>Configuring PHP</li>
<li>Password Protection for certain areas</li>
</ul>
<h3>Ready for Warfare?</h3>
<p>My past work for an Internet Service Provider, followed by 4 years of auditing the security of organizations external/internal networks has given me a fresh perspective on website security, and I think it allows me to see what would really be effective at preventing and killing attacks.  In fact just last night I was once again doing some research into some off-the-wall security topics, and I discovered a new defense method that I will be writing about very soon.  I believe that this new method,  could be quickly adopted and implemented by hosting providers and software developers, which would result in us finally taking the Internet back from all those zombies and robots.  This method will be discussed in great detail soon, and will be a core part of this site setups security and optimization.</p>
<hr class="HR0" />
<h2>Built to <span style="color:red">Bleed Speed</span></h2>
<p><img class="IFL" src="http://uploads.askapache.com/2008/09/speedontheroadimg.jpg" width="150" alt="Optimize a Website for Speed, Security, and Easy Management" title="326255_speed_on_the_road" />Serve&#8217;s files as fast and efficiently as possible using advanced caching, HTTP Protocols, php/server configurations.<br class="C" /></p>
<p>Many of the articles and research on this blog is about improving the speed and efficiency of your website.  In fact that is why I am helping develop open-source software to block spammers from WordPress blogs&#8230; not because I&#8217;m bothered by the spam, but because they make the net slow!  So lets look at some of the ideas we&#8217;ll be implementing.</p>
<p>Many techniques I&#8217;ve been using and tweaking for several years, and recently many of them were included in the high-performance websites list.  Of course we will be taking a look at this list in practical terms, meaning almost all of it, the caching, compression, etc., will be automated in keeping with our &#8220;comfort&#8221; goal, which is to say we want to make the Web Developer and Server Admin&#8217;s lives as easy and comfy as possible.  After all, we do the work right?</p>
<ol>
<li>Reduce HTTP requests &#8211; <a href="http://www.askapache.com/htaccess/speed-up-sites-with-htaccess-caching.html" title="304 If Modified article">Reducing 304 requests with Cache-Control Headers</a></li>
<li>Use a customized php.ini &#8211; <a href="http://www.askapache.com/php/custom-phpini-tips-and-tricks.html">Creating and using a custom PHP.ini</a></li>
<li>Add an Expires header &#8211; <a href="http://www.askapache.com/htaccess/speed-up-your-site-with-caching-and-cache-control.html#caching-with-mod_expires" title="mod_expires Caching article">Caching with mod_expires on Apache</a></li>
<li>Gzip components</li>
<li>Make CSS and unobtrusive Javascript as external files not inline</li>
<li>Reduce DNS lookups &#8211; Use Static IP address, use a subdomain with static IP address for static content.</li>
<li>Minimize Javascript &#8211; Refactor the code, compress with <a href="http://dojotoolkit.org/docs/shrinksafe" class="broken_link" rel="nofollow">dojo</a></li>
<li>Avoid external redirects &#8211; <a href="http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html" title="mod_rewrite internal redirection and rewrites">Use internal redirection with mod_rewrite</a>, <a href="http://www.askapache.com/htaccess/301-redirect-with-mod_rewrite-or-redirectmatch.html" title="301 Redirect with mod_rewrite or RedirectMatch">The correct way to redirect with 301</a></li>
<li>Turn off ETags &#8211; <a href="http://www.askapache.com/htaccess/using-http-headers-with-htaccess.html#prevent-caching-with-htaccess">Prevent Caching with htaccess</a></li>
<li>Make AJAX cacheable and small</li>
</ol>
<h3>AskApache.com, Fastest Site Ever!</h3>
<p>Ok it <em>might</em> not be the #1, but surely the top 10.. ;)</p>
<p>I&#8217;m very proud of the performance I am able to achieve on this site.  Very proud.  I started looking for ways to improve the wp-cache and wp-super-cache WordPress plugins, and came up with hacks for both of them.. but they still didn&#8217;t do what I wanted so I started from scratch and wrote my own caching plugin.</p>
<p>With much more advanced caching options and unquestionably higher performance and lower time usage on the machine.  I&#8217;m hesitant to release it to the public until I get faded on it.. I just really love it.. it has been running my site for several months now and I keep finding ways to improve it.. Stay tuned.</p>
<p>One feature it has is the ability to allow negotiation of a resource between apache and the client.  Think almost transparent mutli-lingual blogs, mutliple formats per document (look at the rdf for this page for an example*). But that plugin is the future and this is the present.. so back to it we go.</p>
<hr class="HR0" />
<h2>Pamper the Webmaster with Extreme Comfort</h2>
<p><img class="IFL" src="http://uploads.askapache.com/2008/09/wwwonthebeachimg.jpg" width="150" alt="Optimize a Website for Speed, Security, and Easy Management" title="Low Maintenance Web Development" />This section alone would make this setup appealing.  I have developed all types of techniques and methods to make my life as easy as possible.  I could literally DIE right now and this blog would continue to run and operate for years on its own.   The general philosophy that I have used to get to where I can goto the beach with my laptop and do all this crazy stuff is <strong>the idea of perfection</strong>.  That may sound a little put-offish, but it basically means I will focus in on one very specific area for improvement or research and just get sick with it.  Most of this blogs articles are enlightening examples of this in action.  I will take a relatively unknown or unused piece of code or software and experiment with it until I feel I have it down, then I move on to the next item of never-ending research.  Mostly I think this is just plain habit from when I was studying security.  I&#8217;m much better at this then that :)</p>
<h3>Apache ErrorDocuments</h3>
<p>The <a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html">57 HTTP Status Codes and Apache ErrorDocuments</a> article is a prime example.  I was simply searching for an authoritative list of HTTP status codes, an issue not many web people find worth their time, and that search led to some of the most useful stuff I&#8217;ve found about the Web</p>
<p>This &#8220;Comfort&#8221; article will include multi-language, intelligent, and optimized error documents for handling any type of HTTP error with class and allow us to stop spammers, save bandwidth, redirect correctly, etc..  You will probably be surprised at all the uses an Apache ErrorDocument can have.. It IS one of the foundations of the HTTP-based Net after all.<br class="C" /></p>
<h3>Emphasis on Easy Upgrades</h3>
<p>The whole setup is geared to make hassle-free WordPress/PHP/application upgrades possible by keeping different types of files in separate places, keeping backups, other misc tricks and since all of these files are in /home/askapache.com, your FTP connection can still access every file easily.  Sometimes security and optimizing your server can lead to it being more of a pain to do updates, backups, and general maintenance.  This article tries to overwhelm the balance with a trifecta of goals.</p>
<h3>Move to a new host? Ok!</h3>
<p>Comfort to me also means being able to pack up the whole website and database and move to another web host in under an hour.  I can move the whole AskApache site to one of several other hosting providers accounts I have in about 30minutes.  If this was a clients site or I was getting paid more, I&#8217;d also be focused on round-robin DNS technology, balance-load setups, and just go crazy making it fast.</p>
<h3>Staying Online, Improving Uptime</h3>
<p>Ever since I started sharing information and software to stop all these resource hogging zombies attacking everything I&#8217;ve been attacked several times.  Normally I get over 10K exploit attempts or requests per day, which I pretty much block 100%.  But a few times they&#8217;ve actually tried to DDOS me off the net in a distributed attack.  I have implemented several &#8220;poor mans&#8221; techniques to put up your best effort at surviving, which I did.  Basically you want to configure your server to KILL connections just as fast as possible and prevent your server resources from skyrocketing and surpassing your quotas.  A skilled attacker could easily shut you down even without the use of a widespread botnet if they are clever, which could be devastating to your small blog or site if it goes down at a crucial instant.</p>
<hr class="HR0" />
<h2>Organization with Templates and Systems</h2>
<p>I used to work with a guy who did alot of the coldfusion programming for us, and I used to cringe every  time I was called in to upgrade a site or do a re-design.  Files and folders EVERYWHERE!  Literally images in every folder, multiple index.html, index1.html, index-old.html, and on and on it went.. It would take me hours just to reverse-engineer the site enough so I could modify files on it without having some unkown consequence happen.</p>
<h3>Do You Have a Cluttered Desktop?</h3>
<p>Everyone has this problem, what I do all the time is just grab everything on my desktop and put it in a folder named with the date.  Then the process repeats itself and invariably a few months later I&#8217;m looking at a cluttered screen again.</p>
<p>This absolutely is the worst thing that can happen to a website, worst for security, comfort for webmaster, and speed.  So this setup addresses that issue completely heads on.  With all the different pages, tools, and resources available on this blog, I can almost promise you that my site has less files than yours.  No small feat to be sure, but worth every second I spent researching how to do it now that its on and popping.</p>
<hr class="HR0" />
<h2>What&#8217;s a Website really?</h2>
<p>All hosts are different, but any host worth their salt is running some kind of <a href="http://www.askapache.com/linux-unix/">BSD/Linux</a> operating system, and that is good news because those operating systems all use very similarly excellent file/folder structures with huge organization systems.  If your web hosting provider is running on a Windows based operating system or other locked/proprietary software than this article is not for you and I would recommend switching hosts to a BSD/Linux open-source operating system.</p>
<h3>Listening for Requests with Web Hosting and DNS</h3>
<p>First you set your website up so it can start serving.</p>
<ol>
<li>You buy your domain name, which just gives you the right to use it.</li>
<li>You pay your webhost for an account on their machine running a Server connected to the Net <em>via a fast connection link</em>.</li>
<li>You pay a DNS provider to redirect requests for your domain  name to be sent to your webhosts machine running the server.</li>
</ol>
<h2>Sub-Domain for Serving Assets</h2>
<p>This is a very cool method I&#8217;ve been using more and more frequently because it makes updates, upgrades, and changes so much easier to manage.  And segmenting various parts of the site is smart security, and even smarter in the way of speeding up a website and keeping your <strong>servers running mean and lean</strong>.</p>
<h2>Full Site Structure Expanded</h2>
<pre>/home/askapache.com
|&#45;- /home/askapache.com/backups/
|&#45;- /home/askapache.com/public_html/
|   |&#45;- /home/askapache.com/public_html/about/
|   |&#45;- /home/askapache.com/public_html/admin/
|   |&#45;- /home/askapache.com/public_html/cgi-bin/
|   |&#45;- /home/askapache.com/public_html/.htaccess
|   |&#45;- /home/askapache.com/public_html/index.php
|   `&#45;- /home/askapache.com/public_html/robots.txt
|&#45;- /home/askapache.com/inc/
|   |&#45;- /home/askapache.com/inc/config.inc.php
|   `&#45;- /home/askapache.com/inc/settings.inc.php
|&#45;- /home/askapache.com/logs/
|   |&#45;- /home/askapache.com/logs/access.log
|   |&#45;- /home/askapache.com/logs/error.log
|   |&#45;- /home/askapache.com/logs/logins.log
|   |&#45;- /home/askapache.com/logs/modsec_audit.log
|   |&#45;- /home/askapache.com/logs/modsec_debug.log
|   `&#45;- /home/askapache.com/logs/php_error.log
|&#45;- /home/askapache.com/static/
|   |&#45;- /home/askapache.com/static/css/
|   |&#45;- /home/askapache.com/static/flv/
|   |&#45;- /home/askapache.com/static/img/
|   |&#45;- /home/askapache.com/static/js/
|   |&#45;- /home/askapache.com/static/mp3/
|   |&#45;- /home/askapache.com/static/pdf/
|   |&#45;- /home/askapache.com/static/swf/
|   |&#45;- /home/askapache.com/static/.htaccess
|   |&#45;- /home/askapache.com/static/index.html
|   `&#45;- /home/askapache.com/static/robots.txt
|&#45;- /home/askapache.com/tmp/
|&#45;- /home/askapache.com/.htpasswd-basic
`&#45;- /home/askapache.com/.htpasswd-digest</pre>
<h2>Full Expanded Structure</h2>
<pre>/home/askapache.com
|&#45;- /home/askapache.com/backups/
|&#45;- /home/askapache.com/public_html/
|   |&#45;- /home/askapache.com/public_html/about/
|   |   `&#45;- /home/askapache.com/public_html/about/index.html
|   |&#45;- /home/askapache.com/public_html/admin/
|   |   |&#45;- /home/askapache.com/public_html/admin/.htaccess
|   |   `&#45;- /home/askapache.com/public_html/admin/index.html
|   |&#45;- /home/askapache.com/public_html/cgi-bin/
|   |   |&#45;- /home/askapache.com/public_html/cgi-bin/bin/
|   |   |   |&#45;- /home/askapache.com/public_html/cgi-bin/bin/.htaccess
|   |   |   |&#45;- /home/askapache.com/public_html/cgi-bin/bin/php.cgi*
|   |   |   |&#45;- /home/askapache.com/public_html/cgi-bin/bin/php.ini
|   |   |   |&#45;- /home/askapache.com/public_html/cgi-bin/bin/php4.cgi*
|   |   |   `&#45;- /home/askapache.com/public_html/cgi-bin/bin/php5.cgi*
|   |   |&#45;- /home/askapache.com/public_html/cgi-bin/private/
|   |   |   |&#45;- /home/askapache.com/public_html/cgi-bin/private/.htaccess
|   |   |   |&#45;- /home/askapache.com/public_html/cgi-bin/private/debug.php
|   |   |   `&#45;- /home/askapache.com/public_html/cgi-bin/private/stats.php
|   |   |&#45;- /home/askapache.com/public_html/cgi-bin/.htaccess
|   |   |&#45;- /home/askapache.com/public_html/cgi-bin/login.php
|   |   |&#45;- /home/askapache.com/public_html/cgi-bin/printenv.cgi*
&nbsp;
|   |   `&#45;- /home/askapache.com/public_html/cgi-bin/redir.cgi*
|   |&#45;- /home/askapache.com/public_html/.htaccess
|   |&#45;- /home/askapache.com/public_html/index.php
|   `&#45;- /home/askapache.com/public_html/robots.txt
|&#45;- /home/askapache.com/inc/
|   |&#45;- /home/askapache.com/inc/config.php
|   `&#45;- /home/askapache.com/inc/functions.php
|&#45;- /home/askapache.com/logs/
|   |&#45;- /home/askapache.com/logs/access.log
|   |&#45;- /home/askapache.com/logs/error.log
|   |&#45;- /home/askapache.com/logs/logins.log
|   |&#45;- /home/askapache.com/logs/modsec_audit.log
|   |&#45;- /home/askapache.com/logs/modsec_debug.log
|   `&#45;- /home/askapache.com/logs/php_error.log
|&#45;- /home/askapache.com/static/
|   |&#45;- /home/askapache.com/static/css/
|   |   `&#45;- /home/askapache.com/static/css/apache.css
|   |&#45;- /home/askapache.com/static/flv/
|   |   `&#45;- /home/askapache.com/static/flv/apache.flv
|   |&#45;- /home/askapache.com/static/img/
|   |   |&#45;- /home/askapache.com/static/img/apache.gif
|   |   |&#45;- /home/askapache.com/static/img/apache.jpg
|   |   `&#45;- /home/askapache.com/static/img/apache.png
|   |&#45;- /home/askapache.com/static/js/
|   |   `&#45;- /home/askapache.com/static/js/apache.js
|   |&#45;- /home/askapache.com/static/mp3/
|   |   `&#45;- /home/askapache.com/static/mp3/apache.mp3
|   |&#45;- /home/askapache.com/static/pdf/
|   |   `&#45;- /home/askapache.com/static/pdf/apache.pdf
|   |&#45;- /home/askapache.com/static/swf/
|   |   `&#45;- /home/askapache.com/static/swf/apache.swf
|   |&#45;- /home/askapache.com/static/.htaccess
|   |&#45;- /home/askapache.com/static/index.html
|   `&#45;- /home/askapache.com/static/robots.txt
|&#45;- /home/askapache.com/tmp/
|&#45;- /home/askapache.com/.htpasswd-basic
`&#45;- /home/askapache.com/.htpasswd-digest</pre>
<p>The buzz about apache and open-source is very real, apache is becoming more of a discussed topic as people realize the power and importance of <q cite="LL Cool J">Doing it and Doing it and Doing it well.</q> &#8211;  <small><a href="http://www.webmonkey.com/blog/Jumpbox_Offers_an_Easier_Way_to_Install_Movable_Type">Movable Type Apache Installs made easy</a>, <a href="http://www.ubuntugeek.com/webalizer-apache-web-server-log-file-analysis-tool.html">Checking out Apache Web logs</a>, <a href="http://eventurebiz.com/blog/securing-securing-your-wordpress-blog-post-6-protecting-the-wp-configphp-file/" class="broken_link" rel="nofollow">Securing WordPress with .htaccess</a>, <a href="http://marketingdefined.com/blog/wordpress/using-wordpress-permalink-redirect-plugins-correctly/">WordPress Permalinks and .htaccess</a>, <a href="http://corpocrat.com/2008/09/19/install-apache-mod_substitute/">New search and replace module for apache!</a>, <a href="http://www.csskarma.com/blog/creating-an-htaccess-template/">creating an .htaccess template</a>, <a href="http://www.thelinuxblog.com/htaccess-allow-from/">.htaccess allow directive</a></small></p>
<p class="anote">Check back in a week for the first article, or better yet subscribe to my <a href="http://www.askapache.com/feed/">rss feed</a> or use the comment form below to get notified.</p>
<p><a href="http://www.askapache.com/htaccess/optimize-website-files-cache-security.html"></a><a href="http://www.askapache.com/htaccess/optimize-website-files-cache-security.html">Optimize a Website for Speed, Security, and Easy Management</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/optimize-website-files-cache-security.html/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Custom bash_profile for Advanced Shell Users</title>
		<link>http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html</link>
		<comments>http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html#comments</comments>
		<pubDate>Mon, 23 Nov 2009 20:32:26 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Linux Unix BSD]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[.bashrc]]></category>
		<category><![CDATA[500]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[Advanced]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[Backups]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[bash alias]]></category>
		<category><![CDATA[bash_profile]]></category>
		<category><![CDATA[CCZE]]></category>
		<category><![CDATA[chmod]]></category>
		<category><![CDATA[CNAME]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[Dig]]></category>
		<category><![CDATA[DreamHost]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Forms]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[GPG]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[HostGator]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[Htpasswd]]></category>
		<category><![CDATA[HTTP Headers]]></category>
		<category><![CDATA[HTTPS SSL]]></category>
		<category><![CDATA[ionice]]></category>
		<category><![CDATA[iostat]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Nice]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[Prompt]]></category>
		<category><![CDATA[PS1]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Redirect]]></category>
		<category><![CDATA[Redirection]]></category>
		<category><![CDATA[Renice]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[shell script]]></category>
		<category><![CDATA[Socket]]></category>
		<category><![CDATA[SOCKS]]></category>
		<category><![CDATA[SPEED]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[stat]]></category>
		<category><![CDATA[SymLinks]]></category>
		<category><![CDATA[Ulimit]]></category>
		<category><![CDATA[Wget]]></category>
		<category><![CDATA[WiredTree]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[wp-config.php]]></category>
		<category><![CDATA[xargs]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=3183</guid>
		<description><![CDATA[<p>Looking for some <strong>advanced uses for the shell</strong>?  Here is <del>some of</del> my best.  The shell is where 70% of my work takes place, and I have at least one terminal open almost 100% of the time, for viewing tailing color-coded logs, and of course for the SSH Tunnels that I use to route various networking through, like my email.  So I decided that to standardize and create a bash_profile containing the most time-saving and helpful functions that I could use on all the various hosting environments would really be some sweet sugar, so here is my constant Work-in-progress.</p>
<p>It works for all shells I encounter, including BackTrack, Debian, Knoppix, Arch Linux, etc.   Also works for many hosting environments I use including DreamHost, HostGator, WiredTree, and pretty much any linux VPS.</p>
<p>I also rely on this heavily from within shell scripts I write to access all the functions and stuff in this .bash_profile, and to do that I just do like:</p>
<pre>#!/bin/bash
&#160;
source ~/.bash_profile &#38;&#62;/dev/nulll
&#160;
pm &#34;PM is a function to output nice messages with color&#34;
yn &#34;Are you enjoying the shell&#34; &#38;&#38; pm &#34;Thats great!&#34; &#124;&#124; pm &#34;Perhaps you&#039;re better suited for DOS&#34;
yn &#34;Show Calendar&#34; &#38;&#38; aa_calendar
yn &#34;Show Fortune&#34; &#38;&#38; aa_fortune</pre>]]></description>
			<content:encoded><![CDATA[<div class='images'><a href='http://uploads.askapache.com/2009/08/askapache-bash_profile.png'><img src="http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?fltr=usm&src=http://uploads.askapache.com/2009/08/askapache-bash_profile.png&w=400" title=" featured" alt="Custom bash profile for Advanced Shell Users" /></a></div><p>Looking for some <strong>advanced uses for the shell</strong>?  Here is <del>some of</del> my best.  Works for all shells I encounter, including BackTrack, Debian, Knoppix, Arch Linux, etc.   Also works for many hosting environments I use including DreamHost, HostGator, WiredTree, and pretty much any linux VPS.</p>
<p class="anote">Want to get started?  Type the following in your shell to download the script and run it.  You should go over the code first and then you can just save it as your .bash_profile &#8211; whenever you want to get updated to the latest version just type aaup, a cool update function that auto dos2unix&#8217;s and runs via an exec command.</p>
<pre>curl -O http://static.askapache.com/askapache-bash-profile.txt &amp;&amp; source askapache-bash-profile.txt
Or if you trust me and my hosting provider (and you aren&#039;t on production)
curl -o ~/.bash_profile http://static.askapache.com/askapache-bash-profile.txt &amp;&amp; exec bash -l</pre>
<p>For those of you power users and server admins that use Bash, ksh, csh, vanilla sh, etc.., or if you are just passionate about shell scripting, because it allows you to get advanced tasks done fast and efficiently, not to mention automated automatically.  I give you my .bash_profile file.   You should edit it to fit your needs, (especially the exported vars like PATH, LDFLAGS, if you don&#8217;t understand something just comment it out) but it&#8217;s pretty universal because I work on alot of other people&#8217;s servers not to mention many different distros and platforms, and when I get hired to do some server work through a shell, I bring this script along for the ride.</p>
<h2>askapache-bash-profile.txt</h2>
<p>You can download the latest version: <a href="http://static.askapache.com/askapache-bash-profile.txt">http://static.askapache.com/askapache-bash-profile.txt</a></p>
<p>The functions and variables below are the way bash sees them, using declare -f, and alias, to make it easier for you to read and understand them.    The actual file at <a href="http://static.askapache.com/askapache-bash-profile.txt">http://static.askapache.com/askapache-bash-profile.txt</a> will always be the most updated version, as I use it personally.  And it has the whole file the way I wrote it, meaning many extra notes and much simpler to follow. Enjoy!</p>
<h2>Gist of the Script..</h2>
<p>I also rely on this heavily from within shell scripts I write to access all the functions and stuff in this .bash_profile, and to do that I just do like:</p>
<pre>#!/bin/bash
&nbsp;
source ~/.bash_profile &amp;&gt;/dev/nulll
&nbsp;
pm &quot;PM is a function to output nice messages with color&quot;
yn &quot;Are you enjoying the shell&quot; &amp;&amp; pm &quot;Thats great!&quot; || pm &quot;Perhaps you&#039;re better suited for DOS&quot;
yn &quot;Show Calendar&quot; &amp;&amp; aa_calendar
yn &quot;Show Fortune&quot; &amp;&amp; aa_fortune</pre>
<pre>alias chmod=&#039;command chmod -c&#039;
alias cpr=&#039;command cp -rpv&#039;
alias df=&#039;command df -kTh&#039;
alias df1=&#039;command df -iTa&#039;
alias diff=&#039;diff -up&#039;
alias dsiz=&#039;du -sk * | sort -n &#45;-&#039;
alias du=&#039;command du -kh&#039;
alias du1=&#039;echo *|tr &quot; &quot; &quot;\n&quot; |xargs -iFF command du -hs FF|sort&#039;
alias env=&#039;command env | sort&#039;
alias h=&#039;history&#039;
alias inice=&#039;ionice -c3 -n7 nice&#039;
alias j=&#039;jobs -l&#039;
alias la=&#039;command ls -Al &#45;-color=auto&#039;
alias lc=&#039;command ls -lAcr &#45;-color=auto&#039;
alias less=&#039;vless&#039;
alias lessc=&#039;ccze -A |`type -P less` -R&#039;
alias lk=&#039;command ls -lASr &#45;-color=auto&#039;
alias llh=&#039;ll -h&#039;
alias lll=&#039;stat -c %a\ %N\ %G\ %U ${PWD}/*|sort&#039;
alias lr=&#039;command ls -lAR &#45;-color=auto&#039;
alias lt=&#039;command ls -lAtr &#45;-color=auto&#039;
alias lu=&#039;command ls -lAur &#45;-color=auto&#039;
alias lx=&#039;command ls -lAXB &#45;-color=auto&#039;
alias mann=&#039;command man -H&#039;
alias n=&#039;/usr/bin/nano3&#039;
alias p=&#039;command ps -HAcl -F S -A f|uniq -w3&#039;
alias path=&#039;echo -e ${PATH//:/\\n}&#039;
alias php=&#039;php -d report_memleaks=1 -d report_zend_debug=1 -d log_errors=0 -d ignore_repeated_errors=0 -d ignore_repeated_source=0 -d error_reporting=30719 -d display_startup_errors=1 -d display_errors=1&#039;
alias pp=&#039;command ps -HAcl -F S -A f&#039;
alias ps1=&#039;command ps -lFA&#039;
alias ps2=&#039;command ps -H&#039;
alias resetw=&#039;echo $&#039;\&#039;&#039;\33[H\33[2J&#039;\&#039;&#039;&#039;
alias subash=&#039;sudo sh -c &#039;\&#039;&#039;export HOME=/root; cd /root; exec bash -l&#039;\&#039;&#039;&#039;
alias top=&#039;top -c&#039;
alias tree=&#039;command tree -Csuflapi&#039;
alias updatedb=&#039;( ( updatedb 2&gt;/dev/null ) &amp; )&#039;
alias vim=&#039;command vim &#45;-noplugin&#039;
alias who=&#039;command who -ar -pld&#039;
alias wtf=&#039;watch -n 1 w -hs&#039;</pre>
<pre>aa_aliases ()
{
    local F=`for i in $(alias|awk -F= &#039;{print $1}&#039;);do echo $i;done|sed -e :a -e &#039;s/^.\{1,15\}$/&amp; /;ta&#039;|tr &#039; &#039; &#039;\032&#039;`;
    i=1;
    for f in ${F};
    do
        echo -en &quot;$f&quot;;
        (( $i % 4 ==0 )) &amp;&amp; echo -en &quot;\n&quot;;
        i=$(( $i + 1));
    done | tr &#039;\032&#039; &quot; &quot;
}
aa_beep ()
{
    local i;
    for i in `seq 1 ${1:-5}`;
    do
        echo -en &quot;\a&quot; &amp;&amp; sleep 1;
    done
}
aa_calendar ()
{
    [[ -d /usr/share/calendar/ ]] &amp;&amp; echo -en &quot;\n${CC[4]}&quot; &amp;&amp; ( sed = $(echo /usr/share/calendar/calendar*) | sed -n &quot;/$(date +%m\\/%d\\\|%b\*\ %d)/p&quot; ) &amp;&amp; echo -en &quot;${R}&quot;
}
aa_current_users ()
{
    echo -n &quot;`command who -q |sed &#039;/^# users=\([0-9]*\).*/!d; s//\1/;q&#039;`&quot;
}
aa_find_exec ()
{
    find -L ${1:-.} -type f -perm +0100 2&gt;$N6 | xargs file | sed -e &#039;s%^\([^:]*\):\([^,]*\).*$%\1:\2%g&#039;
}
aa_fortune ()
{
    local FORTUNE=`command type -P fortune`;
    [[ -x $FORTUNE ]] &amp;&amp; echo -en &quot;\n${CC[5]}&quot; &amp;&amp; $FORTUNE -s &amp;&amp; echo -en &quot;${R}&quot;;
    [[ -x $FORTUNE ]] &amp;&amp; echo -en &quot;\n${CC[6]}&quot; &amp;&amp; $FORTUNE -s &amp;&amp; echo -en &quot;${R}&quot;;
    [[ -x $FORTUNE ]] &amp;&amp; echo -en &quot;\n${CC[7]}&quot; &amp;&amp; $FORTUNE -s &amp;&amp; echo -en &quot;${R}&quot;;
    [[ -x $FORTUNE ]] &amp;&amp; echo -en &quot;\n${CC[8]}&quot; &amp;&amp; $FORTUNE -s &amp;&amp; echo -e &quot;${R}&quot;
}
aa_free_mem ()
{
    echo -n &quot;`[[ -r /proc/meminfo ]] &amp;&amp; sed &#039;/^MemFree: */!d; s///;q&#039; /proc/meminfo`&quot;
}
aa_functions ()
{
    local F=`for i in $(declare -F | sed -e &#039;s/declare -f //g&#039;); do echo $i; done| sed -e :a -e &#039;s/^.\{1,25\}$/&amp; /;ta&#039;|tr &#039; &#039; &#039;\032&#039;`;
    i=1;
    for f in ${F};
    do
        echo -en &quot;$f&quot;;
        (( $i % 4 ==0 )) &amp;&amp; echo -en &quot;\n&quot;;
        i=$(( $i + 1));
    done | tr &#039;\032&#039; &quot; &quot;
}
aa_getsrc ()
{
    [[ &quot;$#&quot; -lt &quot;1&quot; ]] &amp;&amp; echo &quot;Usage: $FUNCNAME &lt;url&gt;&quot; 1&gt;&amp;2 &amp;&amp; return 2;
    [[ -z &quot;$CPPFLAGS&quot; ]] &amp;&amp; pm &quot;Setting CPPFLAGS&quot; &amp;&amp; export CPPFLAGS=&quot;-I/usr/local/include/libxml2 -I/opt/libiconv/include&quot;;
    [[ -z &quot;$LD_FLAGS&quot; ]] &amp;&amp; pm &quot;Setting LD_FLAGS&quot; &amp;&amp; export LD_FLAGS=&quot;-L/usr/local/lib -L/usr/local/lib/python2.4/site-packages -L/usr/local/lib -lxml2 -lz -L/opt/libiconv/lib -liconv -lm&quot;;
    function aa_err ()
    {
        echo &#039;&#039;;
        local s;
        echo -en &quot;\n [ ${1:-Press any key to continue} ]\n&quot;;
        read -n 1 s
    };
    function aa_install ()
    {
        ./configure &#45;-help;
        ./configure &#45;-prefix=/usr/local &quot;$*&quot; &amp;&amp; make -j3 &amp;&amp; sudo make install || aa_err;
        echo -en &quot;\a&quot;
    };
    function aa_extract ()
    {
        case $1 in
            *.tar.bz2)
                tar xjf $1
            ;;
            *.tar.gz)
                tar xzf $1
            ;;
            *.tar)
                tar xf $1
            ;;
            *.tbz2)
                tar xjf $1
            ;;
            *.tgz)
                tar xzf $1
            ;;
            *.bz2)
                bunzip2 $1
            ;;
            *.rar)
                unrar x $1
            ;;
            *.gz)
                gunzip $1
            ;;
            *.zip)
                unzip $1
            ;;
            *.Z)
                uncompress $1
            ;;
            *.7z)
                7z x $1
            ;;
            *)
                aa_err
            ;;
        esac
    };
    local OD=`pwd -L`;
    local FN=$(echo $1 | sed -e &#039;s/^.*\/\([^\/]\{3,\}\)$/\1/g&#039;);
    local SN=$(echo $FN |  sed -e &#039;s/\(.\{1\}\)\([^-.]\{1,\}\).*/\1\2/g&#039;);
    echo -e &quot;OD: $OD \n1: $1 \nFN: $FN \nSN: $SN&quot; &amp;&amp; sleep 1;
    cd /opt/dist;
    ( curl -# -L -f -b c.txt &#45;-cookie-jar c.txt -m 400 -O -H &#039;Accept: */*&#039; -s -S -A &#039;Mozilla/5.0 (Windows NT 5.1; en-US; rv:1.9.1.5) Gecko/2009 Firefox/3.5.5&#039; -e &quot;$1&quot; &#45;-url &quot;$1&quot; || v_err &quot;CURL FAILED for $1&quot; );
    [[ -f &quot;$FN&quot; ]] &amp;&amp; aa_extract &quot;$FN&quot; || aa_err &quot;EXTRACTING FAILED for $FN, go manual it&quot;;
    [[ -d &quot;/opt/$SN&quot; ]] &amp;&amp; mv -v /opt/$SN /opt/.old-$SN;
    mv -v /opt/source/`echo $1|sed -e &#039;s/.*\/\(.*\)\.\([tgz7bar2v]*\)\(\.[tgz7bar2v]*\)$/\1/g&#039;` /opt/$SN || aa_err &quot;Please mv $1 to /opt/$SN&quot;;
    cd /opt/$SN &amp;&amp; command ls -lABls1c $AAC &amp;&amp; aa_install;
    cd $OD
}</pre>
<pre>aa_hexdump ()
{
    local EX;
    [[ $# -eq 1 ]] &amp;&amp; EX=exec;
    [[ -f &quot;$1&quot; ]] &amp;&amp; EX=&#039;cat &quot;$1&quot;&#039;;
    case ${2:-1} in
        0)
            $EX hexdump -C
        ;;
        1)
            $EX hexdump -Cc
        ;;
        2)
            $EX hexdump -Cx
        ;;
        3)
            $EX hexdump -C -e &#039;&quot;&quot;  10/1 &quot;&#039;\&#039;&#039;%_c&#039;\&#039;&#039;\t&quot; &quot;\n&quot;&#039; -e &#039;&quot;&quot; 10/1 &quot;0x%02x\t&quot; &quot;\n\n&quot;&#039;
        ;;
        4)
            $EX hexdump -e &#039;&quot;&quot;  10/1 &quot;&#039;\&#039;&#039;%_c&#039;\&#039;&#039;\t&quot; &quot;\n&quot;&#039;
        ;;
        5)
            $EX hexdump -e &#039;&quot;&quot;  10/1 &quot;&#039;\&#039;&#039;%_c&#039;\&#039;&#039;\t&quot; &quot;\n&quot;&#039; -e &#039;&quot;&quot; 10/1 &quot;0x%04x\t&quot; &quot;\n\n&quot;&#039;
        ;;
        6)
            $EX hexdump -e &#039;90/1 &quot;%_p&quot; &quot;\n&quot;&#039;
        ;;
        7)
            $EX hexdump -e &#039;1/1 &quot;%04_u&quot; &quot;%4_p&quot; &quot;   &quot; 1/1 &quot;%04x&quot; &quot;  &quot; 1/1 &quot;%04_c&quot;  &quot;\n&quot;&#039;
        ;;
        8)
            $EX hexdump -v -e &#039;&quot;x&quot; 1/1 &quot;%02X&quot; &quot; &quot;&#039;
        ;;
        9)
            $EX od -Ax -tx1 -v
        ;;
        10)
            $EX od -t o1z -w1 -Ao -v
        ;;
        11)
            $EX xxd -
        ;;
        12)
            $EX xxd -c1
        ;;
        13)
            $EX xxd -h
        ;;
        14)
            $EX
        ;;
    esac
}
aa_ips ()
{
    ahave ip &amp;&amp; ip -o -f inet addr 2&gt;&amp;1 | sed -e &#039;s/.*inet \([^/]*\).*/\1/g&#039; | sort -u;
    ahave ss &amp;&amp; ss -n 2&gt;&amp;1 | sed -e &#039;s/[^:]*\ \([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\)\:.*/\1/&#039; -e &#039;/^\([^0-9]\|127\.\|10\.\|172\.\)/d&#039; | sort -u;
    [[ -f &quot;$HOME/.cpanel/datastore/_sbin_ifconfig_-a&quot; ]] &amp;&amp; sed -e &#039;/inet/!d&#039; -e &#039;s/.*addr:\([0-9\.]*\).*/\1/g&#039; &quot;$HOME/.cpanel/datastore/_sbin_ifconfig_-a&quot; | sort -u;
    sed -e &#039;s/^\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*/\1/&#039; -e &#039;/^\([^0-9]\|127\.\|10\.\|172\.\|$\)/d&#039; /etc/hosts | sort -u
}
aa_isalpha ()
{
    [[ &quot;$#&quot; -lt &quot;1&quot; ]] &amp;&amp; echo &quot;Usage: $FUNCNAME str&quot; 1&gt;&amp;2 &amp;&amp; return 2;
    case $1 in
        *[!a-zA-Z]* | &quot;&quot;)
            return -1
        ;;
        *)
            return 0
        ;;
    esac
}
aa_isdigit ()
{
    case $1 in
        *[!0-9]* | &quot;&quot;)
            return -1
        ;;
        *)
            return 0
        ;;
    esac
}
aa_mkdir ()
{
    [[ &quot;$#&quot; -lt &quot;1&quot; ]] &amp;&amp; echo &quot;Usage: $FUNCNAME &quot; 1&gt;&amp;2 &amp;&amp; return 2;
    local e=0;
    for f in ${1+&quot;$@&quot;};
    do
        set fnord `echo &quot;:$f&quot;|sed -e &#039;s/^:\//%/&#039; -e &#039;s/^://&#039; -e &#039;s/\// /g&#039; -e &#039;s/^%/\//&#039;`;
        shift;
        p=;
        for d in ${1+&quot;$@&quot;};
        do
            p=&quot;$p$d&quot;;
            case &quot;$p&quot; in
                -*)
                    p=./$p
                ;;
                ?:)
                    p=&quot;$p/&quot;;
                    continue
                ;;
            esac;
            [[ ! -d &quot;$p&quot; ]] &amp;&amp; mkdir -v &quot;$p&quot; || e=$?;
            p=&quot;$p/&quot;;
        done;
    done;
    return $e
}
aa_motd ()
{
    [[ -r /etc/motd &amp;&amp; `cat /etc/motd |wc -l` -gt 7 ]] &amp;&amp; ( echo -e &quot;\n\n${CC[2]}`head -n 7 /etc/motd | tail -n 6`${R}\n&quot; ) &amp;&amp; return;
    ahave figlet &amp;&amp; figlet $HOSTNAME
}
aa_num_procs ()
{
    echo -n `command ps aux|wc -l`
}
aa_prompt ()
{
    AAPS[0]=&#039;\n\e[1;30m[\e[0;37m${SHLVL}\e[1;30m:\e[0;37m\j:\!\e[1;30m][\e[1;34m\u\e[0;34m@\e[1;34m\h\e[1;30m:\e[1;37m${SSHTTY/\/dev\/}\e[1;30m]\e[0;37m[\e[0;37m\w\e[0;37m]\e[1;30m\n\[${R}\]\$ &#039;;
    AAPS[1]=&#039;\n\e[1;30m[\e[0;37m${SHLVL}\e[1;30m:\e[0;37m\j:\!\e[1;30m][\e[0;32m\u\e[1;32m@\e[0;32m\h\e[1;30m:\e[1;37m${SSHTTY/\/dev\/}\e[1;30m]\e[0;37m[\e[0;37m\w\e[0;37m]\e[1;30m\n\[${R}\]\$ &#039;;
    AAPS[2]=&#039;\n\e[1;30m[\e[0;37m${SHLVL}\e[1;30m:\e[0;37m\j:\!\e[1;30m][\e[0;35m\u\e[1;35m@\e[0;35m\h\e[1;30m:\e[1;37m${SSHTTY/\/dev\/}\e[1;30m]\e[0;37m[\e[0;37m\w\e[0;37m]\e[1;30m\n\[${R}\]\$ &#039;;
    : ${PLVL=0};
    [[ &quot;${#AAPS[@]}&quot; -lt &quot;$PLVL&quot; || &quot;${#AAPS[@]}&quot; -eq &quot;$PLVL&quot; ]] &amp;&amp; PLVL=0;
    export PS1=${AAPS[$PLVL]} &amp;&amp; (( PLVL++ )) &amp;&amp; export PLVL;
    echo &quot;PLVL=$PLVL&quot;
}
aa_random_under ()
{
    echo $(( $RANDOM % ${1:-$RANDOM} + 1 ))
}
aa_safe_aliases ()
{
    local MYMVR=$(command type -t mymvmymv);
    [[ &quot;$MYMVR&quot; == &quot;alias&quot; ]] &amp;&amp; echo &quot;Turning Safe Aliases Off&quot; &amp;&amp; for fa in &quot;chmod&quot; &quot;mkdir&quot; &quot;rm&quot; &quot;cp&quot; &quot;mv&quot; &quot;mymv&quot;;
    do
        unalias $fa;
    done &amp;&amp; return;
    echo &quot;Turning Safe Aliases On&quot;;
    alias chmod=&#039;command chmod -c&#039;;
    alias mkdir=&#039;command mkdir -pv&#039;;
    alias rm=&#039;command rm -v&#039;;
    alias cp=&#039;command cp -v&#039;;
    alias mv=&#039;command mv -v&#039;;
    alias mymv=&#039;echo&#039;
}</pre>
<pre>aa_savehist ()
{
    history ${HISTCMD:-5000} | sed -e &#039;s/^[ 0-9]*\(.*\)/\1/g&#039; | tee -a $HISTFILEMASTER_C &gt;&gt;$HISTFILEMASTER;
    cat $HISTFILE | tee -a $HISTFILEMASTER_C &gt;&gt;$HISTFILEMASTER;
    history -w;
    echo
}
aa_show_all_colors ()
{
    for c in `seq 0 255`;
    do
        t=5;
        [[ $c -lt 108 ]] &amp;&amp; t=0;
        for i in `seq $t 5`;
        do
            echo -e &quot;\e[0;48;$i;${c}m|| $i:$c `seq -s+0 $(($COLUMNS/2))|tr -d &#039;[0-9]&#039;`\e[0m&quot;;
        done;
    done;
    echo;
    echo Table for 16-color terminal escape sequences.;
    echo Replace ESC with \\033 in bash.;
    echo;
    echo &quot;Background | Foreground colors&quot;;
    echo &quot;&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&quot;;
    for ((bg=40; bg&lt;=47; bg++))
    do
        for ((bold=0; bold&lt;=1; bold++))
        do
            echo -en &quot;\033[0m&quot;&quot; ESC[${bg}m   | &quot;;
            for ((fg=30; fg&lt;=37; fg++))
            do
                if [ $bold == &quot;0&quot; ]; then
                    echo -en &quot;\033[${bg}m\033[${fg}m [${fg}m  &quot;;
                else
                    echo -en &quot;\033[${bg}m\033[1;${fg}m [1;${fg}m&quot;;
                fi;
            done;
            echo -e &quot;\033[0m&quot;;
        done;
        echo &quot;&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;- &quot;;
    done;
    echo;
    echo
}
aa_sleep ()
{
    echo -en &quot;${CC[6]}${3:-.}&quot;;
    while `command ps -p $1 &amp;&gt;/dev/null`; do
        echo -n &quot;${3:-.}&quot;;
        sleep ${3:-1};
    done;
    echo -e &quot;$R$X&quot; &amp;&amp; sleep 1 &amp;&amp; pd
}
aa_try_for_path ()
{
    local GP=$HOME/bin:$HOME/sbin;
    [[ -z &quot;$PATH&quot; || &quot;$PATH&quot; == &quot;/bin:/usr/bin&quot; ]] &amp;&amp; export PATH=&quot;/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games&quot;;
    local P=$PATH:$HOME/libexec;
    [[ &quot;$EUID&quot; -eq 0 ]] &amp;&amp; P=&quot;/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11&quot;;
    P=${P}:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games;
    P=${P}:/bin:/etc:/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/bin/mh:/usr/libexec;
    P=${P}:/usr/X11R6/bin:/usr/libexec:/etc/X11:/etc/X11/xinit;
    [[ &quot;$DREAMHOST&quot; == &quot;yes&quot; ]] &amp;&amp; ( P=${P}:/usr/local/dh/apache/template/bin:/usr/local/dh/apache2/template/bin;
    P=${P}:/usr/local/dh/apache2/template/build:/usr/local/dh/apache2/template/sbin;
    P=${P}:/usr/local/dh/bin:/usr/local/dh/java/bin:/usr/local/dh/java/jre/bin;
    P=${P}:/usr/lib/ruby/gems/1.8/bin:$HOME/.gem/ruby/1.8/bin );
    P=${P}:/usr/local/php5/bin;
    for p in ${P//:/ };
    do
        [[ -d &quot;${p}&quot; &amp;&amp; -x &quot;${p}&quot; ]] &amp;&amp; GP=${GP}:$p;
    done;
    export PATH=$( echo -en &quot;${GP//:/\\n}&quot; | sed -n &#039;G; s/\n/&amp;&amp;/; /^\([ -~]*\n\).*\n\1/d; h; P&#039; | tr &quot;\n&quot; : ).
}
aa_uniqhistory ()
{
    ( echo $HISTFILE;
    find $HISTFILEMASTER_DIR -type f 2&gt;$N6 ) | xargs -iFFF cat FFF 2&gt;$N6 | sed -e &#039;s/^[ \t]*//;s/[ \t]*$//&#039; -e &#039;/[^ \t]\{1,\}/!d&#039; | tr &#45;-squeeze &#039; &#039; | sort -u
}
aa_weather ()
{
    ahave lynx || return;
    local city weather=$HOME/.weather;
    echo -e &quot;${CC[3]}&quot;;
    local res=`pkill -9 -f 15m &amp;&gt;$N6 || echo -n`;
    [[ -r $weather ]] &amp;&amp; cat $weather &amp;&amp; ( ( sleep 15m &amp;&amp; command rm $HOME/.weather &gt;&amp;$N6 ) &amp; );
    [[ ! -r $weather ]] &amp;&amp; ( ( ( city=`lynx -dump http://api.hostip.info/get_html.php|sed -e &#039;/^City/!d&#039; -e &#039;s/City: \([^,]*\), \(.*\)/\1+\2/g&#039;` &amp;&amp; lynx -dump &quot;http://www.google.com/search?hl=en&amp;q=weather+${city}&quot; | sed -n &#039;/Weather for/,/Search Res/p&#039; | tr -d &#039;\260&#039; | sed -e &#039;/iGoogle/d&#039; -e &#039;s/^[ \t]*//;s/[ \t]*$//&#039; | sed &#039;$d&#039; | head -n 6 &gt;$weather ) &amp;  &gt;&amp;/dev/null ) );
    echo -e $R
}
aaup ()
{
    curl3 -0 -o ~/.bash_profile http://static.askapache.com/askapache-bash-profile.txt &amp;&amp; dos2unix -dv ~/.bash_profile &amp;&amp; ( rm -rf ~/{.bash_logout,.toprc,.lynxrc,.ncftp} || echo;
    echo ) &amp;&amp; aa_savehist &amp;&amp; exec bash -l
}
ahave ()
{
    unset -v ahave;
    command command type $1 &gt;&amp;$N6 &amp;&amp; ahave=&quot;yes&quot; || return 1
}
ahelp ()
{
    unset -v ahelp;
    [[ &quot;$#&quot; -gt &quot;0&quot; ]] &amp;&amp; [[ &quot;$1&quot; == &quot;-h&quot; || &quot;$1&quot; == &quot;&#45;-h&quot; || &quot;$1&quot; == &quot;&#45;-help&quot; || &quot;$1&quot; == &quot;-help&quot; || &quot;$1&quot; == &quot;-?&quot; ]] &amp;&amp; ahelp=&quot;yes&quot;
}
arepeat ()
{
    [[ &quot;$#&quot; -lt &quot;1&quot; ]] &amp;&amp; echo &quot;Usage: $FUNCNAME &quot; 1&gt;&amp;2 &amp;&amp; return 2;
    local i max=$1;
    shift;
    for ((i=1; i &lt;= max ; i++))
    do
        eval &quot;$@&quot;;
    done
}
ascript_title ()
{
    ahave tput &amp;&amp; tput cup 0 3;
    clear;
    lin 0;
    echo -e &quot;| ${CC[${1:-2}]}                ___       __    ___                 __                  ${CC[0]} |&quot;;
    echo -e &quot;| ${CC[${1:-2}]}               / _ | ___ / /__ / _ | ___  ___ _____/ /  ___             ${CC[0]} |&quot;;
    echo -e &quot;| ${CC[${2:-9}]}              / __ |(_-&lt;/  &#039;_// __ |/ _ \/ _ \`/ __/ _ \/ -_)            ${CC[0]} |&quot;;
    echo -e &quot;| ${CC[${2:-9}]}             /_/ |_/___/_/\_\/_/ |_/ .__/\_,_/\__/_//_/\__/             ${CC[0]} |&quot;;
    echo -e &quot;| ${CC[${2:-9}]}                                  /_/                                   ${CC[0]} |&quot;;
    lin 1;
    lin 2 &quot;${USER} &quot;;
    lin 2 &quot;${1:-$AAPN} &quot;;
    lin 2 &quot;Version ${2:-$AAPV} - Built: ${3:-$AAPT} &quot;;
    lin 3
}
asetup_colors ()
{
    create_colors;
    ahave dircolors &amp;&amp; eval &quot;`dircolors -b`&quot;;
    export GREP_COLOR=&#039;
cho $R;
    [[ -r $HOME/.dircolors ]] &amp;&amp; eval &quot;`dircolors $HOME/.dircolors`&quot; || dircolors &#45;-print-database &gt;$HOME/.dircolors;
    local L=&quot;no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:*.tar=01;31:*.tgz=01;31:*.svgz=01;31:*.arj=01;31:*.taz=01;31&quot;;
    L=&quot;${L}:*.lzh=01;31:*.lzma=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31&quot;;
    L=&quot;${L}:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.mng=01;35&quot;;
    L=&quot;${L}:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35&quot;;
    L=&quot;${L}:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.cpio=01;31&quot;;
    export LS_COLORS=&quot;${L}:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.htaccess=01;31:*.htpasswd=01;31:*.htpasswda1=01;31:*config.php=01;31:*wp-config.php=01;31:&quot;
}</pre>
<pre>asetup_history ()
{
    export HISTFILE=${HISTFILE:-$HOME/.bash_history};
    export HISTCONTROL=${HISTCONTROL:-&#039;ignoreboth&#039;};
    export HISTSIZE=500;
    export HISTFILESIZE=500;
    export HISTIGNORE=&#039;clear:ls:ll:updatedb:top:h2:h1:h3:dir:cd ..:date:exit&#039;;
    unset HISTTIMEFORMAT;
    HISTFILEMASTER_DIR=$HOME/backups/.history;
    [[ ! -d &quot;$HISTFILEMASTER_DIR/&quot; ]] &amp;&amp; mkdir -pv $HISTFILEMASTER_DIR;
    [[ ! -r ${HISTFILE} ]] &amp;&amp; history -w $HISTFILE;
    HISTFILEMASTER=${HISTFILEMASTER_DIR}/combined.log;
    [[ ! -f $HISTFILEMASTER ]] &amp;&amp; history -r &amp;&amp; history -w $HISTFILEMASTER &amp;&amp; history -c &amp;&amp; echo &quot;&quot; &gt;$HISTFILE;
    export HISTFILEMASTER;
    HISTFILEMASTER_C=$HISTFILEMASTER_DIR/combined-uniq.log;
    [[ ! -f &quot;$HISTFILEMASTER_C&quot; ]] &amp;&amp; echo &quot;&quot; &gt;$HISTFILEMASTER_C;
    export HISTFILEMASTER_C
}
askapache ()
{
    ascript_title;
    aa_motd;
    aa_weather;
    ahave who &amp;&amp; pm &quot;Users&quot; &amp;&amp; pm &quot;Logged In&quot; 3;
    command who -ar -pld &amp;&amp; pm &quot;Current Limits&quot; 3;
    command ulimit -a;
    pm &quot;Machine stats&quot;;
    ahave uptime &amp;&amp; pm &quot;uptime&quot; 3 &amp;&amp; command uptime;
    [[ -d /proc ]] &amp;&amp; [[ -f /proc/meminfo ]] &amp;&amp; cat /proc/meminfo;
    ahave who &amp;&amp; pm &quot;Users&quot; 3 &amp;&amp; command who;
    pm &quot;Networking&quot;;
    ahave ip &amp;&amp; pm &quot;interfaces&quot; 3 &amp;&amp; ip -o addr | sed -e &#039;s/ \{1,\}/\t/g&#039;;
    [[ -r /proc/net/sockstat ]] &amp;&amp; pm &quot;Sockets&quot; 3 &amp;&amp; head -n 2 /proc/net/sockstat;
    ahave ss &amp;&amp; pm &quot;Networking Stats&quot; 3 &amp;&amp; ss -s;
    ahave netstat &amp;&amp; pm &quot;Routing Information&quot; 3 &amp;&amp; netstat -r;
    pm &quot;Disk&quot;;
    pm &quot;Mounts&quot; 3;
    command df -hai;
    ahave iostat &amp;&amp; pm &quot;I/O on Disks&quot; &amp;&amp; iostat -p ALL;
    pm &quot;Processes&quot;;
    pm &quot;process tree&quot; 3;
    command ps -HAcl -F S -A f | uniq -w3;
    ahave procinfo &amp;&amp; pm &quot;procinfo&quot; 3 &amp;&amp; procinfo | head -n 13 | tail -n 11;
    pm &quot;Functions&quot;;
    aa_functions;
    pm &quot;Aliases&quot;;
    aa_aliases
}
clean_exit ()
{
    lin 0;
    lin 1;
    lin 2 &quot;COMPLETED SUCCESSFULLY&quot;;
    lin 1;
    lin 3
}
cont ()
{
    local ans;
    echo -en &quot;\n\n ${CC[15]}[ ${1:-Press any key to continue} ]$R\n\n&quot;;
    read -n 1 ans;
    aa_beep 1
}
create_colors ()
{
    for i in `seq 0 7`;
    do
        ii=$(($i+7));
        CC[$i]=&quot;\033[1;3${i}m&quot;;
        CC[$ii]=&quot;\033[0;3${i}m&quot;;
    done;
    CC[15]=&quot;\033[30;42m&quot;;
    export R=`tput sgr0`;
    export X=&#039;&#039;;
    export CC
}</pre>
<pre>curl1 ()
{
    command curl -A &#039;Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5&#039; -e -L -H &#039;Accept: */*&#039; &quot;$@&quot;
}
curl2 ()
{
    ( echo &quot;\n\nurl_effective:\t\t%{url_effective}\ncontent_type:\t\t%{content_type}&quot;;
    echo &quot;http_code:\t\t%{http_code}\t\tThe numerical code that was found in the last retrieved HTTPS page&quot;;
    echo &quot;http_connect:\t\t%{http_connect}\t\tThe numerical code that was found in the last response from a proxy to a curl CONNECT request&quot;;
    echo &quot;time_total:\t\t%{time_total}\t\tThe time will be displayed with millisecond resolution&quot;;
    echo &quot;time_namelookup:\t%{time_namelookup}\t\tThe time, in seconds, it took from the start until the name resolving was completed&quot;;
    echo &quot;time_connect:\t\t%{time_connect}\t\tThe time, in seconds, it took from the start until the connect to the remote host or proxy was completed&quot;;
    echo &quot;time_pretransfer:\t%{time_pretransfer}\t\tThe time, in seconds, it took from the start until the file transfer is just about to begin. This includes all pre-transfer commands and negotiations to the particular protocols involved&quot;;
    echo &quot;time_redirect:\t\t%{time_redirect}\t\tThe time, in seconds, it took for all redirection steps. time_redirect shows the complete execution time for multiple redirections&quot;;
    echo &quot;time_starttransfer:\t%{time_starttransfer}\t\tThe time, in seconds, it took from the start until the first byte is just about to be transferred. This includes time_pretransfer and also the time the server needs to calculate the result&quot;;
    echo &quot;size_download:\t\t%{size_download}\t\tThe total amount of bytes that were downloaded&quot;;
    echo &quot;size_upload:\t\t%{size_upload}\t\tThe total amount of bytes that were uploaded&quot;;
    echo &quot;size_header:\t\t%{size_header}\t\tThe total amount of bytes of the downloaded headers&quot;;
    echo &quot;size_request:\t\t%{size_request}\t\tThe total amount of bytes that were sent in the HTTP request&quot;;
    echo &quot;speed_download:\t\t%{speed_download}\tThe average download speed that curl measured for the complete download&quot;;
    echo &quot;speed_upload:\t\t%{speed_upload}\t\tThe average upload speed that curl measured for the complete upload&quot;;
    echo &quot;num_connects:\t\t%{num_connects}\t\tNumber of new connects made in the recent transfer&quot; ) | curl &quot;$@&quot; -w &#039;@-&#039;
}
curl3 ()
{
    ahave curl &amp;&amp; ( curl -A &#039;Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5&#039; -e -L -b ~/.curl_cookie.$$ &#45;-cookie-jar ~/.curl_cookie.$$ -H &#039;Accept: */*&#039; &quot;$@&quot; );
    ahave curl || ( command wget `sed -e &#039;s/^-o /-O /g&#039; -e &#039;s/ -o / -O /g&#039; -e &#039;s/^&#45;-output /&#45;-output-file /g&#039; -e &#039;s/ &#45;-output / &#45;-output-file /g&#039; &lt;&lt;&lt; &quot;$@&quot;` )
}
cuttail ()
{
    [[ &quot;$#&quot; -lt &quot;1&quot; ]] &amp;&amp; echo &quot;Usage: $FUNCNAME &quot; 1&gt;&amp;2 &amp;&amp; return 2;
    sed -n -e :a -e &quot;1,${2:-10}!{P;N;D;};N;ba&quot; $1
}
diffdirs ()
{
    [[ &quot;$#&quot; -gt &quot;0&quot; &amp;&amp; $1 == *-h* ]] &amp;&amp; ahelp $1 &amp;&amp; echo &quot;Usage: $FUNCNAME&quot; &amp;&amp; return 2;
    [[ &quot;$#&quot; -lt &quot;2&quot; ]] &amp;&amp; echo &quot;Usage: $FUNCNAME dir1 dir2&quot; 1&gt;&amp;2 &amp;&amp; return 2;
    ahave colordiff &amp;&amp; colordiff -urp -w $1 $2
}
dirty_exit ()
{
    echo &quot;See ya..&quot;;
    sleep 1;
    exit
}
do_sleep ()
{
    local E D;
    echo -en &quot;${CC[6]}${3:-.}&quot;;
    while `command ps -p $RJ &amp;&gt;$N6`; do
        sleep ${2:-3};
        echo -en &quot;${3:-.}&quot;;
    done;
    echo -e &quot;${CC[0]}&quot; &amp;&amp; sleep 1 &amp;&amp; pd
}
dos2unixx ()
{
    [[ $# -eq 0 ]] &amp;&amp; exec tr -d &#039;\015\032&#039; || [[ ! -f &quot;$1&quot; ]] &amp;&amp; echo &quot;Not found: $1&quot; &amp;&amp; return;
    for f in &quot;$@&quot;;
    do
        [[ ! -f &quot;$f&quot; ]] &amp;&amp; continue;
        tr -d &#039;\015\032&#039; &lt;&quot;$f&quot; &gt;&quot;$f.t&quot; &amp;&amp; cmp &quot;$f&quot; &quot;$f.t&quot; &gt;$N6 &amp;&amp; rm -f &quot;$f.t&quot; || ( touch -r &quot;$f&quot; &quot;$f.t&quot; &amp;&amp; mv &quot;$f&quot; &quot;$f.b&quot; &amp;&amp; mv &quot;$f.t&quot; &quot;$f&quot; &amp;&amp; rm -f &quot;$f.b&quot; ) &gt;&amp;$N6;
    done
}
dump_ps_environment ()
{
    command ps aux | command grep ${USER:0:3} | command awk &#039;{print $2}&#039; | xargs -t -ipid /bin/sh -c &#039;test -r /proc/pid/environ &amp;&amp; cat /proc/pid/environ | tr &quot;\000&quot; &quot; &quot;&#039;
}
ex ()
{
    [[ &quot;$#&quot; -gt &quot;0&quot; &amp;&amp; $1 == *-h* ]] &amp;&amp; ahelp $1 &amp;&amp; echo &quot;Usage: $FUNCNAME&quot; &amp;&amp; return 2;
    until [[ -z &quot;$1&quot; ]]; do
        if [[ -f &quot;$1&quot; ]]; then
            pm &quot;Extracting $1 &#46;..&quot;;
            case $1 in
                *.tar.bz2)
                    tar xjf $1
                ;;
                *.tar.gz)
                    tar xzf $1
                ;;
                *.tar)
                    tar xf $1
                ;;
                *.tbz2)
                    tar xjf $1
                ;;
                *.tgz)
                    tar xzf $1
                ;;
                *.bz2)
                    bunzip2 $1
                ;;
                *.rar)
                    unrar x $1
                ;;
                *.gz)
                    gunzip $1
                ;;
                *.zip)
                    unzip $1
                ;;
                *.Z)
                    uncompress $1
                ;;
                *.7z)
                    7z x $1
                ;;
                *)
                    pm &quot;Don&#039;t know how to extract &#039;$1&#039;&quot;
                ;;
            esac;
        else
            pm &quot;&#039;$1&#039; is not a valid file&quot;;
        fi;
        shift;
    done
}
exitall ()
{
    aa_savehist;
    pkill -9 -t &quot;${SSH_TTY/\/dev\/}&quot;
}
figtest ()
{
    [[ &quot;$#&quot; -gt &quot;0&quot; &amp;&amp; $1 == *-h* ]] &amp;&amp; ahelp $1 &amp;&amp; echo &quot;Usage: $FUNCNAME word&quot; &amp;&amp; return 2;
    for a in /usr/share/figlet/*.flf;
    do
        r=`basename ${a%%.flf}`;
        echo -e &quot;${r}&quot;;
        figlet -t -f &quot;$r&quot; &quot;$1&quot;;
    done
}
find_symlinks ()
{
    local O=$IFS;
    IFS=&#039;&#039;;
    for file in &quot;$( find ${1:-`pwd`} -type l )&quot;;
    do
        echo &quot;$file&quot;;
    done | sort
}
get_crypt_user ()
{
    ahave gpg || return;
    local U=`gpg &#45;-list-keys|sed -e &#039;/^uid /!d&#039; -e &#039;s/^uid[ ]*\(.*\)/\1/g&#039;` || unknown;
    [[ $# -ne 0 ]] &amp;&amp; U=${U//\&lt;*};
    echo -n $U
}
get_latest_revision ()
{
    local URL=${1:-http://svn.automattic.com/wordpress/trunk};
    svn info $URL | grep ^Rev | sed -e &#039;s/Revision: \([0-9]*\)/\1/g&#039;
}
grepc ()
{
    [[ &quot;$#&quot; -gt &quot;0&quot; &amp;&amp; $1 == *-h* ]] &amp;&amp; ahelp $1 &amp;&amp; echo &quot;Usage: $FUNCNAME&quot; &amp;&amp; return 2;
    command grep &#45;-color=always &quot;$@&quot;
}
grepp ()
{
    [[ &quot;$#&quot; -gt &quot;0&quot; &amp;&amp; $1 == *-h* ]] &amp;&amp; ahelp $1 &amp;&amp; echo &quot;Usage: $FUNCNAME&quot; &amp;&amp; return 2;
    command grep -i &#45;-color=always &quot;$@&quot; -r .
}</pre>
<pre>h2 ()
{
    [[ &quot;$#&quot; -lt &quot;1&quot; ]] &amp;&amp; echo &quot;Usage: $FUNCNAME query&quot; 1&gt;&amp;2 &amp;&amp; return 2;
    command grep -h &quot;$@&quot; $HISTFILEMASTER_C
}
h2c ()
{
    [[ &quot;$#&quot; -lt &quot;1&quot; ]] &amp;&amp; echo &quot;Usage: $FUNCNAME query&quot; 1&gt;&amp;2 &amp;&amp; return 2;
    command grep &#45;-color=always -h &quot;$@&quot; $HISTFILEMASTER_C
}
h2i ()
{
    [[ &quot;$#&quot; -lt &quot;1&quot; ]] &amp;&amp; echo &quot;Usage: $FUNCNAME query&quot; 1&gt;&amp;2 &amp;&amp; return 2;
    command grep -h -i &quot;$@&quot; $HISTFILEMASTER_C
}
histfilemaster ()
{
    set -vx;
    history -a;
    [[ &quot;`wc -l &lt; $HISTFILE`&quot; -gt &quot;$HISTSIZE&quot; ]] &amp;&amp; ( cat $HISTFILE &gt;&gt;$HISTFILEMASTER;
    cat $HISTFILE &gt;`date +$HISTFILEMASTER_DIR/%m-%d-%y.history`;
    cat $HISTFILE $HISTFILEMASTER_C | sort | uniq &gt;$HISTFILEMASTER_DIR/hc.tmp;
    [[ &quot;`wc -l &lt; $HISTFILEMASTER_DIR/hc.tmp`&quot; -gt &quot;`wc -l &lt; $HISTFILEMASTER_C`&quot; ]] &amp;&amp; mv $HISTFILEMASTER_DIR/hc.tmp $HISTFILEMASTER_C || cat $HISTFILE &gt;&gt;$HISTFILEMASTER_C;
    echo &quot;&quot; &gt;$HISTFILE );
    set +vx
}
kill_jobs ()
{
    for i in `command jobs -p`;
    do
        kill -9 $i;
    done
}
l ()
{
    command ls -AhFp $AAC &quot;$@&quot;
}
la ()
{
    command du -kh * | awk &#039;{print $2,$1}&#039; | sort -n | tr &#039; &#039; &quot;\t&quot;
}
lin ()
{
    local L2 L1=&#039;__________________________________________________________________________&#039;;
    case ${1:-1} in
        0)
            echo -e &quot;\n ${CC[0]}${L1}&quot;
        ;;
        1)
            L2=`echo &#039;                                                                          &#039;`;
            echo -e &quot;${CC[0]}|${CC[34]}${L2}${CC[0]}|&quot;
        ;;
        2)
            echo -en &quot;${CC[0]}|${CC[34]}&quot;;
            echo -en &quot;${2:-1}&quot; | sed -e :a -e &#039;s/^.\{1,72\}$/ &amp; /;ta&#039; -e &quot;s/\(.*\)/\1/&quot;;
            echo -e &quot;${CC[0]} |&quot;
        ;;
        3)
            echo -e &quot;${CC[0]} ${L1} $R$X\n\n&quot;
        ;;
    esac
}
ll ()
{
    command ls -lABls1c $AAC &quot;$@&quot;
}
locate1 ()
{
    [[ &quot;$#&quot; -gt &quot;0&quot; &amp;&amp; $1 == *-h* ]] &amp;&amp; ahelp $1 &amp;&amp; echo &quot;Usage: $FUNCNAME&quot; &amp;&amp; return 2;
    [[ &quot;$#&quot; -lt &quot;1&quot; ]] &amp;&amp; echo &quot;Usage: $FUNCNAME &quot; 1&gt;&amp;2 &amp;&amp; return 2;
    command locate &quot;$@&quot; | xargs -iFF stat -c %a\ %A\ \ A\ %x\ \ M\ %y\ \ C\ %z\ \ %N FF
}
make_ionice ()
{
    ahave ionice || return;
    local theclass thenicelevel thepid;
    thepid=${1:-$$};
    theclass=${2:-3};
    thenicelevel=${3:-7};
    pm &quot;Making IONice class: $theclass, nicelevel: $thenicelevel, process: $thepid&quot;;
    pm 0 0;
    command ionice -c$theclass -n$thenicelevel -p $thepid;
    pd
}
make_nice ()
{
    ahave renice || return;
    local thenicelevel thepid;
    thepid=${1:-$$};
    thenicelevel=${2:-19};
    pm &quot;Making process $thepid $thenicelevel nice.&quot;;
    pm 0 0;
    command renice $thenicelevel -p $theppid;
    pd
}
nh ()
{
    [[ &quot;$#&quot; -lt &quot;1&quot; ]] &amp;&amp; echo &quot;Usage: $FUNCNAME &lt;command&gt;&quot; 1&gt;&amp;2 &amp;&amp; return 2;
    nohup &quot;$@&quot; &gt;&amp;$N6 &amp; echo
}
nicest ()
{
    [[ &quot;$#&quot; -gt &quot;0&quot; &amp;&amp; $1 == *-h* ]] &amp;&amp; ahelp $1 &amp;&amp; echo &quot;Usage: $FUNCNAME&quot; &amp;&amp; return 2;
    local ncmd icmd=&#039;&#039;;
    ahave ionice &amp;&amp; icmd=&#039;ionice -c3 -n7&#039;;
    ahave nice &amp;&amp; ncmd=&#039;nice -n 19&#039;;
    $icmd $ncmd &quot;$@&quot;;
    ahave ionice
}
nob ()
{
    [[ $# -eq 0 ]] &amp;&amp; exec grep -v ^$ | sed -e &#039;/[^ \t]\{1,\}/!d&#039;
}
nobb ()
{
    [[ $# -eq 0 ]] &amp;&amp; exec sed -e &#039;s/^[ \t]*//;s/[ \t]*$//&#039; -e &#039;/[^ \t]\{1,\}/!d&#039;
}
nobl ()
{
    [[ $# -eq 0 ]] &amp;&amp; exec sed -e &#039;s/^[ \t]*//&#039;
}
nobt ()
{
    [[ $# -eq 0 ]] &amp;&amp; exec sed -e &#039;s/[ \t]*$//&#039;
}
pd ()
{
    echo -e &quot;\n ${CC[15]} ${1:-DONE} $R\n\n&quot;
}
pm ()
{
    [[ &quot;$#&quot; -lt &quot;1&quot; ]] &amp;&amp; echo &quot;Usage: $FUNCNAME &quot; 1&gt;&amp;2 &amp;&amp; return 2;
    local I=${1:-3};
    echo -en &quot;$R\n&quot;;
    case ${2:-1} in
        0)
            echo -en &quot;${CC[6]}&#45;- $X$R&quot;
        ;;
        1)
            echo -e &quot;${CC[2]}&gt;&gt;&gt; $X$I$R&quot;
        ;;
        2)
            echo -en &quot;${CC[4]} &gt; $X$I$R&quot;
        ;;
        3)
            echo -e &quot;${CC[4]} :: $X$I$R&quot;
        ;;
    esac
}
print_ascii_chart ()
{
    for i in `seq 0 256`;
    do
        echo -e &quot;\\0$(( $i/64*100 + $i%64/8*10 + $i%8 ))&quot;;
    done
}
procinfo1 ()
{
    PI=($(strace -s1 procinfo -a 2&gt;&amp;1|sed -e &#039;/^op/!d&#039; -e &#039;/pro/!d&#039; -e &#039;/= -1/d&#039;|sed -e &#039;s%o.*&quot;/proc/\(.*\)&quot;.*% \1%g&#039;));
    for i in ${PI[*]};
    do
        echo -e &quot;\n&#45;&#45;-===[  /proc/$i  ]\n&quot; &amp;&amp; cat /proc/$i &amp;&amp; echo -e &quot;\n\n&quot;;
    done
}
ps ()
{
    [[ -z &quot;$1&quot; ]] &amp;&amp; command ps -Hacl -F S -A f &amp;&amp; return;
    command ps &quot;$@&quot;
}
pss ()
{
    local U PPS PL PX PXX UUS=($(command ps uax|awk &#039;{print $1}&#039;|command tail -n +2|sort|uniq));
    UL=$((${#UUS[@]} - 1));
    exec 6&gt;&amp;1;
    exec &gt;~/proc.$$;
    ps aux | grep ${USER:0:3} | awk &#039;{print $2}&#039; | xargs -t -ipid cat /proc/pid/environ;
    for UX in $(seq 0 1 $UUS);
    do
        U=${UUS[$UX]};
        PPS=($(pgrep -u ${U}));
        PL=$((${#PPS[@]} - 1));
        for PX in $(seq 0 1 $PL);
        do
            PXX=${PPS[$PX]};
            echo -e &quot;\n\n\n&#45;&#45;&#45;&#45;- PROCESS ID: ${PXX} &#45;&#45;&#45;&#45;-\n\n&quot;;
            cat /proc/${PXX}/cmdline 2&gt;$N6 || echo;
            echo -e &quot;\n\n&quot;;
            command tree -Csuflapi /proc/Q/${PXX};
        done;
    done;
    exec 1&gt;&amp;6 6&gt;&amp;-;
    cat ~/proc.$$ | more
}
psu ()
{
    command ps -Hcl -F S f -u ${1:-$USER}
}
pwd ()
{
    command pwd -LP &quot;$@&quot;
}
rmb ()
{
    [[ &quot;$#&quot; -lt &quot;1&quot; ]] &amp;&amp; echo &quot;Usage: $FUNCNAME dirnametoremove&quot; 1&gt;&amp;2 &amp;&amp; return 2;
    ( ( command rm -rf &quot;$@&quot; &gt;&amp;$N6 ) &amp; )
}
set_window_title ()
{
    [[ &quot;$#&quot; -lt &quot;1&quot; ]] &amp;&amp; echo &quot;Usage: $FUNCNAME &quot; 1&gt;&amp;2 &amp;&amp; return 2;
    echo -n -e &quot;\033]0;$*\007&quot;
}
sleeper ()
{
    [[ &quot;$#&quot; -lt &quot;1&quot; ]] &amp;&amp; echo &quot;Usage: $FUNCNAME &lt;process id&gt;&quot; 1&gt;&amp;2 &amp;&amp; return 2;
    echo -en &quot;\n${2:-.}&quot;;
    while `command ps -p $1 &amp;&gt;$N6`; do
        echo -n &quot;${2:-.}&quot;;
        sleep ${3:-1};
    done;
    echo
}
stat1 ()
{
    local D=${1:-$PWD/*};
    stat -c %a\ %A\ \ A\ %x\ \ M\ %y\ \ C\ %z\ \ %N ${D} | sed -e &#039;s/ [0-9:]\{8\}\.[0-9]\{9\} -[0-9]\+//g&#039; | tr -d &quot;\`\&#039;&quot; | sort -r
}
stat2 ()
{
    local D=${1:-$PWD/*};
    stat -c %a\ %A\ \ A\ %x\ \ M\ %y\ \ C\ %z\ \ %N ${D} | sed -e &#039;s/\.[0-9]\{9\} -[0-9]\+//g&#039; | tr -d &quot;\`\&#039;&quot; | sort -r
}
tard ()
{
    [[ &quot;$#&quot; -lt &quot;2&quot; ]] &amp;&amp; echo &quot;Usage: $FUNCNAME dest-file (auto adds tgz&quot; 1&gt;&amp;2 &amp;&amp; return 2;
    yn &quot;Tarring $2 to $1&quot; &amp;&amp; ( ( command tar -zcpf &quot;$1&quot; &quot;$2&quot; &gt;&amp;$N6 ) &amp; )
}
test_colors ()
{
    echo -e &quot;$R&quot;;
    ahave tput &amp;&amp; tput sgr0;
    for ((i=0; i&lt;=${#CC[@]} - 1; i++))
    do
        echo -e &quot;${CC[$i]}[$i]\n$R&quot;;
    done
}
uniq2 ()
{
    [[ -f &quot;$1&quot; ]] &amp;&amp; sed = $1 | sed -n &#039;G; s/\n/&amp;&amp;/; /^\([ -~]*\n\).*\n\1/d; s/\n//; h; P&#039;
}
uniqf ()
{
    [[ &quot;$#&quot; -lt &quot;1&quot; ]] &amp;&amp; echo &quot;Usage: $FUNCNAME &quot; 1&gt;&amp;2 &amp;&amp; return 2;
    awk &#039;!($0 in a) {a[$0];print}&#039; &quot;$1&quot;
}
uptime1 ()
{
    command uptime | sed &#039;/.*,  \([0-9]*\) users,  load average: \(.*\)/!d; s//[ \2, \1 users ]/;q&#039;
}
vless ()
{
    [[ $# -eq 0 ]] &amp;&amp; command vim &#45;-cmd &#039;let no_plugin_maps = 1&#039; -c &#039;runtime! macros/less.vim&#039; -;
    [[ $# -eq 0 ]] || command vim &#45;-cmd &#039;let no_plugin_maps = 1&#039; -c &#039;runtime! macros/less.vim&#039; &quot;$@&quot;
}
wcdir ()
{
    [[ &quot;$#&quot; -gt &quot;0&quot; &amp;&amp; $1 == *-h* ]] &amp;&amp; ahelp $1 &amp;&amp; echo &quot;Usage: $FUNCNAME&quot; &amp;&amp; return 2;
    find ${1:-.} -mindepth 1 -type d -print0 | xargs -0 -iFF sh -c &#039;echo `find &quot;FF&quot;/ -type f 2&gt;/dev/null|wc -l;echo &quot;FF&quot;`&#039; | sort -n | sed -e &#039;s/^\([0-9]*\) \(.*\)$/ \1\t\2/g&#039;
}
yes_no ()
{
    [[ &quot;$#&quot; -lt &quot;1&quot; ]] &amp;&amp; echo &quot;Usage: $FUNCNAME Question&quot; 1&gt;&amp;2 &amp;&amp; return 2;
    local a YN=65;
    echo -en &quot;${1:-Answer} [Y/n] ?&quot;;
    read -n 1 a;
    case $a in
        [yY])
            YN=0
        ;;
    esac;
    return $YN
}
yn ()
{
    [[ &quot;$#&quot; -lt &quot;1&quot; ]] &amp;&amp; echo &quot;Usage: $FUNCNAME &quot; 1&gt;&amp;2 &amp;&amp; return 2;
    local a YN=65;
    echo -en &quot;\n ${CC[6]}@@ ${1:-Q} $R$X[y/N] ?$R&quot;;
    read -n 1 a;
    echo;
    case $a in
        [yY])
            echo -n &quot;Y&quot;;
            YN=0
        ;;
        *)
            echo -n &quot;N&quot;
        ;;
    esac;
    return $YN
}</pre>
<p><a href="http://uploads.askapache.com/2009/08/askapache-bash_profile.png"><!-- IMAGE REMOVED BY wp-image-resizer HERE --></a></p>
<div class='presskit'><h3>High Resolution Press Images:</h3>[+] <a href='http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?src=http://uploads.askapache.com/2009/08/askapache-bash_profile.png&down=true'>askapache-bash_profile.png</a><br /></div><p><a href="http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html"></a><a href="http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html">Custom bash_profile for Advanced Shell Users</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Protecting Files with Advanced Mod_Rewrite Anti-Hotlinking</title>
		<link>http://www.askapache.com/htaccess/anti-hotlinking-mod_rewrite.html</link>
		<comments>http://www.askapache.com/htaccess/anti-hotlinking-mod_rewrite.html#comments</comments>
		<pubDate>Wed, 16 Sep 2009 05:09:11 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Apache Modules]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Linux Unix BSD]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Webmaster]]></category>
		<category><![CDATA[Advanced]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[Blocking]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[hotlinking]]></category>
		<category><![CDATA[htaccess tutorial]]></category>
		<category><![CDATA[HTTP Headers]]></category>
		<category><![CDATA[Mod_Rewrite]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[Rewrite Tricks]]></category>
		<category><![CDATA[rewritecond]]></category>
		<category><![CDATA[rewriterule]]></category>
		<category><![CDATA[Robot]]></category>
		<category><![CDATA[robots]]></category>
		<category><![CDATA[robots.txt]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[stat]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=3287</guid>
		<description><![CDATA[<p><a class="IFL" id="id17" href="http://www.askapache.com/htaccess/anti-hotlinking-mod_rewrite.html"></a>If you have files on your site that you don't want indexed by malicious search engines, grabbed and leeched by malicious spammers, or stolen and made available elsewhere, you can use mod_rewrite to drastically reduce or totally reduce that activity.<br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<div class='images'></div><p><a class="IFL" id="id17" href="http://uploads.askapache.com/2009/09/866310_predestrian_lights.jpg"></a><br style="padding-top:2em;" /><br />If you have files on your site that you don&#8217;t want indexed by malicious search engines, grabbed and leeched by malicious spammers, or stolen and made available elsewhere, you can use mod_rewrite to drastically reduce or totally reduce that activity.</p>
<h2>The Worst Kind of People</h2>
<p><strong>Spammers, and Leechers</strong>.  They operate like this:  Let&#8217;s say you have some mp3 files on a server, and SOMEWHERE on the web there is a link to that mp3 file&#8217;s location.  This includes in javascript files, css files, robots.txt files, the spammers and leechers robots check all those files looking for the type of link they are looking for.   Then they try to request that file usually utilizing a number of different types of requests to get access to the file.  Then they use it for personal gain, at your peril.</p>
<p>Some robots perform valuable services for the world wide web community, and other leeching programming is pretty cool, so not all these activities are perpetrated by nefarious spammers.</p>
<p><br class="C" /></p>
<h2>Blocking by IP COOKIE</h2>
<p>Ok so if a link exists to your file, it is going to be requested by a robot eventually, so the way to defeat them is by doing something on your site that modifies the way a user would request it.  Robots for the most part are not javascript-capable, so the most-common advanced method is to set a cookie using javascript, and then we can check for that cookie in the request for the file using mod_rewrite.</p>
<p>So if your site sets a cookie named fspammers, and furthermore gives that cookie a value of 445, then this is what the request sent by an HTTP Client like Firefox looks like.</p>
<pre>GET /hotlink/lovefreedom.mp3 HTTP/1.1
Host: static.askapache.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)
Accept: image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.askapache.com/wordpress/seo-in-wordpress.html
Cookie: fspammers=455</pre>
<h2>Mod_Rewrite HTTP Headers</h2>
<p>The mod_rewrite module has access to ALL the HTTP Headers sent in a request, so for each of the HTTP Headers in the request example above, we can use mod_rewrite to validate.</p>
<h2>Mod_Rewrite .htaccess Example</h2>
<p>Finally, now that everyone is on the same page about what is really going on, here is the <a href="http://www.askapache.com/htaccess/htaccess.html" title=".htaccess tutorial">.htaccess</a> code that blocks any requests for anything in the /hotlink/ folder.</p>
<p>Here are the triggers this code blocks access based on.</p>
<ol>
<li><strong>Cookie</strong>: Checks if fspammers cookie is present, and that it has the value of 445. </li>
<li><strong>HTTP Protocol</strong>: Checks if HTTP 1.1 is being used (many robots use 1.0)</li>
<li><strong>Host</strong>: Checks that the HOST Requested was static.askapache.com</li>
<li><strong>Referer</strong>:  Checks for Referring site is static.askapache.com or www.askapache.com</li>
</ol>
<pre>RewriteEngine On
RewriteBase /
&nbsp;
RewriteCond %{HTTP_COOKIE} !^.*fspammers=445.*$ [NC,OR]
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ /(.*)\ HTTP/1\.1 [NC,OR]
RewriteCond %{HTTP_HOST} !^z\.askapache\.com$ [NC,OR]
RewriteCond %{HTTP_REFERER} !^http://(www|z)\.askapache\.com.*$ [NC]
RewriteRule ^hotlink/.*$ - [F]&lt;/p&gt;</pre>
<p><a href="http://www.askapache.com/htaccess/anti-hotlinking-mod_rewrite.html"></a><a href="http://www.askapache.com/htaccess/anti-hotlinking-mod_rewrite.html">Protecting Files with Advanced Mod_Rewrite Anti-Hotlinking</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/anti-hotlinking-mod_rewrite.html/feed/</wfw:commentRss>
		<slash:comments>1</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[Apache]]></category>
		<category><![CDATA[Apache Modules]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[DreamHost]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[Linux Unix BSD]]></category>
		<category><![CDATA[Mod_Rewrite]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[Web Tools]]></category>
		<category><![CDATA[Webmaster]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[.htaccess examples]]></category>
		<category><![CDATA[301 Redirect]]></category>
		<category><![CDATA[302 Redirect]]></category>
		<category><![CDATA[401]]></category>
		<category><![CDATA[403 Forbidden]]></category>
		<category><![CDATA[404 Not Found]]></category>
		<category><![CDATA[500]]></category>
		<category><![CDATA[503]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[Advanced]]></category>
		<category><![CDATA[Apache Htaccess]]></category>
		<category><![CDATA[apache ssl]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[ASP]]></category>
		<category><![CDATA[authorization]]></category>
		<category><![CDATA[Backups]]></category>
		<category><![CDATA[Bandwidth]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Blocking]]></category>
		<category><![CDATA[Boot]]></category>
		<category><![CDATA[Cache-Control]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[cheatsheet]]></category>
		<category><![CDATA[chmod]]></category>
		<category><![CDATA[code snippets]]></category>
		<category><![CDATA[compression]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[error log]]></category>
		<category><![CDATA[errordocument]]></category>
		<category><![CDATA[Etags]]></category>
		<category><![CDATA[Examples]]></category>
		<category><![CDATA[experiments]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[FeedBurner]]></category>
		<category><![CDATA[File System]]></category>
		<category><![CDATA[FilesMatch]]></category>
		<category><![CDATA[filesystem]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Forms]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[hotlinking]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[htaccess files]]></category>
		<category><![CDATA[htaccess guide]]></category>
		<category><![CDATA[htaccess rewrite]]></category>
		<category><![CDATA[htaccess tricks]]></category>
		<category><![CDATA[htaccess tutorial]]></category>
		<category><![CDATA[Htpasswd]]></category>
		<category><![CDATA[HTTP Error]]></category>
		<category><![CDATA[HTTP Headers]]></category>
		<category><![CDATA[HTTP-EQUIV]]></category>
		<category><![CDATA[httpd]]></category>
		<category><![CDATA[httpd.conf]]></category>
		<category><![CDATA[HTTPS SSL]]></category>
		<category><![CDATA[hyper text transfer protocol]]></category>
		<category><![CDATA[If-Modified-Since]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Last-Modified]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Login]]></category>
		<category><![CDATA[Logs]]></category>
		<category><![CDATA[mad skills]]></category>
		<category><![CDATA[mod_include]]></category>
		<category><![CDATA[mod_python]]></category>
		<category><![CDATA[Mod_Rewrite examples]]></category>
		<category><![CDATA[Mod_Security]]></category>
		<category><![CDATA[Mod_Setenvif]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Nice]]></category>
		<category><![CDATA[nsa]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[password protection]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php.ini]]></category>
		<category><![CDATA[phpinfo]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[Powweb]]></category>
		<category><![CDATA[Prompt]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[Redirect]]></category>
		<category><![CDATA[Redirection]]></category>
		<category><![CDATA[Request Method]]></category>
		<category><![CDATA[Rewrite Tricks]]></category>
		<category><![CDATA[rewritecond]]></category>
		<category><![CDATA[rewriterule]]></category>
		<category><![CDATA[Robot]]></category>
		<category><![CDATA[robots]]></category>
		<category><![CDATA[Sample .htaccess]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[seo secrets]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[server config]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[SetEnvIf]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Socket]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[SPEED]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[stat]]></category>
		<category><![CDATA[SymLinks]]></category>
		<category><![CDATA[trick]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[ultimate htaccess]]></category>
		<category><![CDATA[Username]]></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[<div class='images'><a href='http://uploads.askapache.com/2008/08/htaccess-up.png'><img src="http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?fltr=usm&src=http://uploads.askapache.com/2008/08/htaccess-up.png&w=400" title=" apache" alt="The Ultimate Htaccess" /></a><a href='http://uploads.askapache.com/2009/01/htaccess-explorer.png'><img src="http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?fltr=usm&src=http://uploads.askapache.com/2009/01/htaccess-explorer.png&w=400" title=" apache" alt="The Ultimate Htaccess" /></a><a href='http://uploads.askapache.com/2009/01/viewing-htaccess-files.png'><img src="http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?fltr=usm&src=http://uploads.askapache.com/2009/01/viewing-htaccess-files.png&w=400" title=" apache" alt="The Ultimate Htaccess" /></a><a href='http://uploads.askapache.com/2008/08/htaccess-up1-350x178.png'><img src="http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?fltr=usm&src=http://uploads.askapache.com/2008/08/htaccess-up1-350x178.png&w=400" title=" apache" alt="The Ultimate Htaccess" /></a><a href='http://uploads.askapache.com/2008/01/jail-bars-1.png'><img src="http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?fltr=usm&src=http://uploads.askapache.com/2008/01/jail-bars-1.png&w=400" title=" apache" alt="The Ultimate Htaccess" /></a><a href='http://uploads.askapache.com/2007/10/cookies.png'><img src="http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?fltr=usm&src=http://uploads.askapache.com/2007/10/cookies.png&w=400" title=" apache" alt="The Ultimate Htaccess" /></a><a href='http://uploads.askapache.com/2008/04/bad_robot1.png'><img src="http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?fltr=usm&src=http://uploads.askapache.com/2008/04/bad_robot1.png&w=400" title=" apache" alt="The Ultimate Htaccess" /></a></div><p><strong><dfn title="HyperText Access">.htaccess</dfn></strong> 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 is sometimes called:  &#8220;HyperText Access&#8221; because of its ability to control access of the <acronym title="World Wide Web">WWW</acronym>&#8216;s HyperText Transfer Protocol (<acronym title="HyperText Transfer Protocol">HTTP</acronym>) using Password Protection, 301 Redirects, 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 built for HTTP.  Eventually these Web Servers (configured with htaccess) became known as the World Wide Web, and eventually grew into the Internet we know today.</p>
<p><a class="IFL" href="/htaccess/htaccess.html"><!-- IMAGE REMOVED BY wp-image-resizer HERE --></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.</p>
<p>You&#8217;ve come to the right place if you are looking to acquire <strong>mad skills</strong> for using .htaccess files.</p>
<p>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>
<h3>AskApache Htaccess Journey</h3>
<p><strong>Skip this &#8211; 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 &#8220;share&#8221; 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&#8217;t use .htaccess much, if AT ALL.  It&#8217;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&#8217;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&#8217;s almost as powerful as httpd.conf itself!</p>
<p>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&#8217;s common to see &#8220;computer gurus&#8221; 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 &#8211; I wonder if these &#8220;gurus&#8221; know the history of the htaccess file, like it&#8217;s use in the earliest versions of the HTTP Server- NCSA&#8217;s HTTPd, which BTW, became known as Apache HTTP.  So you could easily say that htaccess files predates Apache itself.</p>
<p>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&#8217;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>
<div style="margin-left:2em;">
<p><a id="htaccess-toc" title="Htaccess - Table of Contents"></a></p>
<h2>Table of Contents</h2>
<ol class="TOC">
<li><a href="#htaccess-evolution" title="Evolution of Htaccess">Evolution of Htaccess</a></li>
<li><a href="#httpd-config-examples" title="Server Config (httpd.conf) Examples">Server Config (httpd.conf) Examples</a></li>
<li><a href="#htaccess-example-files" title="Example .htaccess Files"><strong>Example .htaccess Files</strong></a></li>
<li><a href="#htaccess-code-examples" title="Example .htaccess Code Snippets"><strong>Example .htaccess Code Snippets</strong></a></li>
<li><a href="#mod_rewrite-examples" title="Example mod_rewrite code and tricks"><strong>NEW: Advanced Mod_Rewrite Tricks</strong></a></li>
<li><a href="#best-htaccess-articles" title="Best AskApache .htaccess Articles">Best AskApache .htaccess Articles</a></li>
<li><a href="#favorite-htaccess" title="Favorite .htaccess Links">Favorite .htaccess Links</a></li>
<li><a href="#htaccess-directives-list" title="Master List of .htaccess Directives">Master List of .htaccess Directives</a></li>
<li><a href="#htaccess-modules" title="Htaccess Modules List">Htaccess Modules List</a></li>
</ol>
</div>
<p><a id="htaccess-evolution" title="Htaccess - Evolved"></a></p>
<h2>Htaccess &#8211; 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 &#8220;server farms&#8221; where many hundreds and thousands of web hosting customers are all put on the same Apache Server.  This type of hosting is called &#8220;virtual hosting&#8221; 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&#8217;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 &#8212; 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&#8217;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&#8217;s own config files (either from the <Directory> sections in access.conf, or from defaults in srm.conf, which actually behaves for most purposes almost exactly like <code><Directory /></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>Creating Htaccess Files</h4>
<p><a class="IFL" href="http://uploads.askapache.com/2009/01/htaccess-explorer.png"><!-- IMAGE REMOVED BY wp-image-resizer HERE --></a>Htaccess files use the default filename &#8220;<code>.htaccess</code>&#8221; 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&#8217;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"><!-- IMAGE REMOVED BY wp-image-resizer HERE --></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&#8217;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&#8217;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&#8217;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&#8217;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&#8217;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"><!-- IMAGE REMOVED BY wp-image-resizer HERE --></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 &#8212; 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&#8217;s performance, comparing to Apache&#8217;s 40% drop in performance. </p>
<p><a id="httpd-config-examples"></a></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 &quot;GZIP compressed document&quot; .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" />
<p><a id="htaccess-example-files"></a></p>
<h2>Example .htaccess Files</h2>
<p>Here are some samples and examples taken from different .htaccess files I&#8217;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 &quot;None&quot;, &quot;All&quot;, 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 &quot;handlers&quot;:
# 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 &quot;ExecCGI&quot; to the &quot;Options&quot; 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 &quot;EMail&quot; 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 &quot;\.(flv|gif|jpg|jpeg|png|ico)$&quot;&gt;
Header set Cache-Control &quot;max-age=2592000&quot;
&lt;/FilesMatch&gt;
&lt;FilesMatch &quot;\.(js|css|pdf|swf)$&quot;&gt;
Header set Cache-Control &quot;max-age=604800&quot;
&lt;/FilesMatch&gt;
&lt;FilesMatch &quot;\.(html|htm|txt)$&quot;&gt;
Header set Cache-Control &quot;max-age=600&quot;
&lt;/FilesMatch&gt;
&lt;FilesMatch &quot;\.(pl|php|cgi|spl|scgi|fcgi)$&quot;&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 &quot;\.(pl|php|cgi|spl|scgi|fcgi)$&quot;&gt;
ExpiresActive Off
&lt;/FilesMatch&gt;
## META HTTP-EQUIV REPLACEMENTS
&lt;FilesMatch &quot;\.(html|htm|php)$&quot;&gt;
Header set imagetoolbar &quot;no&quot;
&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 &quot;prompt&quot;
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 &quot;\.(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$&quot;&gt;
Order Allow,Deny
Deny from all
&lt;/FilesMatch&gt;
## PREVENT HOTLINKING
SetEnvIfNoCase Referer &quot;^http://subdomain.askapache.com/&quot; good
SetEnvIfNoCase Referer &quot;^$&quot; good
&lt;FilesMatch &quot;\.(png|jpg|jpeg|gif|bmp|swf|flv)$&quot;&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 &quot;askapache.com&quot;
ErrorDocument 403 https://askapache.com
## COMBINED DEVELOPER HTACCESS CODE-USE THIS
&lt;FilesMatch &quot;\.(flv|gif|jpg|jpeg|png|ico|js|css|pdf|swf|html|htm|txt)$&quot;&gt;
Header set Cache-Control &quot;max-age=5&quot;
&lt;/FilesMatch&gt;
AuthType basic
AuthName &quot;Ooops! Temporarily Under Construction&#46;..&quot;
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 &quot;\.(flv|gif|jpg|jpeg|png|ico|js|css|pdf|swf|html|htm|txt)$&quot;&gt;
Header set Cache-Control &quot;max-age=5&quot;
&lt;/FilesMatch&gt;
## ALLOW ACCESS WITH PASSWORD OR NO PASSWORD FOR SPECIFIC IP/HOSTS
AuthType basic
AuthName &quot;Ooops! Temporarily Under Construction&#46;..&quot;
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" />
<p><a id="htaccess-code-examples"></a></p>
<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 &quot;Under Development&quot;
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 &quot;askapache.com&quot;
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 &#8220;File Save As&#8221; 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 &quot;^php5?\.(ini|cgi)$&quot;&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 &quot;language=%{lang}e; path=/;&quot; 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 &quot;\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$&quot;&gt;
Header set Cache-Control &quot;public&quot;
Header set Expires &quot;Thu, 15 Apr 2010 20:00:00 GMT&quot;
Header unset Last-Modified
&lt;/FilesMatch&gt;
#2 hours
&lt;FilesMatch &quot;\.(html|htm|xml|txt|xsl)$&quot;&gt;
Header set Cache-Control &quot;max-age=7200, must-revalidate&quot;
&lt;/FilesMatch&gt;
&lt;FilesMatch &quot;\.(js|css)$&quot;&gt;
SetOutputFilter DEFLATE
Header set Expires &quot;Thu, 15 Apr 2010 20:00:00 GMT&quot;
&lt;/FilesMatch&gt;</pre>
<h4>Password Protect single file</h4>
<pre>&lt;Files login.php&gt;
AuthName &quot;Prompt&quot;
AuthType Basic
AuthUserFile /home/askapache.com/.htpasswd
Require valid-user
&lt;/Files&gt;</pre>
<h4>Password Protect multiple files</h4>
<pre>&lt;FilesMatch &quot;^(private|phpinfo)\.*$&quot;&gt;
AuthName &quot;Development&quot;
AuthUserFile /.htpasswd
AuthType basic
Require valid-user
&lt;/FilesMatch&gt;</pre>
<h4>Send Custom Headers</h4>
<pre>Header set P3P &quot;policyref=\&quot;http://www.askapache.com/w3c/p3p.xml\&quot;&quot;
Header set X-Pingback &quot;http://www.askapache.com/xmlrpc.php&quot;
Header set Content-Language &quot;en-US&quot;
Header set Vary &quot;Accept-Encoding&quot;</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$ &quot;(.+)&quot; HTTP_IF_MODIFIED_SINCE=$1
SetEnvIfNoCase ^If-None-Match$ &quot;(.+)&quot; HTTP_IF_NONE_MATCH=$1
SetEnvIfNoCase ^Cache-Control$ &quot;(.+)&quot; HTTP_CACHE_CONTROL=$1
SetEnvIfNoCase ^Connection$ &quot;(.+)&quot; HTTP_CONNECTION=$1
SetEnvIfNoCase ^Keep-Alive$ &quot;(.+)&quot; HTTP_KEEP_ALIVE=$1
SetEnvIfNoCase ^Authorization$ &quot;(.+)&quot; HTTP_AUTHORIZATION=$1
SetEnvIfNoCase ^Cookie$ &quot;(.+)&quot; 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 &quot;208\.113\.183\.103&quot; &quot;nolog,noauditlog,pass&quot;</pre>
<h4>Turn logging on for IP</h4>
<pre>SecFilterSelective REMOTE_ADDR &quot;!^208\.113\.183\.103&quot; &quot;nolog,noauditlog,pass&quot;
SecFilterSelective REMOTE_ADDR &quot;208\.113\.183\.103&quot; &quot;log,auditlog,pass&quot;</pre>
<hr class="C" />
<p><a id="mod_rewrite-examples"></a></p>
<h2>Advanced Mod_Rewrite Examples</h2>
<p>Here are some specific examples taken mostly from my WordPress Password Protection plugin, that also does alot more than password protection as you can see from the following mod_rewrite examples.  These are a few of the mod_rewrite uses that BlogSecurity declared pushed the boundaries of Mod_Rewrite!  Some of these snippets are quite exotic and unlike anything you may have seen before, also only for those who understand them as they can kill a website pretty quick.</p>
<h4>Directory Protection</h4>
<p>Enable the DirectoryIndex Protection, preventing directory index listings and defaulting. [<a href="/htaccess/htaccess.html">Disable</a>]</p>
<pre>Options -Indexes
DirectoryIndex index.html index.php /index.php</pre>
<h4>Password Protect wp-login.php</h4>
<p>Requires a valid user/pass to access the login page[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-401">401</a>]</p>
<pre>&lt;Files wp-login.php&gt;
Order Deny,Allow
Deny from All
Satisfy Any
AuthName &quot;Protected By AskApache&quot;
AuthUserFile /home/askapache.com/.htpasswda1
AuthType Basic
Require valid-user
&lt;/Files&gt;</pre>
<h4>Password Protect wp-admin</h4>
<p>Requires a valid user/pass to access any non-static (css, js, images) file in this directory.[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-401">401</a>]</p>
<pre>Options -ExecCGI -Indexes +FollowSymLinks -Includes
DirectoryIndex index.php /index.php
Order Deny,Allow
Deny from All
Satisfy Any
AuthName &quot;Protected By AskApache&quot;
AuthUserFile /home/askapache.com/.htpasswda1
AuthType Basic
Require valid-user
&lt;FilesMatch &quot;\.(ico|pdf|flv|jpg|jpeg|mp3|mpg|mp4|mov|wav|wmv|png|gif|swf|css|js)$&quot;&gt;
Allow from All
&lt;/FilesMatch&gt;
&lt;FilesMatch &quot;(async-upload)\.php$&quot;&gt;
&lt;IfModule mod_security.c&gt;
SecFilterEngine Off
&lt;/IfModule&gt;
Allow from All
&lt;/FilesMatch&gt;</pre>
<h4>Protect wp-content</h4>
<p>Denies any Direct request for files ending in .php with a 403 Forbidden.. May break plugins/themes [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-401">401</a>]</p>
<pre>RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /wp-content/.*$ [NC]
RewriteCond %{REQUEST_FILENAME} !^.+flexible-upload-wp25js.php$
RewriteCond %{REQUEST_FILENAME} ^.+\.(php|html|htm|txt)$
RewriteRule .* - [F,NS,L]</pre>
<h4>Protect wp-includes</h4>
<p>Denies any Direct request for files ending in .php with a 403 Forbidden.. May break plugins/themes [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /wp-includes/.*$ [NC]
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ /wp-includes/js/.+/.+\ HTTP/ [NC]
RewriteCond %{REQUEST_FILENAME} ^.+\.php$
RewriteRule .* - [F,NS,L]</pre>
<h4>Common Exploits</h4>
<p>Block common exploit requests with 403 Forbidden. These can help alot, may break some plugins. [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ ///.*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\?\=?(http|ftp|ssl|https):/.*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\?\?.*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.(asp|ini|dll).*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.(htpasswd|htaccess|aahtpasswd).*\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]</pre>
<h4>Stop Hotlinking</h4>
<p>Denies any request for static files (images, css, etc) if referrer is not local site or empty. [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{HTTP_REFERER} !^http://www.askapache.com.*$ [NC]
RewriteRule \.(ico|pdf|flv|jpg|jpeg|mp3|mpg|mp4|mov|wav|wmv|png|gif|swf|css|js)$ - [F,NS,L]</pre>
<h4>Safe Request Methods</h4>
<p>Denies any request not using <a href="http://www.askapache.com/online-tools/request-method-scanner/">GET,PROPFIND,POST,OPTIONS,PUT,HEAD</a>[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|POST|PROPFIND|OPTIONS|PUT)$ [NC]
RewriteRule .* - [F,NS,L]</pre>
<h4>Forbid Proxies</h4>
<p>Denies any POST Request using a Proxy Server. Can still access site, but not comment.  See <a href="http://perishablepress.com/press/2008/04/20/how-to-block-proxy-servers-via-htaccess/">Perishable Press</a> [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP:VIA}%{HTTP:FORWARDED}%{HTTP:USERAGENT_VIA}%{HTTP:X_FORWARDED_FOR}%{HTTP:PROXY_CONNECTION} !^$ [OR]
RewriteCond %{HTTP:XPROXY_CONNECTION}%{HTTP:HTTP_PC_REMOTE_ADDR}%{HTTP:HTTP_CLIENT_IP} !^$
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]</pre>
<h4>Real wp-comments-post.php</h4>
<p>Denies any POST attempt made to a non-existing wp-comments-post.php[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*/wp-comments-post\.php.*\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]</pre>
<h4>HTTP PROTOCOL</h4>
<p>Denies any badly formed HTTP PROTOCOL in the request, 0.9, 1.0, and 1.1 only[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ .+\ HTTP/(0\.9|1\.0|1\.1) [NC]
RewriteRule .* - [F,NS,L]</pre>
<h4>SPECIFY CHARACTERS</h4>
<p>Denies any request for a url containing characters other than &#8220;a-zA-Z0-9.+/-?=&#038;&#8221;  &#8211; REALLY helps but may break your site depending on your links. [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;amp;]+\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]</pre>
<h4>BAD Content Length</h4>
<p>Denies any POST request that doesnt have a Content-Length Header[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP:Content-Length} ^$
RewriteCond %{REQUEST_URI} !^/(wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]</pre>
<h4>BAD Content Type</h4>
<p>Denies any POST request with a content type other than application/x-www-form-urlencoded|multipart/form-data[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP:Content-Type} !^(application/x-www-form-urlencoded|multipart/form-data.*(boundary.*)?)$ [NC]
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]</pre>
<h4>Missing HTTP_HOST</h4>
<p>Denies requests that dont contain a HTTP HOST Header.[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{HTTP_HOST} ^$
RewriteRule .* - [F,NS,L]</pre>
<h4>Bogus Graphics Exploit</h4>
<p>Denies obvious exploit using bogus graphics[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{HTTP:Content-Disposition} \.php [NC]
RewriteCond %{HTTP:Content-Type} image/.+ [NC]
RewriteRule .* - [F,NS,L]</pre>
<h4>No UserAgent, Not POST</h4>
<p>Denies POST requests by blank user-agents.  May prevent a small number of visitors from POSTING. [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP_USER_AGENT} ^-?$
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]</pre>
<h4>No Referer, No Comment</h4>
<p>Denies any comment attempt with a blank HTTP_REFERER field, highly indicative of spam.  May prevent some visitors from POSTING. [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*/wp-comments-post\.php.*\ HTTP/ [NC]
RewriteCond %{HTTP_REFERER} ^-?$
RewriteRule .* - [F,NS,L]</pre>
<h4>Trackback Spam</h4>
<p>Denies obvious trackback spam.  See Holy Shmoly! [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP_USER_AGENT} ^.*(opera|mozilla|firefox|msie|safari).*$ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.+/trackback/?\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]</pre>
<h4>Map all URIs except those corresponding to existing files to a handler</h4>
<pre>RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule . /script.php</pre>
<h4>Map any request to a handler</h4>
<p>In the case where all URIs should be sent to the same place (including potentially requests for static content) the method to use depends on the type of the handler. For php scripts, use:<br />
For other handlers such as php scripts, use:</p>
<pre>RewriteEngine On
RewriteCond %{REQUEST_URI} !=/script.php
RewriteRule .* /script.php</pre>
<h4>And for CGI scripts:</h4>
<pre>ScriptAliasMatch .* /var/www/script.cgi</pre>
<h4>Map URIs corresponding to existing files to a handler instead</h4>
<pre>RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f
RewriteCond %{REQUEST_URI} !=/script.php
RewriteRule .* /script.php</pre>
<p>If the existing files you wish to have handled by your script have a common set of file extensions distinct from that of the hander, you can bypass mod_rewrite and use instead mod_actions. Let&#8217;s say you want all .html and .tpl files to be dealt with by your script:</p>
<pre>Action foo-action /script.php
AddHandler foo-action html tpl</pre>
<h4>Deny access if var=val contains the string foo.</h4>
<pre>RewriteCond %{QUERY_STRING} foo
RewriteRule ^/url - [F]</pre>
<h4>Removing the Query String</h4>
<pre>RewriteRule ^/url /url?</pre>
<h4>Adding to the Query String</h4>
<p>Keep the existing query string using the Query String Append flag, but add var=val to the end.</p>
<pre>RewriteRule ^/url /url?var=val [QSA]</pre>
<h4>Rewriting For Certain Query Strings</h4>
<p>Rewrite URLs like http://askapache.com/url1?var=val to http://askapache.com/url2?var=val but don&#8217;t rewrite if val isn&#8217;t present.</p>
<pre>RewriteCond %{QUERY_STRING} val
RewriteRule ^/url1 /url2</pre>
<h4>Modifying the Query String</h4>
<p>Change any single instance of val in the query string to other_val when accessing /path. Note that %1 and %2 are back-references to the matched part of the regular expression in the previous RewriteCond.</p>
<pre>RewriteCond %{QUERY_STRING} ^(.*)val(.*)$
RewriteRule /path /path?%1other_val%2</pre>
<hr class="C" />
<p><a id="best-htaccess-articles"></a></p>
<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  &#8220;expert level&#8221; 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"><!-- IMAGE REMOVED BY wp-image-resizer HERE --></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&#8217;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"><!-- IMAGE REMOVED BY wp-image-resizer HERE --></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"><!-- IMAGE REMOVED BY wp-image-resizer HERE --></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 apache" /></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 &#8220;http&#8221; or &#8220;https&#8221; 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" />
<p><a id="htaccess-merging-order"></a></p>
<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>
<p>.</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 &quot;^.*b$&quot;&gt;
C
&lt;/DirectoryMatch&gt;
&lt;Directory /a/b&gt;
A
&lt;/Directory&gt;</pre>
<p><a id="favorite-htaccess"></a></p>
<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&#8217;m really into doing your own hacking to get knowledge and these links are all great resources in that respect.  I&#8217;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></p>
<p><strong>Robert Hansen</strong><br />Here&#8217;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/">&#8220;.htaccess &#8211; gzip and cache your site for faster loading and bandwidth saving.&#8221;</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&#8230; 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&#038;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&#8217;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.</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&#8242;s that produced some <a href="http://www.apacheweek.com/features/userauth">excellent documentation</a>.</p>
<p><strong>Corz</strong><br />Here&#8217;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&#8217;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>.</a></p>
<hr class="C" />
<p><a id="htaccess-directives-list"></a></p>
<h2>Htaccess Directives</h2>
<p class="anote">This is an AskApache.com exclusive <em>you won&#8217;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" />
<p><a id="htaccess-modules"></a></p>
<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" />
<p><a id="htaccess-software"></a></p>
<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&#8217;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>
<p>Here are some <strong>example snippets of htaccess files</strong> grabbed from various sites.</p>
<pre>&lt;IfModule mod_rewrite.c&gt;
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
&lt;/IfModule&gt;
&nbsp;
&lt;Limit GET POST PUT&gt;
Order Allow,Deny
Deny from All
&lt;/Limit&gt;
&nbsp;
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
&lt;/IfModule&gt;
&nbsp;
#
# Apache/PHP/Drupal settings:
#
# Protect files and directories from prying eyes.
&nbsp;
Options +Indexes
&nbsp;
AddIcon /icons/compressed.gif .bz2
AddType image/svg+xml .svg
AddType image/svg+xml .svgz
AddType text/html .shtml
AddHandler server-parsed .shtml .html
&nbsp;
#DirectoryIndex index.php index.html
#Options +FollowSymLinks
#Options -Indexes
&nbsp;
Options All -Indexes
&nbsp;
# The concept for this was taken from the Drupal project by D. Keith Casey Jr. - caseydk@use&#46;..
# PHP 4, Apache 1
&lt;IfModule mod_php4.c&gt;
php_value magic_quotes_gpc 0
&nbsp;
Options Indexes
&nbsp;
XBitHack on
&nbsp;
&lt;ifmodule mod_rewrite.c&gt;
RewriteEngine On
RewriteRule ^user/(\w+)/(\w+)/(\w+) index.php?user=$1&amp;w=$2&amp;root=$3 [L,QSA]
RewriteRule ^user/(\w+)/(\w+) index.php?user=$1&amp;w=$2 [L,QSA]
RewriteRule ^user/(\w+) index.php?user=$1 [L,QSA]
&nbsp;
Satisfy All
Options -Indexes
&lt;Files ~ &quot;^\.&quot;&gt;
order allow,deny
&nbsp;
#
# Apache/PHP/Drupal settings:
#
#php_flag display_errors on
#php_flag display_startup_errors on
&nbsp;
&lt;Files &quot;config.php&quot;&gt;
Order Allow,Deny
Deny from All
&lt;/Files&gt;
&nbsp;
&lt;?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
&nbsp;
DirectoryIndex index.htm index.html index.php index.prc index.htpl
&lt;FilesMatch &quot;\.(htpl|prc)$&quot;&gt;
SetHandler htpl-script
&lt;/FilesMatch&gt;
&nbsp;
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
&nbsp;
&lt;filesmatch &quot;\.php$&quot;&gt;
allow from all
&lt;/filesmatch&gt;
#Uncomment the below to enable podcasting
&nbsp;
#
# Apache/PHP/Drupal settings:
#
# Protect files and directories from prying eyes.
AddDefaultCharset utf-8
&nbsp;
# $Id: .htaccess,v 1.8 2004/11/03 18:21:16 rurban Exp $
&lt;IfModule mod_php4.c&gt;
# For added security (and PhpWiki debugging purposes) you may want to
&nbsp;
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
&lt;/IfModule&gt;
&nbsp;
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteRule ^([0-9]+)$ index.cgi?id=$1 [L]
RewriteRule ^(rss|atom)$ index.cgi?action=qotw&amp;output=$1 [L]
RewriteRule ^([a-z_]+)(/([a-z_]*))?$ index.cgi?action=$1&amp;admin_action=$3 [L,QSA]</pre>
<p><strong>More on Page 2.</strong></p>
<p><span id="more-23"></span></p>
<div class='presskit'><h3>High Resolution Press Images:</h3>[+] <a href='http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?src=http://uploads.askapache.com/2008/08/htaccess-up.png&down=true'>htaccess-up.png</a><br />[+] <a href='http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?src=http://uploads.askapache.com/2009/01/htaccess-explorer.png&down=true'>htaccess-explorer.png</a><br />[+] <a href='http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?src=http://uploads.askapache.com/2009/01/viewing-htaccess-files.png&down=true'>viewing-htaccess-files.png</a><br />[+] <a href='http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?src=http://uploads.askapache.com/2008/08/htaccess-up1-350x178.png&down=true'>htaccess-up1-350x178.png</a><br />[+] <a href='http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?src=http://uploads.askapache.com/2008/01/jail-bars-1.png&down=true'>jail-bars-1.png</a><br />[+] <a href='http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?src=http://uploads.askapache.com/2007/10/cookies.png&down=true'>cookies.png</a><br />[+] <a href='http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?src=http://uploads.askapache.com/2008/04/bad_robot1.png&down=true'>bad_robot1.png</a><br /></div><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>71</slash:comments>
		</item>
		<item>
		<title>.htaccess Plugin Blocks Spam, Hackers, and Password Protects Blog</title>
		<link>http://www.askapache.com/htaccess/htaccess-plugin-blocks-spam-hackers-and-password-protects-blog.html</link>
		<comments>http://www.askapache.com/htaccess/htaccess-plugin-blocks-spam-hackers-and-password-protects-blog.html#comments</comments>
		<pubDate>Sat, 22 Nov 2008 14:18:12 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Plugins]]></category>
		<category><![CDATA[.htaccess plugin]]></category>
		<category><![CDATA[301 Redirect]]></category>
		<category><![CDATA[401]]></category>
		<category><![CDATA[403 Forbidden]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[Advanced]]></category>
		<category><![CDATA[Anti-Spam]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[ASP]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Dig]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[errordocument]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[FilesMatch]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[hotlinking]]></category>
		<category><![CDATA[htaccess files]]></category>
		<category><![CDATA[htaccess rewrite]]></category>
		<category><![CDATA[htaccess tricks]]></category>
		<category><![CDATA[Htpasswd]]></category>
		<category><![CDATA[HTTP Headers]]></category>
		<category><![CDATA[httpd]]></category>
		<category><![CDATA[HTTPS SSL]]></category>
		<category><![CDATA[Login]]></category>
		<category><![CDATA[mod_include]]></category>
		<category><![CDATA[Mod_Rewrite]]></category>
		<category><![CDATA[Mod_Security]]></category>
		<category><![CDATA[Mod_Setenvif]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[Redirect]]></category>
		<category><![CDATA[Request Method]]></category>
		<category><![CDATA[Rewrite Tricks]]></category>
		<category><![CDATA[rewritecond]]></category>
		<category><![CDATA[rewriterule]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[SetEnvIf]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[stat]]></category>
		<category><![CDATA[SymLinks]]></category>
		<category><![CDATA[trick]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=1053</guid>
		<description><![CDATA[<p><a class="IFL" href="http://www.askapache.com/htaccess/htaccess-plugin-blocks-spam-hackers-and-password-protects-blog.html"><img src="http://uploads.askapache.com/2008/11/htaccess-plugin-2.png" alt=".htaccess security plugin 2" title=".htaccess security plugin 2" width="269" height="436" /></a><br /><br />Well what can I say, <strong>other than this is sooo DOPE</strong>!  Here is a list of the modules this plugin (version 4.7 unreleased) will automatically detect.  I compiled the list myself using every module included with any default Apache installation for ALL the versions listed below, 1.3 to 2.2+<br /><br />Want to know something else I'm including in this plugin?  For each and every module that is detected, this plugin can then detect ALL of the modules .htaccess Directives!  For instance, <code>RewriteRule, AccessFileName, AddHandler, etc..</code> are each a directive belonging to a module that is allowed to be used from within .htaccess files.<br /><br /><strong>Talk about sick.. these tricks have the diamond disease!</strong><br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<div class='images'><a href='http://uploads.askapache.com/2008/11/htaccess-plugin-2.png'><img src="http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?fltr=usm&src=http://uploads.askapache.com/2008/11/htaccess-plugin-2.png&w=400" title=" apache" alt=".htaccess Plugin Blocks Spam, Hackers, and Password Protects Blog" /></a><a href='http://uploads.askapache.com/2008/11/htaccess-plugin-1.png'><img src="http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?fltr=usm&src=http://uploads.askapache.com/2008/11/htaccess-plugin-1.png&w=400" title=" apache" alt=".htaccess Plugin Blocks Spam, Hackers, and Password Protects Blog" /></a><a href='http://uploads.askapache.com/2008/11/htaccess-plugin-3.png'><img src="http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?fltr=usm&src=http://uploads.askapache.com/2008/11/htaccess-plugin-3.png&w=400" title=" apache" alt=".htaccess Plugin Blocks Spam, Hackers, and Password Protects Blog" /></a><a href='http://uploads.askapache.com/2008/11/htaccess-plugin-4.png'><img src="http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?fltr=usm&src=http://uploads.askapache.com/2008/11/htaccess-plugin-4.png&w=400" title=" apache" alt=".htaccess Plugin Blocks Spam, Hackers, and Password Protects Blog" /></a><a href='http://uploads.askapache.com/2008/07/http-security-askapache1.png'><img src="http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?fltr=usm&src=http://uploads.askapache.com/2008/07/http-security-askapache1.png&w=400" title=" apache" alt=".htaccess Plugin Blocks Spam, Hackers, and Password Protects Blog" /></a></div><p><a class="IFL" href="http://uploads.askapache.com/2008/11/htaccess-plugin-2.png"><!-- IMAGE REMOVED BY wp-image-resizer HERE --></a></p>
<p>Well what can I say, <strong>other than this is sooo DOPE</strong>!  Here is a <a href="#htaccess-module-list">list of the modules</a> this plugin (version 4.7 unreleased) will automatically detect.  I compiled the list myself using every module included with any default Apache installation for ALL the versions listed below, 1.3 to 2.2+</p>
<p>Want to know something else I&#8217;m including in this plugin?  For each and every module that is detected, this plugin can then detect ALL of the modules .htaccess Directives!  For instance, <code>RewriteRule, AccessFileName, AddHandler, etc..</code> are each a directive belonging to a module that is allowed to be used from within .htaccess files.</p>
<p><strong>Talk about sick.. these tricks have the diamond disease!</strong><br class="C" /></p>
<h2>Screenshot Unreleased 4.7</h2>
<p>I&#8217;ve been making a lot of progress as these screenshots illustrate, including the ability to detect 100% accurately the modules that are enabled on your server.  Big deal!  you might say&#8230; &#8220;How does knowing the modules help?&#8221;</p>
<p>Well it just so happens that in addition to detecting which modules are loaded on your server, this plugin will also detect which Directives are enabled for each module that are allowed to be used from within your .htaccess file!  Future release will provide the ability to explore the different .htaccess directives allowed by your server, so you can do all sorts of cool Apache .htaccess tricks to secure your blog and make it run better.</p>
<p><a href="http://uploads.askapache.com/2008/11/htaccess-plugin-1.png"><!-- IMAGE REMOVED BY wp-image-resizer HERE --></a><br /><a href="http://uploads.askapache.com/2008/11/htaccess-plugin-3.png"><!-- IMAGE REMOVED BY wp-image-resizer HERE --></a><br /><a href="http://uploads.askapache.com/2008/11/htaccess-plugin-4.png"><!-- IMAGE REMOVED BY wp-image-resizer HERE --></a></p>
<h2><a id="htaccess-module-list">Apache Module Detection</a></h2>
<p>Future releases of this plugin will also let you search for non-default modules, wild, beta, and others.</p>
<ul>
<li>mod_access</li>
<li>mod_actions</li>
<li>mod_alias</li>
<li>mod_asis</li>
<li>mod_auth</li>
<li>mod_auth_anon</li>
<li>mod_auth_basic</li>
<li>mod_auth_dbm</li>
<li>mod_auth_digest</li>
<li>mod_auth_ldap</li>
<li>mod_authn_alias</li>
<li>mod_authn_anon</li>
<li>mod_authn_dbd</li>
<li>mod_authn_dbm</li>
<li>mod_authn_default</li>
<li>mod_authn_file</li>
<li>mod_authnz_ldap</li>
<li>mod_authz_dbm</li>
<li>mod_authz_default</li>
<li>mod_authz_groupfile</li>
<li>mod_authz_host</li>
<li>mod_authz_owner</li>
<li>mod_authz_user</li>
<li>mod_autoindex</li>
<li>mod_bucketeer</li>
<li>mod_cache</li>
<li>mod_case_filter</li>
<li>mod_case_filter_in</li>
<li>mod_cern_meta</li>
<li>mod_cgi</li>
<li>mod_cgid</li>
<li>mod_charset_lite</li>
<li>mod_dav</li>
<li>mod_dav_fs</li>
<li>mod_dav_lock</li>
<li>mod_dbd</li>
<li>mod_deflate</li>
<li>mod_dir</li>
<li>mod_disk_cache</li>
<li>mod_dumpio</li>
<li>mod_echo</li>
<li>mod_env</li>
<li>mod_example</li>
<li>mod_expires</li>
<li>mod_ext_filter</li>
<li>mod_file_cache</li>
<li>mod_filter</li>
<li>mod_headers</li>
<li>mod_ident</li>
<li>mod_imagemap</li>
<li>mod_imap</li>
<li>mod_include</li>
<li>mod_info</li>
<li>mod_isapi</li>
<li>mod_log_config</li>
<li>mod_log_forensic</li>
<li>mod_logio</li>
<li>mod_mem_cache</li>
<li>mod_mime</li>
<li>mod_mime_magic</li>
<li>mod_mycore</li>
<li>mod_negotiation</li>
<li>mod_netware</li>
<li>mod_nw_ssl</li>
<li>mod_optional_fn_export</li>
<li>mod_optional_fn_import</li>
<li>mod_optional_hook_export</li>
<li>mod_optional_hook_import</li>
<li>mod_proxy</li>
<li>mod_proxy_ajp</li>
<li>mod_proxy_balancer</li>
<li>mod_proxy_connect</li>
<li>mod_proxy_ftp</li>
<li>mod_proxy_http</li>
<li>mod_rewrite</li>
<li>mod_security</li>
<li>mod_setenvif</li>
<li>mod_so</li>
<li>mod_speling</li>
<li>mod_ssl</li>
<li>mod_status</li>
<li>mod_substitute</li>
<li>mod_suexec</li>
<li>mod_test</li>
<li>mod_unique_id</li>
<li>mod_userdir</li>
<li>mod_usertrack</li>
<li>mod_version</li>
<li>mod_vhost_alias</li>
<li>mod_win32</li>
</ul>
<p><a rel="lb" class="IFL hs hs35" href='http://uploads.askapache.com/2008/07/http-security-askapache.png' title="http-security-askapache"></a>The original plugin page and description <a href="http://www.askapache.com/wordpress/htaccess-password-protect.html">can be found here</a>.<br class="C" /></p>
<h2>UPDATE: 11/22/08</h2>
<p><a rel="lb" class="IFL hs hs35" href='http://uploads.askapache.com/2008/07/http-security-askapache.png' title="http-security-askapache"></a><strong>To make a long story short,</strong> I downloaded each major release of the apache httpd source code from version 1.3.0 to version 2.2.10, then I configured and compiled each for a custom HTTPD installation built from source.  This allowed me to find every directive allowed in .htaccess files for each particular version.  <strong style="font-weight:bold;">YES!</strong><br class="C" /></p>
<blockquote cite="http://wordpress.org/support/topic/214390"><p><cite><a href="http://wordpress.org/support/rss/topic/214390">http://wordpress.org/support/rss/topic/214390</a></cite><br />
I&#8217;ve been working on a completely improved version on/off for about a month with the specific goal of finally ending all the little errors that can crop up when dealing with .htaccess.</p>
<p>To that effect I am succeeding marvelously, first I&#8217;ve converted the plugin to a class (4+5 compat), I&#8217;ve replaced my error_handling with WordPress&#8217;s WP_Error class, and the coolest change is the new tests I&#8217;ve added.</p>
<p>To make a long story short, I downloaded each major release of the apache httpd source code starting at version 1.3.0 and finishing with version 2.2.10, I then compiled each version and built a HTTPD from source for all the apache versions.  </p>
<p><em><code>1.3.0</code>, <code>1.3.1</code>, <code>1.3.11</code>, <code>1.3.12</code>, <code>1.3.14</code>, <code>1.3.17</code>, <code>1.3.19</code>, <code>1.3.2</code>, <code>1.3.20</code>, <code>1.3.22</code>, <code>1.3.23</code>, <code>1.3.24</code>, <code>1.3.27</code>, <code>1.3.28</code>, <code>1.3.29</code>, <code>1.3.3</code>, <code>1.3.31</code>, <code>1.3.32</code>, <code>1.3.33</code>, <code>1.3.34</code>, <code>1.3.35</code>, <code>1.3.36</code>, <code>1.3.37</code>, <code>1.3.39</code>, <code>1.3.4</code>, <code>1.3.41</code>, <code>1.3.6</code>, <code>1.3.9</code>, <code>2.0.35</code>, <code>2.0.36</code>, <code>2.0.39</code>, <code>2.0.40</code>, <code>2.0.42</code>, <code>2.0.43</code>, <code>2.0.44</code>, <code>2.0.45</code>, <code>2.0.46</code>, <code>2.0.47</code>, <code>2.0.48</code>, <code>2.0.49</code>, <code>2.0.50</code>, <code>2.0.51</code>, <code>2.0.52</code>, <code>2.0.53</code>, <code>2.0.54</code>, <code>2.0.55</code>, <code>2.0.58</code>, <code>2.0.59</code>, <code>2.0.61</code>, <code>2.0.63</code>, <code>2.1.3-beta</code>, <code>2.1.6-alpha</code>, <code>2.1.7-beta</code>, <code>2.1.8-beta</code>, <code>2.1.9-beta</code>, <code>2.2.0</code>, <code>2.2.10</code>, <code>2.2.2</code>, <code>2.2.3</code>, <code>2.2.4</code>, <code>2.2.6</code>, <code>2.2.8</code>, <code>2.2.9</code></em></p>
<p>Then I went through each version and determined the compatible modules for that version, and I&#8217;m pretty confident that I was also able to find each and every directive allowed by the compatible modules for that version (including core directives).  See <a href="http://www.askapache.com/htaccess/htaccess.html#htaccess-directives">.htaccess directive list</a>.</p>
<p>Basically I can now test a server using a variety of methods and determine almost 100% accurately what version of Apache (down to the API) is running, what modules (and versions) are enabled, and each and every directive that is allowed or disallowed for that version.</p>
<p>So this is so awesome because now we can enable all sorts of additional security features.</p>
<p>Other big changes are:</p>
<ul>
<li>Completely hands-off updates, so that updating the plugin keeps all your settings.</li>
<li>making each SID module have its own configuration and options (like protecting individual files, individual request, and custom exploit strings).</li>
<li>Advanced ErrorDocument usage and handling (like tracking repeat offenders and suggesting they be blocked, emailing admin with custom info, etc..)</li>
<li>Multi User/Group password Control</li>
</ul>
<p>And this time I am developing the plugin using a plethora of wordpress installations and configurations, to make sure that it will work regardless of a custom siteurl, blogid, etc..</p>
<p><strong>Release will come before 2009.. I have some vacations to take and business to finish first. </strong>
</p></blockquote>
<h2>.htaccess Security Modules</h2>
<h3><a id="htaccess-sid700" title="Directory Protection">Directory Protection</a></h3>
<p>Enable the DirectoryIndex Protection, preventing directory index listings and defaulting. [<a href="http://www.askapache.com/htaccess/htaccess.html">Disable</a>]</p>
<pre>Options -Indexes
DirectoryIndex index.html index.php /index.php</pre>
<h3><a id="htaccess-sid800" title="Password Protect wp-login.php">Password Protect wp-login.php</a></h3>
<p>Requires a valid user/pass to access the login page <strong>- *** Safe, Use</strong> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-401">401</a>]</p>
<pre>&lt;Files wp-login.php&gt;
Order Deny,Allow
Deny from All
Satisfy Any
&nbsp;
AuthName &quot;Protected By AskApache&quot;
AuthUserFile /home/askapache.com/.htpasswda1
AuthType Basic
Require valid-user
&lt;/Files&gt;</pre>
<h3><a id="htaccess-sid900" title="Password Protect wp-admin">Password Protect wp-admin</a></h3>
<p>Requires a valid user/pass to access any non-static (css, js, images) file in this directory. <strong>- *** Safe, Use</strong> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-401">401</a>]</p>
<pre>Options -ExecCGI -Indexes +FollowSymLinks -Includes
DirectoryIndex index.php /index.php
&nbsp;
Order Deny,Allow
&nbsp;
Deny from All
Satisfy Any
&nbsp;
AuthName &quot;Protected By AskApache&quot;
AuthUserFile /home/askapache.com/.htpasswda1
AuthType Basic
Require valid-user
&nbsp;
&lt;FilesMatch &quot;\.(ico|pdf|flv|jpg|jpeg|mp3|mpg|mp4|mov|wav|wmv|png|gif|swf|css|js)$&quot;&gt;
Allow from All
&lt;/FilesMatch&gt;
&nbsp;
&lt;FilesMatch &quot;(async-upload)\.php$&quot;&gt;
&lt;IfModule mod_security.c&gt;
SecFilterEngine Off
&lt;/IfModule&gt;
Allow from All
&lt;/FilesMatch&gt;</pre>
<h3><a id="htaccess-sid1000" title="Protect wp-content">Protect wp-content</a></h3>
<p>Denies any Direct request for files ending in .php with a 403 Forbidden.. May break plugins/themes [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-401">401</a>]</p>
<pre>RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /wp-content/.*$ [NC]
RewriteCond %{REQUEST_FILENAME} !^.+flexible-upload-wp25js.php$
RewriteCond %{REQUEST_FILENAME} ^.+\.(php|html|htm|txt)$
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1010" title="Protect wp-includes">Protect wp-includes</a></h3>
<p>Denies any Direct request for files ending in .php with a 403 Forbidden.. May break plugins/themes [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /wp-includes/.*$ [NC]
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ /wp-includes/js/.+/.+\ HTTP/ [NC]
RewriteCond %{REQUEST_FILENAME} ^.+\.php$
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1011" title="Common Exploits">Common Exploits</a></h3>
<p>Block common exploit requests with 403 Forbidden. These can help alot, may break some plugins. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ ///.*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\?\=?(http|ftp|ssl|https):/.*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\?\?.*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.(asp|ini|dll).*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.(htpasswd|htaccess|aahtpasswd).*\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1012" title="Stop Hotlinking">Stop Hotlinking</a></h3>
<p>Denies any request for static files (images, css, etc) if referrer is not local site or empty. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{HTTP_REFERER} !^http://www.askapache.com.*$ [NC]
RewriteRule \.(ico|pdf|flv|jpg|jpeg|mp3|mpg|mp4|mov|wav|wmv|png|gif|swf|css|js)$ - [F,NS,L]</pre>
<h3><a id="htaccess-sid1015" title="Safe Request Methods">Safe Request Methods</a></h3>
<p>Denies any request not using <a href="http://www.askapache.com/online-tools/request-method-scanner/">GET,PROPFIND,POST,OPTIONS,PUT,HEAD</a> <strong>- *** Safe, Use</strong> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|POST|PROPFIND|OPTIONS|PUT)$ [NC]
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1017" title="Forbid Proxies">Forbid Proxies</a></h3>
<p>Denies any POST Request using a Proxy Server. Can still access site, but not comment.  See <a href="http://perishablepress.com/press/2008/04/20/how-to-block-proxy-servers-via-htaccess/">Perishable Press</a> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP:VIA}%{HTTP:FORWARDED}%{HTTP:USERAGENT_VIA}%{HTTP:X_FORWARDED_FOR}%{HTTP:PROXY_CONNECTION} !^$ [OR]
RewriteCond %{HTTP:XPROXY_CONNECTION}%{HTTP:HTTP_PC_REMOTE_ADDR}%{HTTP:HTTP_CLIENT_IP} !^$
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1018" title="Real wp-comments-post.php">Real wp-comments-post.php</a></h3>
<p>Denies any POST attempt made to a non-existing wp-comments-post.php <strong>- *** Safe, Use</strong> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*/wp-comments-post\.php.*\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1019" title="HTTP PROTOCOL">HTTP PROTOCOL</a></h3>
<p>Denies any badly formed HTTP PROTOCOL in the request, 0.9, 1.0, and 1.1 only  <strong>- *** Safe, Use</strong> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ .+\ HTTP/(0\.9|1\.0|1\.1) [NC]
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1020" title="SPECIFY CHARACTERS">SPECIFY CHARACTERS</a></h3>
<p>Denies any request for a url containing characters other than &#8220;a-zA-Z0-9.+/-?=&#038;&#8221;  &#8211; REALLY helps but may break your site depending on your links. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1021" title="BAD Content Length">BAD Content Length</a></h3>
<p>Denies any POST request that doesnt have a Content-Length Header <strong>- *** Safe, Use</strong> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP:Content-Length} ^$
RewriteCond %{REQUEST_URI} !^/(wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1022" title="BAD Content Type">BAD Content Type</a></h3>
<p>Denies any POST request with a content type other than application/x-www-form-urlencoded|multipart/form-data <strong>- *** Safe, Use</strong> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP:Content-Type} !^(application/x-www-form-urlencoded|multipart/form-data.*(boundary.*)?)$ [NC]
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1023" title="Directory Traversal">Directory Traversal</a></h3>
<p>Denies Requests containing ../ or ./. which is a directory traversal exploit attempt <strong>- *** Safe, Use</strong> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<h3><a id="htaccess-sid1024" title="PHPSESSID Cookie">PHPSESSID Cookie</a></h3>
<p>Only blocks when a PHPSESSID cookie is sent by the user and it contains characters other than 0-9a-z <strong>- *** Safe, Use</strong> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<h3><a id="htaccess-sid1025" title="NO HOST:">NO HOST:</a></h3>
<p>Denies requests that dont contain a HTTP HOST Header. <strong>- *** Safe, Use</strong> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{HTTP_HOST} ^$
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1026" title="Bogus Graphics Exploit">Bogus Graphics Exploit</a></h3>
<p>Denies obvious exploit using bogus graphics  <strong>- *** Safe, Use</strong> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{HTTP:Content-Disposition} \.php [NC]
RewriteCond %{HTTP:Content-Type} image/.+ [NC]
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1027" title="No UserAgent, No Post">No UserAgent, No Post</a></h3>
<p>Denies POST requests by blank user-agents.  May prevent a small number of visitors from POSTING. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP_USER_AGENT} ^-?$
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1028" title="No Referer, No Comment">No Referer, No Comment</a></h3>
<p>Denies any comment attempt with a blank HTTP_REFERER field, highly indicative of spam.  May prevent some visitors from POSTING. [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*/wp-comments-post\.php.*\ HTTP/ [NC]
RewriteCond %{HTTP_REFERER} ^-?$
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1029" title="Trackback Spam">Trackback Spam</a></h3>
<p>Denies obvious trackback spam.   See <a href="http://ocaoimh.ie/2008/07/03/more-ways-to-stop-spammers-and-unwanted-traffic/">Holy Shmoly!</a> [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP_USER_AGENT} ^.*(opera|mozilla|firefox|msie|safari).*$ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.+/trackback/?\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]</pre>
<h3><a id="htaccess-sid1030" title="SSL-Only Site">SSL-Only Site</a></h3>
<p>Redirects all non-SSL (https) requests to your https-enabled url [<a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#status-301">301</a>]</p>
<h3><a id="htaccess-sid2000" title="Anti-Spam, Anti-Exploits">Anti-Spam, Anti-Exploits</a></h3>
<p>Denies Obvious Spam and uses advanced mod_security protection [<a href="http://www.askapache.com/htaccess/mod_security-htaccess-tricks.html">Read More</a>]</p>
<h2>.htaccess Security Module Screenshot</h2>
<p><a rel="lb" href='http://uploads.askapache.com/2008/07/http-security-askapache.png'><!-- IMAGE REMOVED BY wp-image-resizer HERE --></a></p>
<div class='presskit'><h3>High Resolution Press Images:</h3>[+] <a href='http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?src=http://uploads.askapache.com/2008/11/htaccess-plugin-2.png&down=true'>htaccess-plugin-2.png</a><br />[+] <a href='http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?src=http://uploads.askapache.com/2008/11/htaccess-plugin-1.png&down=true'>htaccess-plugin-1.png</a><br />[+] <a href='http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?src=http://uploads.askapache.com/2008/11/htaccess-plugin-3.png&down=true'>htaccess-plugin-3.png</a><br />[+] <a href='http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?src=http://uploads.askapache.com/2008/11/htaccess-plugin-4.png&down=true'>htaccess-plugin-4.png</a><br />[+] <a href='http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?src=http://uploads.askapache.com/2008/07/http-security-askapache1.png&down=true'>http-security-askapache1.png</a><br /></div><p><a href="http://www.askapache.com/htaccess/htaccess-plugin-blocks-spam-hackers-and-password-protects-blog.html"></a><a href="http://www.askapache.com/htaccess/htaccess-plugin-blocks-spam-hackers-and-password-protects-blog.html">.htaccess Plugin Blocks Spam, Hackers, and Password Protects Blog</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/htaccess-plugin-blocks-spam-hackers-and-password-protects-blog.html/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
		<item>
		<title>Preloading .flv and .mp3 files with Flash</title>
		<link>http://www.askapache.com/flash/preloading-caching-flv-mp3.html</link>
		<comments>http://www.askapache.com/flash/preloading-caching-flv-mp3.html#comments</comments>
		<pubDate>Tue, 05 Aug 2008 16:30:16 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Advanced]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[Boot]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[Cache-Control]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[compression]]></category>
		<category><![CDATA[Dig]]></category>
		<category><![CDATA[Etags]]></category>
		<category><![CDATA[expires header]]></category>
		<category><![CDATA[FilesMatch]]></category>
		<category><![CDATA[Flash Actionscript]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[HTTP Headers]]></category>
		<category><![CDATA[HTTPS SSL]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Last-Modified]]></category>
		<category><![CDATA[preload]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[SPEED]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[stat]]></category>
		<category><![CDATA[trick]]></category>

		<guid isPermaLink="false">http://www.askapache.com/flash/preloading-caching-flv-mp3.html</guid>
		<description><![CDATA[<p><a class="IFL" rel="lb" href='http://www.askapache.com/flash/preloading-caching-flv-mp3.html' title='Preload/Cache .mp3 .flv files with Flash Actionscript'><img src='http://uploads.askapache.com/2008/02/myflash1.thumbnail.jpg' alt='Preload/Cache .mp3 .flv files with Flash Actionscript' /></a>If you want to pre-load <code>.flv</code> / <code>.mp3</code> files into a visitors browser cache using flash, here's the actionscript I use to do it, and some ideas behind a good javascript implementation using swfobject or ufo.<br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<div class='images'><a href='http://uploads.askapache.com/2008/02/myflash1.thumbnail.jpg'><img src="http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?fltr=usm&src=http://uploads.askapache.com/2008/02/myflash1.thumbnail.jpg&w=400" title=" flash" alt="Preloading .flv and .mp3 files with Flash" /></a></div><p><a class="IFL" rel="lb" href='http://www.askapache.com/flash/preloading-caching-flv-mp3.html' title='Preload/Cache .mp3 .flv files with Flash Actionscript'><!-- IMAGE REMOVED BY wp-image-resizer HERE --></a>The company I work for does <em>tons</em> of online videos for our clients, and being the lead web designer I am responsible for making the videos work flawlessly and instantly.  Fortunately for my clients, I am a little obsessive about finding the best of the best of the best way to do things.  I have a LONG way to go, especially when it comes to flash, but here are a few choice tips and tricks that currently work for my clients.<br class="C" /></p>
<p class="anote">You can read an alternate/older explanation of this <a href="http://www.askapache.com/htaccess/preload-and-cache-flash-flv-files.html">method here</a>.</p>
<h2>Preloading files into Browser Cache</h2>
<p>One thing I like to do that no-one can appreciate except me and maybe you is to preload the sites various .flv and .mp3 files into the site visitors cache.  Let me give you an example.  Site.com has 12 videos spread out on multiple pages, all are .flv files controlled by a single .swf flash video player.  Most visitors arrive at the home page which has 1 of the 12 videos on it.  So the trick is to preload the other 11 .flv video files from the home page.  Then when the visitor goes to a different page with a different video, it loads instantly.</p>
<h2>Preloading .flv files with Actionscript</h2>
<p>The actionscript is easy, it opens a connection to the .flv file, sets the buffertime to 0, plays the video and immediately pauses, then seeks the position back to 0.</p>
<p>Its relatively easy to get this to work, heres all the actionscript you will need to preload any .flv file.  Just create a new flash document, and on frame 1 enter in this actionscript.  You can also search your flash help for &#8220;preloading&#8221; for more help.</p>
<pre>var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
//attach videodisplay
_level0.attachVideo(ns);
ns.setBufferTime(0);
ns.play(&#039;http://static.askapache.com/f/flv/create-boot-ini.flv&#039;);
ns.pause();
ns.seek(0);</pre>
<h2>Preloading .mp3 files with Actionscript</h2>
<p>This is even easier than .flv!  This is all you need and the mp3 file will be requested from the browser and added to the browsers cache.</p>
<pre>var songTrack:Sound = new Sound();
songTrack.loadSound(&quot;http://static.askapache.com/f/mp3/ga-urchin-speed.mp3&quot;, true);</pre>
<h2>Little Tricks and Tips</h2>
<h3>Passing filenames with flashvars</h3>
<p>So now you have the actionscript and files, but what if you want to pass the file using flashvars?  So <code>/preloader.swf?file=http://static.askapache.com/f/flv/create-boot-ini.flv</code> will work?</p>
<pre>if (!_root.file) {
  file = &#039;http://static.askapache.com/f/flv/create-boot-ini.flv&#039;;
} else {
  file = _root.file;
}
&nbsp;
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
//attach videodisplay
_level0.attachVideo(ns);
ns.setBufferTime(0);
ns.play(file);
ns.pause();
ns.seek(0);</pre>
<h3>Using javascript to time the downloads</h3>
<p>Now, you may think you are a hotshot if you preload 12 .flv files from the homepage using swfobject or ufo, but the problem with doing that all at once is that flash has some real serious issues with running multiple instances like that.  Meaning the movie that IS on your homepage might very well FREEZE or stutter mid-play if you are trying to preload all these files in the background.  I won&#8217;t get into advanced stuff here but to start with you should at least utilize something like a setTimeout function.  I rely heavily on javascript loops to do this.</p>
<pre>setTimeout(function(){swfobject or ufo code;},10000); // 10 second wait</pre>
<h3>Waiting till fully buffered</h3>
<p>Depending on your .flv video player .swf, you may or may not have the capability to receive information on whether or not a file has been loaded or is fully buffered.  So an additional step that I personally take is I don&#8217;t start the preloading loop code until the 1st movie on the home-page has fully buffered.  Sometimes I wait until its done playing.</p>
<h2>Apache .htaccess</h2>
<p>Of course, I can&#8217;t forget this bit of .htaccess</p>
<pre>AddType video/x-flv .flv
AddType application/x-shockwave-flash .swf
&nbsp;
&lt;FilesMatch &quot;\.(flv|swf|mp3)$&quot;&gt;
Header unset Pragma
FileETag None
Header unset ETag
Header unset P3P
Header set Cache-Control &quot;public&quot;
Header set Expires &quot;Thu, 15 Apr 2010 20:00:00 GMT&quot;
&lt;/FilesMatch&gt;</pre>
<h2>Feeling Lucky?</h2>
<p>If by lucky you mean you dig learning how to make your sites FAST, heres some money.</p>
<p><strong>Easy Apache Speed Tips Articles</strong></p>
<ul>
<li><a href="http://www.askapache.com/htaccess/apache-speed-compression.html" title="Turn On gzip Compression to Speed Up Apache">Turn On Compression</a></li>
<li><a href="http://www.askapache.com/htaccess/apache-speed-expires.html" title="Add Far Future Expires Headers to Speed Up Your Site">Add Future Expires Header</a></li>
<li><a href="http://www.askapache.com/htaccess/apache-speed-cache-control.html" title="Cache-Control Headers using Apache and .htaccess">Add Cache-Control Headers</a></li>
<li><a href="http://www.askapache.com/htaccess/apache-speed-etags.html" title="Remove ETag Headers to Speed up Apache">Turn Off ETags</a></li>
<li><a href="http://www.askapache.com/htaccess/apache-speed-last-modified.html" title="Remove the Last-Modified Header from Files to Speed Apache">Remove Last-Modified Header</a></li>
<li><a href="http://www.askapache.com/htaccess/apache-speed-subdomains.html" title="Multiple Subdomains for a Quicker and Faster Web Site">Use Multiple SubDomains</a></li>
</ul>
<div class='presskit'><h3>High Resolution Press Images:</h3>[+] <a href='http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?src=http://uploads.askapache.com/2008/02/myflash1.thumbnail.jpg&down=true'>myflash1.thumbnail.jpg</a><br /></div><p><a href="http://www.askapache.com/flash/preloading-caching-flv-mp3.html"></a><a href="http://www.askapache.com/flash/preloading-caching-flv-mp3.html">Preloading .flv and .mp3 files with Flash</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/flash/preloading-caching-flv-mp3.html/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
<enclosure url="http://static.askapache.com/f/flv/create-boot-ini.flv" length="1027853" type="video/x-flv" />
<enclosure url="http://static.askapache.com/f/mp3/ga-urchin-speed.mp3" length="49152" type="audio/mpeg" />
		</item>
		<item>
		<title>PHP Sessions/Cookies On The Fly</title>
		<link>http://www.askapache.com/ajax/php-sessions-cookies.html</link>
		<comments>http://www.askapache.com/ajax/php-sessions-cookies.html#comments</comments>
		<pubDate>Fri, 28 Mar 2008 10:08:48 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[Advanced]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[Cache-Control]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[Htpasswd]]></category>
		<category><![CDATA[HTTP Headers]]></category>
		<category><![CDATA[HTTPS SSL]]></category>
		<category><![CDATA[Last-Modified]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mod_Rewrite]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[Redirect]]></category>
		<category><![CDATA[Rewrite Tricks]]></category>
		<category><![CDATA[rewriterule]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[Sessions]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[stat]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.askapache.com/htaccess/php-sessions-cookies.html</guid>
		<description><![CDATA[<p><a class="IFL" rel="lb" href='http://uploads.askapache.com/2008/03/dna.jpg' title='Multiple Web Technologies for dynamic php session control'><img src='http://uploads.askapache.com/2008/03/dna.thumbnail.jpg' alt='Multiple Web Technologies for dynamic php session control' /></a>This article shows how to save and modify php session data, cookies, do anything really... <em>without</em> using ajax or iframes or forcing the user make a request.<br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<div class='images'><a href='http://uploads.askapache.com/2008/03/dna.thumbnail.jpg'><img src="http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?fltr=usm&src=http://uploads.askapache.com/2008/03/dna.thumbnail.jpg&w=400" title=" ajax" alt="PHP Sessions/Cookies On The Fly" /></a></div><p><a class="IFL" rel="lb" href='http://uploads.askapache.com/2008/03/dna.jpg' title='Multiple Web Technologies for dynamic php session control'><!-- IMAGE REMOVED BY wp-image-resizer HERE --></a>This article shows how to save and modify php session data, cookies, do anything really&#8230; <em>without</em> using ajax or iframes or forcing the user make a request.<br class="C" /></p>
<p class="cnote"><strong>Warning</strong>: Touches on some moderately advanced web development, definately some very cool stuff though.</p>
<h2>.htaccess mod_rewrite code</h2>
<p>This code turns a request for askapache.com/sess.gif to serve the file /cgi-bin/session-cookie.php &#8211; further disguising this &#8220;image&#8221;.</p>
<pre>RewriteEngine On
RewriteBase /
RewriteRule ^(.*)session\.gif$ /cgi-bin/session-cookie.php [NC,L,QSA]</pre>
<h2>Using javascript</h2>
<p>You can either put a basic img tag somewhere and it will capture this info, or if you want a dynamic way to call this image, you can do it with javascript very easily.</p>
<p>This code loads a new image as soon as this code is executed.. so you could quite easily add this code to be executed upon a certain button click, anything.</p>
<pre>  var t=new Image();
  t.src=&#039;http://www.askapache.com/sess.gif&#039;;</pre>
<h2>The php controller</h2>
<p>This file has some cool stuff in it, check it out.  First we check to see if a session has been initialized and if not we start a session.  Then we initialize an output buffer to hold all the output including the headers until we are ready to send output, the only output we will be sending is a 43 byte 1&#215;1 white image.  The code also sends HTTP headers that prevent the clients browser from caching the image, so a new request is made for the image each time a browser encounters it.</p>
<p>The data we will be saving in the users session file using the session variable called <code>IMAGETEST</code> are the entire <code>$_GET</code>, <code>$_COOKIE</code>, <code>$_POST</code>,  and <code>$_SERVER</code> global variable arrays builtin to php.</p>
<pre>&lt;?php
(!isset($_SESSION)) ? session_start() : $ok=NULL;
ob_start();
&nbsp;
$G=$S=array();
$G=$_REQUEST;
$S=$_SERVER;
&nbsp;
$g=base64_encode(gzcompress(serialize(array(&#039;REQUEST&#039;=&gt;$G,&#039;SERVER&#039;=&gt;$S))));
$_SESSION[&#039;IMAGETEST&#039;]=$g;
&nbsp;
$imagedata=base64_decode(&#039;R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==&#039;);
&nbsp;
header(&quot;Expires: Mon, 26 Jul 1997 05:00:00 GMT&quot;);
header(&quot;Last-Modified: &quot; . gmdate(&quot;D, d M Y H:i:s&quot;) . &quot; GMT&quot;);
header(&quot;Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0&quot;);
header(&quot;Pragma: no-cache&quot;);
header(&#039;Content-Length: 43&#039;);
header(&#039;Content-Type: image/gif&#039;);
echo $imagedata;
&nbsp;
$r=ob_get_clean();
echo $r;
exit;
?&gt;</pre>
<p>The result from requesting the php file is a session variable is created called IMAGETEST that contains a base64 encoded and gzip compressed and php serialized string representing the <code>$_REQUEST</code> and <code>$_SERVER</code> variables for that specific request.</p>
<h3>Example Session IMAGETEST value</h3>
<pre> [IMAGETEST] =&gt; eJy1Vm1vo0YQ/ivIUqu7Orws78ZCKrKxg842LuBE1y9ogSVBscEFnERX33/vsIDj5NK75NQqcoDd2Zln3p5ZbIjG35UhGYO5HQzG2ED9d5KVg</pre>
<h2>Decoding the IMAGETEST</h2>
<p>So to see the values of IMAGETEST if you used my method to compress and save the data as a string, is basically to run the string through the same process backwards.</p>
<pre>&lt;?php
echo &#039;&lt;pre&gt;&#039;;
$p=unserialize(gzuncompress(base64_decode($_SESSION[&#039;IMAGETEST&#039;])));
print_r($p);
?&gt;</pre>
<p>This results in displaying all the variables and data you saved.</p>
<pre>Array
(
[REQUEST] =&gt; Array
(
[ASKAPACHE] =&gt; 6a81995f0c4b73b4d
[MP3] =&gt; off
[subscribe_checkbox_0460e1098afa8bf8b] =&gt; unchecked
[wordpresspass_5510982bf8b] =&gt; 6555555
[wordpressuser_0559828bf8b] =&gt; youdliketoknow
[wordpress_test_cookie] =&gt; WP Cookie check
)
&nbsp;
[SERVER] =&gt; Array
(
[PATH] =&gt; /usr/local/bin:/usr/bin:/bin
[REDIRECT_STATUS] =&gt; 200
[SCRIPT_URL] =&gt; /sess.gif
[SCRIPT_URI] =&gt; http://www.askapache.com/sess.gif
[TZ] =&gt; America/Indianapolis
[SERVER_ADMIN] =&gt; webmaster[at]askapache.com
[HTTP_HOST] =&gt; www.askapache.com
[HTTP_USER_AGENT] =&gt; Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13
[HTTP_ACCEPT] =&gt; image/png,*/*;q=0.5
[HTTP_ACCEPT_LANGUAGE] =&gt; en-us,en;q=0.5
[HTTP_ACCEPT_ENCODING] =&gt; gzip,deflate
[HTTP_ACCEPT_CHARSET] =&gt; ISO-8859-1,utf-8;q=0.7,*;q=0.7
[HTTP_KEEP_ALIVE] =&gt; 300
[HTTP_CONNECTION] =&gt; keep-alive
[HTTP_REFERER] =&gt; http://www.askapache.com/online-tools/htpasswd-generator/
[HTTP_COOKIE] =&gt; 405485
[SERVER_SIGNATURE] =&gt;
[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 SVN/1.4.2
[SERVER_NAME] =&gt; www.askapache.com
[SERVER_ADDR] =&gt; 208.113.183.103
[SERVER_PORT] =&gt; 80
[REMOTE_ADDR] =&gt; 2.12.64.105
[DOCUMENT_ROOT] =&gt; /home/domain.com/public_html
[SCRIPT_FILENAME] =&gt; /home/domain.com/public_html/cgi-bin/session-cookie.php
[REMOTE_PORT] =&gt; 1857
[REDIRECT_QUERY_STRING] =&gt; dir=
[REDIRECT_URL] =&gt; /cgi-bin/session-cookie.php
[GATEWAY_INTERFACE] =&gt; CGI/1.1
[SERVER_PROTOCOL] =&gt; HTTP/1.1
[REQUEST_METHOD] =&gt; GET
[QUERY_STRING] =&gt; dir=
[REQUEST_URI] =&gt; /sess.gif
[SCRIPT_NAME] =&gt; /cgi-bin/session-cookie.php
[ORIG_PATH_INFO] =&gt; /cgi-bin/session-cookie.php
[ORIG_PATH_TRANSLATED] =&gt; /home/domain.com/public_html/cgi-bin/session-cookie.php
[PHP_SELF] =&gt; /cgi-bin/session-cookie.php
[REQUEST_TIME] =&gt; 1206697334
)
&nbsp;
)</pre>
<h2>Simpler php example</h2>
<pre>&lt;?php
session_start();
&nbsp;
$name=$_GET[&#039;name&#039;];
$_SESSION[&quot;$name&quot;]=$_GET[&#039;value&#039;];
&nbsp;
$res=&#039;R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==&#039;;
$c=base64_decode($res);
header(&#039;Content-Length: &#039;.strlen($c));
header(&#039;Content-Type: image/gif&#039;);
echo $c;
&nbsp;
exit;
?&gt;</pre>
<div class='presskit'><h3>High Resolution Press Images:</h3>[+] <a href='http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?src=http://uploads.askapache.com/2008/03/dna.thumbnail.jpg&down=true'>dna.thumbnail.jpg</a><br /></div><p><a href="http://www.askapache.com/ajax/php-sessions-cookies.html"></a><a href="http://www.askapache.com/ajax/php-sessions-cookies.html">PHP Sessions/Cookies On The Fly</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/ajax/php-sessions-cookies.html/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Speed Tips: Add Cache-Control Headers</title>
		<link>http://www.askapache.com/htaccess/apache-speed-cache-control.html</link>
		<comments>http://www.askapache.com/htaccess/apache-speed-cache-control.html#comments</comments>
		<pubDate>Tue, 11 Mar 2008 03:53:16 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[DreamHost]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[Cache-Control]]></category>
		<category><![CDATA[compression]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Etags]]></category>
		<category><![CDATA[expires header]]></category>
		<category><![CDATA[FilesMatch]]></category>
		<category><![CDATA[HTTP Headers]]></category>
		<category><![CDATA[httpd]]></category>
		<category><![CDATA[httpd.conf]]></category>
		<category><![CDATA[Last-Modified]]></category>
		<category><![CDATA[Mod_Rewrite]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[Rewrite Tricks]]></category>
		<category><![CDATA[SPEED]]></category>
		<category><![CDATA[SSI]]></category>

		<guid isPermaLink="false">http://www.askapache.com/htaccess/apache-speed-cache-control.html</guid>
		<description><![CDATA[<p><a class="IFL" rel="lb" href='http://uploads.askapache.com/2007/09/speed-cache-control-on.png' title='Cache-Control Headers On'><img src='http://uploads.askapache.com/2007/09/speed-cache-control-on.thumbnail.png' alt='Cache-Control Headers On' /></a><strong>Using Cache-Control headers you can specify which types of proxies can cache certain content, and how long files should be cached</strong>.<br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<div class='images'><a href='http://uploads.askapache.com/2007/09/speed-cache-control-on.thumbnail.png'><img src="http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?fltr=usm&src=http://uploads.askapache.com/2007/09/speed-cache-control-on.thumbnail.png&w=400" title=" apache" alt="Speed Tips: Add Cache Control Headers" /></a><a href='http://uploads.askapache.com/2007/09/speed-cache-control-off.png'><img src="http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?fltr=usm&src=http://uploads.askapache.com/2007/09/speed-cache-control-off.png&w=400" title=" apache" alt="Speed Tips: Add Cache Control Headers" /></a><a href='http://uploads.askapache.com/2007/09/speed-cache-control-on.png'><img src="http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?fltr=usm&src=http://uploads.askapache.com/2007/09/speed-cache-control-on.png&w=400" title=" apache" alt="Speed Tips: Add Cache Control Headers" /></a></div><p><a class="IFL" rel="lb" href='http://uploads.askapache.com/2007/09/speed-cache-control-on.png' title='Cache-Control Headers On'><!-- IMAGE REMOVED BY wp-image-resizer HERE --></a><strong>Using Cache-Control headers you can specify which types of proxies can cache certain content, and how long files should be cached.</strong>  You can also add the <code>must-revalidate</code> header to force checking the <code>ETag</code> and or <code>Last-Modified</code> for the file to make sure the cache is using the current version.<br class="C" /></p>
<p><strong>Easy Apache Speed Tips Articles</strong></p>
<ul>
<li><a href="http://www.askapache.com/htaccess/apache-speed-compression.html" title="Turn On gzip Compression to Speed Up Apache">Turn On Compression</a></li>
<li><a href="http://www.askapache.com/htaccess/apache-speed-expires.html" title="Add Far Future Expires Headers to Speed Up Your Site">Add Future Expires Header</a></li>
<li><a href="http://www.askapache.com/htaccess/apache-speed-cache-control.html" title="Cache-Control Headers using Apache and .htaccess">Add Cache-Control Headers</a></li>
<li><a href="http://www.askapache.com/htaccess/apache-speed-etags.html" title="Remove ETag Headers to Speed up Apache">Turn Off ETags</a></li>
<li><a href="http://www.askapache.com/htaccess/apache-speed-last-modified.html" title="Remove the Last-Modified Header from Files to Speed Apache">Remove Last-Modified Header</a></li>
<li><a href="http://www.askapache.com/htaccess/apache-speed-subdomains.html" title="Multiple Subdomains for a Quicker and Faster Web Site">Use Multiple SubDomains</a></li>
</ul>
<p class="anote">Keep in mind, if you use a <strong>far future Expires header</strong> you have to change the component&#8217;s filename whenever the file changes.  So please add must-revalidate to your Cache-Control header for your .html files.</p>
<h2>Add Cache-Control Headers</h2>
<p>This goes in your root <a href="http://www.askapache.com/htaccess/htaccess.html">.htaccess file</a> but if you have access to <code>httpd.conf</code> that is better.</p>
<p>This code uses the <a href="http://www.askapache.com/htaccess/using-filesmatch-and-files-in-htaccess.html">FilesMatch directive</a> and the <a href="http://askapache.info/trunk/mod/mod_headers.html#header">Header</a> directive to add Cache-Control Headers to certain files.</p>
<pre># 480 weeks
&lt;FilesMatch &quot;\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$&quot;&gt;
Header set Cache-Control &quot;max-age=290304000, public&quot;
&lt;/FilesMatch&gt;
&nbsp;
# 2 DAYS
&lt;FilesMatch &quot;\.(xml|txt)$&quot;&gt;
Header set Cache-Control &quot;max-age=172800, public, must-revalidate&quot;
&lt;/FilesMatch&gt;
&nbsp;
# 2 HOURS
&lt;FilesMatch &quot;\.(html|htm)$&quot;&gt;
Header set Cache-Control &quot;max-age=7200, must-revalidate&quot;
&lt;/FilesMatch&gt;</pre>
<p>If you are using <a href="http://www.askapache.com/htaccess/apache-speed-expires.html">far Future Expires Headers</a> and Cache-Control <em>(recommended)</em>, you can do this for these files.</p>
<pre>&lt;FilesMatch &quot;\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$&quot;&gt;
Header set Cache-Control &quot;public&quot;
Header set Expires &quot;Thu, 15 Apr 2010 20:00:00 GMT&quot;
&lt;/FilesMatch&gt;</pre>
<h3>Without Cache-Control Headers</h3>
<p><!-- IMAGE REMOVED BY wp-image-resizer HERE --></p>
<h3>With Cache-Control Headers</h3>
<p><!-- IMAGE REMOVED BY wp-image-resizer HERE --></p>
<h2>Currently AskApache.com Uses</h2>
<p>You can use the <a href="http://www.askapache.com/online-tools/http-headers-tool">HTTP Header Viewer Tool</a> to check it.</p>
<pre>Header unset Pragma
FileETag None
Header unset ETag
&nbsp;
# 1 YEAR
&lt;FilesMatch &quot;\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$&quot;&gt;
Header set Cache-Control &quot;public&quot;
Header set Expires &quot;Thu, 15 Apr 2010 20:00:00 GMT&quot;
Header unset Last-Modified
&lt;/FilesMatch&gt;
&nbsp;
# 2 HOURS
&lt;FilesMatch &quot;\.(html|htm|xml|txt|xsl)$&quot;&gt;
Header set Cache-Control &quot;max-age=7200, must-revalidate&quot;
&lt;/FilesMatch&gt;
&nbsp;
# CACHED FOREVER
# MOD_REWRITE TO RENAME EVERY CHANGE
&lt;FilesMatch &quot;\.(js|css)$&quot;&gt;
Header set Cache-Control &quot;public&quot;
Header set Expires &quot;Thu, 15 Apr 2010 20:00:00 GMT&quot;
Header unset Last-Modified
&lt;/FilesMatch&gt;</pre>
<div class='presskit'><h3>High Resolution Press Images:</h3>[+] <a href='http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?src=http://uploads.askapache.com/2007/09/speed-cache-control-on.thumbnail.png&down=true'>speed-cache-control-on.thumbnail.png</a><br />[+] <a href='http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?src=http://uploads.askapache.com/2007/09/speed-cache-control-off.png&down=true'>speed-cache-control-off.png</a><br />[+] <a href='http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?src=http://uploads.askapache.com/2007/09/speed-cache-control-on.png&down=true'>speed-cache-control-on.png</a><br /></div><p><a href="http://www.askapache.com/htaccess/apache-speed-cache-control.html"></a><a href="http://www.askapache.com/htaccess/apache-speed-cache-control.html">Speed Tips: Add Cache-Control Headers</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/apache-speed-cache-control.html/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Preload flash .flv files into browser cache</title>
		<link>http://www.askapache.com/htaccess/preload-and-cache-flash-flv-files.html</link>
		<comments>http://www.askapache.com/htaccess/preload-and-cache-flash-flv-files.html#comments</comments>
		<pubDate>Mon, 04 Feb 2008 14:15:06 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Cache]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[404 Not Found]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[Backups]]></category>
		<category><![CDATA[Bandwidth]]></category>
		<category><![CDATA[Boot]]></category>
		<category><![CDATA[Cache-Control]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[FilesMatch]]></category>
		<category><![CDATA[Flash Actionscript]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[HTTP Headers]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Logs]]></category>
		<category><![CDATA[Mod_Rewrite]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[preload]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[Rewrite Tricks]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[SPEED]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[stat]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Wireshark]]></category>

		<guid isPermaLink="false">http://www.askapache.com.com/htaccess/preload-and-cache-flash-flv-files.html</guid>
		<description><![CDATA[<p>How I was able to <a href="http://www.askapache.com/htaccess/preload-and-cache-flash-flv-files.html">preload many flash flv and swf files</a> on one of my clients sites that has a lot of online video and relatively small traffic.  Their site visitors would usually watch 3-10 videos per visit and so to make the videos load almost instantly on every page I came up with a way to preload the top 10 .flv files and the swf flv player files as soon as the visitor successfully started watching the 1st video.  Of course I also setup .htaccess caching on the server so that once they downloaded the files into their cache they would never request them from the server again.  I was having fun with this so its pretty funky and uses some really cool combinations of javascript, swf preloader from xml, css classes to help automate it all..</p>

]]></description>
			<content:encoded><![CDATA[<div class='images'></div><p><img class="IFR" src='http://uploads.askapache.com/2007/12/flashplayer.gif' alt='Adobe Flash Positioning' title="flashplayer web cache" /><strong>Found a great way to preload and cache flash</strong> .flv video files.  Recently (<em>2006</em>) I was hired as the lead web-designer for an insurance company website with over 30 online videos to be placed throughout the site.  My area of expertise when it comes to Web Development is web-standards, and pretty much anything else open-source, <em>NOT</em> flash.  I started programming Flash back when it first came out, version 1.x, (and I think it was called something else..) because I was learning it for my job at the ISP..  The main reason I don&#8217;t spend my time learning it (although actionscript is very very rad) is because I&#8217;m not a designer.  I don&#8217;t have the patience for colors and images and effects, that&#8217;s boring to me, especially because I&#8217;m not gifted in the art department.<br class="C" /></p>
<p>My employer is a video production firm, so I use flash (for video and small Advertisements and logos) on pretty much every site I work on, now&#8230; this article shows what I learned while building the insurance site and the solutions we came up with for it.</p>
<p class="enote"><strong>Note:</strong> This site had only 50-100 site visitors/day and each visitor typically viewed 3-10 of the videos, so this type of aggressive caching and bandwidth-raising techniques should be looked at on a site-by-site basis.</p>
<hr />
<p>After using the site for a month I noticed that 8 of the 30 videos on the site were being using by almost every site visitor.  To speed up the site I created a very small swf (<em>flash 7</em>) file that uses very minimal actionscript to preload flvs specified in a preloadlist.xml file</p>
<p>Any page that I want the <strong>flv files to be preloaded</strong> I have to have an element with an id of &#8220;preloading&#8221; or the javascript does not load the swf file.  So I set it up so that the preloading only happens when visitors goto the homepage (where they typically land), and also only when visitors <strong>haven&#8217;t already preloaded the flvs</strong>.  To check for this I set a cookie when the flvs are preloaded.</p>
<p class="anote">Note there is a newer/briefer <a href="http://www.askapache.com/flash/preloading-caching-flv-mp3.html">update to this technique</a>.</p>
<hr class="C" />
<h2>CSS for preloading</h2>
<p>If you give an element a <code>display:none</code> css attribute, it doesn&#8217;t work for everyone.  Once the swf loads you can of course change it to none as the preloader initiates the requests onload.</p>
<pre>#preloading {position:absolute; bottom:0;left:0; display:block; width:1px; height:1px; overflow:hidden; z-index:1;}</pre>
<h2>XHTML for preloading</h2>
<p>This just starts the preloadflv function AFTER the HTML file has been loaded&#8230; (nowadays I ONLY do unobtrusive javascript and keep everything in an external .js)  Also note that some browsers/flash versions need the preloading span element to be at the top of the html if your html page scrolls down past the window&#8217;s viewable area.</p>
<pre>&lt;body onload=&quot;preloadflv();&quot;&gt;
&lt;span id=&quot;preloading&quot;&gt;&lt;/span&gt;</pre>
<hr class="C" />
<h2>Actionscript for preloadflv.fla</h2>
<p>This is literally the whole file, I spent weeks researching to come up with this optimized and customized swf prefloader.  One useful feature is by using the external .xml file you can preload any files dynamically.  Just make sure you setup the caching correctly, don&#8217;t cache the xml file for very long!  To really appreciate this preloader you should definately use an HTTP capture program like <a href="http://wireshark.askapache.com/">WireShark</a> and also watch your Apache access logs on your server.</p>
<pre>var netPath:NetConnection = new NetConnection();
netPath.connect(null);
var ncPreLD:NetStream = new NetStream(netPath);
var i:Number = 1;
var preloaderXML:XML = new XML();
preloaderXML.ignoreWhite = true;
preloaderXML.onLoad = function(success:Boolean):Void  {
  if (success) {
    var flvFiles:Array = preloaderXML.firstChild.childNodes;
    var flvDir:String = preloaderXML.firstChild.attributes.basedir;
    ncPreLD.play(flvDir+preloaderXML.firstChild.childNodes[0].attributes.path+&quot;.flv&quot;);
    ncPreLD.onStatus = function(infoObject:Object):Void  {
      if (infoObject.code == &quot;NetStream.Play.Start&quot;) {
        ncPreLD.pause();
        if (i&lt;flvFiles.length) {
          ncPreLD.play(flvDir+preloaderXML.firstChild.childNodes[i].attributes.path+&quot;.flv&quot;);
          i++;
        }
      }
    };
  }
};
preloaderXML.load(&quot;preloadlist.xml&quot;);</pre>
<hr class="C" />
<h2>XML file preloadlist.xml</h2>
<p>Save this file in the directory of your preloader (unless you modify the .fla) and basically just list all the files to preload from the basedir url.</p>
<pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;preloader basedir=&quot;http://static.askapache.com/f/flv/&quot;&gt;
  &lt;flv path=&quot;404-error-page.flv
  &lt;flv path=&quot;404-google-plugin.flv
  &lt;flv path=&quot;anonymous.flv
  &lt;flv path=&quot;create-boot-ini.flv
  &lt;flv path=&quot;install-recovery-console.flv
  &lt;flv path=&quot;mysql-backup-script.flv
  &lt;flv path=&quot;php-ajax-shell.flv
  &lt;flv path=&quot;setup-recovery-console.flv
&lt;/preloader&gt;</pre>
<h3>NetStream</h3>
<h4>The NetStream.onStatus</h4>
<dl>
<dt>NetStream.Buffer.Empty</dt>
<dd>statusData is not being received quickly enough to fill the buffer. Data flow will be interrupted until the buffer refills, at which time a NetStream.Buffer.Full message will be sent and the stream will begin playing again.</dd>
<dt>NetStream.Buffer.Full</dt>
<dd>status The buffer is full and the stream will begin playing.</dd>
<dt>NetStream.Buffer.Flush</dt>
<dd>status Data has finished streaming, and the remaining buffer will be emptied.</dd>
<dt>NetStream.Play.Start </dt>
<dd>status Playback has started.</dd>
<dt>NetStream.Play.Stop</dt>
<dd>status Playback has stopped.</dd>
<dt>NetStream.Play.StreamNotFound</dt>
<dd>error The FLV passed to the play() method can&#8217;t be found.</dd>
<dt>NetStream.Seek.InvalidTime</dt>
<dd>error For video downloaded with progressive download, the user has tried to seek or play past the end of the video data that has downloaded thus far, or past the end of the video once the entire file has downloaded. The message.details property contains a time code that indicates the last valid position to which the user can seek.</dd>
<dt>NetStream.Seek.Notify</dt>
<dd>status The seek operation is complete.</dd>
</dl>
<h2>.htaccess flash and flv</h2>
<p>Make sure apache sends the correct content-type headers with the swf and flv files</p>
<pre>AddType video/x-flv .flv
AddType application/x-shockwave-flash .swf</pre>
<h2>Implement HTTP Caching</h2>
<p>Please see: <a href="http://www.askapache.com/htaccess/mod_rewrite-fix-for-caching-updated-files.html">.htaccess Caching Tutorial</a></p>
<pre># 1 YEAR
&lt;FilesMatch &quot;\.(ico|pdf|flv)$&quot;&gt;
Header set Expires &quot;Mon, 27 Mar 2038 20:59:12 GMT&quot;
Header set Cache-Control &quot;max-age=29030400&quot;
&lt;/FilesMatch&gt;
# 1 WEEK
&lt;FilesMatch &quot;\.(jpg|jpeg|png|gif|swf)$&quot;&gt;
Header set Cache-Control &quot;max-age=604800&quot;
&lt;/FilesMatch&gt;
# 3 HOUR
&lt;FilesMatch &quot;\.(css|xml|txt|js|html)$&quot;&gt;
Header set Cache-Control &quot;max-age=10800,must-revalidate&quot;
&lt;/FilesMatch&gt;</pre>
<p><a href="http://www.askapache.com/htaccess/preload-and-cache-flash-flv-files.html"></a><a href="http://www.askapache.com/htaccess/preload-and-cache-flash-flv-files.html">Preload flash .flv files into browser cache</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/preload-and-cache-flash-flv-files.html/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Skeleton .htaccess file for Powweb Hosting</title>
		<link>http://www.askapache.com/htaccess/powweb-htaccess.html</link>
		<comments>http://www.askapache.com/htaccess/powweb-htaccess.html#comments</comments>
		<pubDate>Fri, 11 Jan 2008 09:05:51 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[Webmaster]]></category>
		<category><![CDATA[301 Redirect]]></category>
		<category><![CDATA[401]]></category>
		<category><![CDATA[403 Forbidden]]></category>
		<category><![CDATA[404 Not Found]]></category>
		<category><![CDATA[500]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[Cache-Control]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[DreamHost]]></category>
		<category><![CDATA[errordocument]]></category>
		<category><![CDATA[Examples]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[FilesMatch]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Htpasswd]]></category>
		<category><![CDATA[HTTP Headers]]></category>
		<category><![CDATA[Mod_Rewrite]]></category>
		<category><![CDATA[Mod_Setenvif]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Powweb]]></category>
		<category><![CDATA[Redirect]]></category>
		<category><![CDATA[Rewrite Tricks]]></category>
		<category><![CDATA[rewritecond]]></category>
		<category><![CDATA[rewriterule]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[SetEnvIf]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.askapache.com/htaccess/powweb-htaccess.html</guid>
		<description><![CDATA[<p><a href='http://uploads.askapache.com/2008/02/pow_head_logo.gif' title='Powweb Web Hosting'><img src='http://uploads.askapache.com/2008/02/pow_head_logo.gif' alt='Powweb Web Hosting' /></a>If you have a Powweb Webhosting account, you will appreciate this simple skeleton .htaccess file for use on their systems.<br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<div class='images'><a href='http://uploads.askapache.com/2008/02/pow_head_logo.gif'><img src="http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?fltr=usm&src=http://uploads.askapache.com/2008/02/pow_head_logo.gif&w=400" title=" apache" alt="Skeleton .htaccess file for Powweb Hosting" /></a></div><p><a class="IFL" href='http://uploads.askapache.com/2008/02/pow_head_logo.gif' title='Powweb Web Hosting'><!-- IMAGE REMOVED BY wp-image-resizer HERE --></a> One thing that can come in reallly handy if you are in charge of mutliple websites, often adding new ones is a template .htaccess file.  Especially for a webhost like Powweb, which is perfect for ordinary people who want a web site.  Normally I would recommend DreamHost, but maybe more on that later.</p>
<h2>A .htaccess Template For Powweb</h2>
<p>Pretty short and to the point, mostly useful for newcomers to apache to have a system whereby they know where stuff should go and how it goes together.  This is how I like to do it on Powweb.</p>
<h2>Download .htaccess file</h2>
<ol>
<li><a href='http://uploads.askapache.com/2008/04/sample-powweb-htaccess.txt'>Powweb .htaccess</a></li>
<li><a href='http://uploads.askapache.com/2008/04/htaccess-sample.txt'>htaccess-sample</a></li>
</ol>
<pre>#&gt; http://www.askapache.com/htaccess/htaccess.html &lt;#
&nbsp;
##############################################
#            DEFAULT SETTINGS                #
##############################################
Options +All +ExecCGI -Indexes
DirectoryIndex index.html index.php /index.php
&nbsp;
### MEDIA TYPES ###
AddType video/x-flv .flv
AddType application/x-shockwave-flash .swf
AddType application/octet-stream .chm .bz2
AddType application/vnd.ms-excel .csv
AddType application/x-pilot .prc .pdb
AddType application/x-gzip .gz
AddType image/x-icon .ico
&nbsp;
### CHARSET LANG ###
DefaultType text/html
AddDefaultCharset utf-8
AddLanguage en-us .html .htm .php .xml
&nbsp;
### SETUP ENV ###
SetEnv TZ America/Indianapolis
SetEnv SERVER_ADMIN webmaster@site.com
ServerSignature off
&nbsp;
### ERRORDOCUMENTS ###
ErrorDocument 206 /ERROR/206.html
ErrorDocument 401 /ERROR/401.html
ErrorDocument 403 /ERROR/403.html
ErrorDocument 404 /ERROR/404.html
ErrorDocument 500 /ERROR/500.html
&nbsp;
##############################################
#           HEADERS and CACHING              #
##############################################
#### CACHING ####
ExpiresActive On
ExpiresDefault A3600

# 1 MONTH
&lt;FilesMatch &quot;\.(ico|gif|jpe?g|png|flv|pdf|swf|mov|mp3|wmv|ppt)$&quot;&gt;
ExpiresDefault A2419200
Header append Cache-Control &quot;public&quot;
&lt;/FilesMatch&gt;

# 2 HOURS
&lt;FilesMatch &quot;\.(xml|txt|html|js|css)$&quot;&gt;
ExpiresDefault A7200
Header append Cache-Control &quot;private, must-revalidate&quot;
&lt;/FilesMatch&gt;

# NEVER CACHE
&lt;FilesMatch &quot;\.(php|cgi|pl|htm)$&quot;&gt;
ExpiresDefault A0
Header set Cache-Control &quot;no-store, no-cache, must-revalidate, max-age=0&quot;
Header set Pragma &quot;no-cache&quot;
&lt;/FilesMatch&gt;
&nbsp;
##############################################
#          MOD_ALIAS REDIRECTS               #
##############################################
#### PERMANENT REDIRECTS ####
Redirect 301 /all.html http://www.askapache.com/htaccess/htaccess.html
Redirect 301 /awkl http://www.askapache.com/awk/awk-tutorial.html
Redirect 301 /ben.html http://www.askapache.com/wordpress/best-adsense-optimization.html
Redirect 301 /commonly-s.html http://www.askapache.com/htaccess/commonly-used-htaccess-code-examples.html
Redirect 301 /css-backgro http://www.askapache.com/css/css-background-image-sprite.html
Redirect 301 /htacce http://www.askapache.com/htaccess/feedsmith-htaccess.html
&nbsp;
### PERMANENT REDIRECTMATCH ###
RedirectMatch 301 ^/([\(]+)(.*)$ http://www.askapache.com/
RedirectMatch 301 ^/(.+)\.htm$ http://www.askapache.com/$1.html
RedirectMatch 301 ^/(.+)\.html/$ http://www.askapache.com/$1.html
RedirectMatch 301 ^/(.+)/\.html$ http://www.askapache.com/$1/
RedirectMatch 301 ^/&amp;amp(.*)$ http://www.askapache.com/
&nbsp;
#### TEMPORARY REDIRECTS ####
Redirect 307 /about/feeds/ http://feeds.askapache.com/apache/htaccess
Redirect 307 /about/feeds/it/ http://feeds.askapache.com/apache/htaccess
Redirect 307 /apachesearch/ http://google.com/coop/cse?cx=002660089121042511758%3Akk7rwc2gx0i
Redirect 307 /apachecsetest/ http://google.com/coop/cse?cx=002660089121042511758%3Akk7rwc2gx0i
&nbsp;
#### TEMPORARY REDIRECTMATCH ####
RedirectMatch 307 ^/(.*)//(.*)$ http://www.askapache.com/$1/$2
RedirectMatch 307 ^//(.*)$ http://www.askapache.com/$1
RedirectMatch 307 ^/(.*)askapache(.*)askapache(.*)$ http://www.askapache.com/
&nbsp;
##############################################
#          MOD_REWRITE REWRITES              #
##############################################
RewriteEngine On
RewriteBase /
&nbsp;
### REQUIRE WWW ###
RewriteCond %{HTTP_HOST} !^www\.site\.com$ [NC]
RewriteRule ^(.*)$ http://www.site.com/$1 [R=301,L]
&nbsp;
### CACHEABLE FILES
RewriteRule ^z/j/site-([0-9]+)\.js$ /z/j/site.js [L]
RewriteRule ^z/c/site-([0-9]+)\.css$ /z/c/site.css [L]
&nbsp;
##############################################
#          MOD_SETENVIF VARIABLES            #
##############################################
SetEnvIfNoCase Remote_Host &quot;(.*)&quot; ASKAPACHE_HOST=$1
SetEnvIfNoCase Remote_Addr &quot;(.*)&quot; ASKAPACHE_REMOTE_ADDR=$1
SetEnvIfNoCase Server_Addr &quot;(.*)&quot; ASKAPACHE_SERVER_ADDR=$1
SetEnvIf Request_Method &quot;(.*)&quot; ASKAPACHE_REQUEST_METHOD=$1
SetEnvIf Request_Protocol &quot;(.*)&quot; ASKAPACHE_REQUEST_PROTOCOL=$1
SetEnvIf Request_URI &quot;(.*)&quot; ASKAPACHE_REQUEST_URI=$1
SetEnvIf Remote_Addr 208\.113\.183\.103 REMOTE_HOST=www.askapache.com
&nbsp;
#&gt; http://www.askapache.com/htaccess/htaccess.html &lt;#</pre>
<pre>#            DEFAULT SETTINGS                #
##############################################
Options +All +ExecCGI -Indexes
DirectoryIndex index.html index.php
SetEnv TZ America/Indianapolis
#SetEnv SERVER_ADMIN webmaster@askapache.com
ServerSignature Off
#
AddType video/x-flv .flv
AddType application/x-shockwave-flash .swf
AddType image/x-icon .ico
#
#AddHandler php-cgi .php
#Action php-cgi /cgi-bin/php5.cgi
#
&lt;FilesMatch &quot;\.(html|htm)$&quot;&gt;
AddDefaultCharset utf-8
DefaultLanguage en-us
&lt;/FilesMatch&gt;
&nbsp;
AuthName &quot;Blog&quot;
Require user admin
AuthUserFile /home/users/web/b646/pow.askapache/.htpasswd
AuthType basic

&nbsp;
#                  CACHING                   #
##############################################
#   YEAR
&lt;FilesMatch &quot;\.(ico|gif|jpg|jpeg|png|flv)$&quot;&gt;
Header set Cache-Control &quot;max-age=29030400&quot;
&lt;/FilesMatch&gt;
#   MONTH
&lt;FilesMatch &quot;\.(js|css|pdf|txt|swf)$&quot;&gt;
Header set Cache-Control &quot;max-age=2592000&quot;
&lt;/FilesMatch&gt;
#   HOUR
&lt;FilesMatch &quot;\.(html|htm)$&quot;&gt;
Header set Cache-Control &quot;max-age=3600&quot;
&lt;/FilesMatch&gt;
#   DONT CACHE</pre>
<div class='presskit'><h3>High Resolution Press Images:</h3>[+] <a href='http://www.askapache.com/wp-content/plugins/wp-image-resizer/thumb/phpThumb.php?src=http://uploads.askapache.com/2008/02/pow_head_logo.gif&down=true'>pow_head_logo.gif</a><br /></div><p><a href="http://www.askapache.com/htaccess/powweb-htaccess.html"></a><a href="http://www.askapache.com/htaccess/powweb-htaccess.html">Skeleton .htaccess file for Powweb Hosting</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/powweb-htaccess.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Random Bits, the podcast that gives you an insiders view</title>
		<link>http://www.askapache.com/web-design/random-bits-podcast.html</link>
		<comments>http://www.askapache.com/web-design/random-bits-podcast.html#comments</comments>
		<pubDate>Tue, 09 Oct 2007 04:31:34 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Review]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[500]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Elite]]></category>
		<category><![CDATA[Examples]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[Logs]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Nice]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.askapache.com/web-design/random-bits-podcast.html</guid>
		<description><![CDATA[<p>I was over at <a href="http://alexking.org/projects/wordpress">Alex King's</a> blog today checking out his mobile web plugin for wordpress and I noticed some fresh podcasts from some of the industry's finest.  The feeds are .mp3 and are easy to find and browse on the search-this.com site.  They have some pretty nice articles over there as well..</p>]]></description>
			<content:encoded><![CDATA[<div class='images'></div><h3><a href="http://www.search-this.com/random-bits" title="Link to original website">Search-This presents Random Bits, the podcast that gives you an insiders view into the personalities behind the web</a></h3>
<p>I was over at <a href="http://alexking.org/projects/wordpress">Alex King&#8217;s</a> blog today checking out his mobile web plugin for wordpress and I noticed some fresh podcasts from some of the industry&#8217;s finest.  The feeds are .mp3 and are easy to find and browse on the search-this.com site.  They have some pretty nice articles over there as well..<br class="C" /></p>
<blockquote><h3><a href="http://www.search-this.com/2007/10/08/random-bits-podcast-with-alex-king/">Random Bits Podcast with <strong>Alex King</strong> &#8211; Episode 11</a></h3>
<p>Interview with Alex King &#8211; a WordPress developer, WordPress plugin developer, ShareThis creator and web designer.</p>
<h3><a href="http://www.search-this.com/2007/09/17/random-bits-podcast-with-eric-meyer-part-2/">Random Bits Podcast with <strong>Eric Meyer</strong>, Part 2 &#8211; Episode 10</a></h3>
<p>Part 2 of a conversation with CSS master Eric Meyer. Eric has written several books on CSS (including &#8220;Cascading Style Sheets: The Definitive Guide&#8221; for O&#8217;Reilly and Associates), founded the css-discuss mailing list, maintained CSS support charts, and presented at a wide variety of conferences.</p>
<h3><a href="http://www.search-this.com/2007/09/03/random-bits-podcast-with-eric-meyer/">Random Bits Podcast with <strong>Eric Meyer</strong>, Part 1 &#8211; Episode 9</a></h3>
<p>A conversation with CSS master Eric Meyer.</p>
</blockquote>
<hr class="HR0" />
<blockquote><h3><a href="http://www.search-this.com/2007/08/20/random-bits-podcast-with-chris-garrett-part-2/">Random Bits Podcast with Chris Garrett, Part 2 &#8211; Episode 8</a></h3>
<p>Part 2, Chris Garrett is a professional blogger and in this podcast he shares his blogging experience.</p>
<h3><a href="http://www.search-this.com/2007/08/06/random-bits-podcast-with-chris-garrett-part-1/">Random Bits Podcast with Chris Garrett, Part 1 &#8211; Episode 7</a></h3>
<p>Chris Garrett is a professional blogger and in this podcast he shares his blogging experience.</p>
<h3><a href="http://www.search-this.com/2007/07/16/random-bits-podcast-with-craig-newmark/">Random Bits Podcast with Craig Newmark &#8211; Episode 6</a></h3>
<p>Craig took the time to have a phone call with me last week and not only is he the brains behind craigslist; but he is also the heart behind it. Craig tells us some reasons why he feels craigslist has grown as much as it has and why it will continue to do us. Listen to this interesting podcast and learn a little more about the man behind the list.</p>
</blockquote>
<hr class="HR0" />
<blockquote><h3><a href="http://www.search-this.com/2007/07/02/random-bits-podcast-with-lee-dodd/">Random Bits Podcast with Lee Dodd &#8211; Episode 5</a></h3>
<p>Lee Dodd is very well known in the web industry for being a successful community owner and has recently branched out into teaching!</p>
<p>Lee shares some tips on community building and gives us personal examples with which we can relate. One of Lee&#8217;s tips is to not monetize a community (or any website for that matter) until you reach at least 500 visits a day! I hadn&#8217;t really looked at things that way. Lee also talks about the elite retreat and who can benefit from attending such an event!</p>
<h3><a href="http://www.search-this.com/2007/06/11/random-bits-podcast-with-peter-flaschner/">Random Bits Podcast with Peter Flaschner &#8211; Episode 4</a></h3>
<p>I have been a fan of TheBlogStudio.com and their business model for over a year now so I jumped at the opportunity to interview Peter!</p>
<p>Peter is someone who has experience in running a business in the Brick and Mortar sense, and he took his dream of an online business and made it a reality. He points out some great things to consider when starting an online business. The Blog Studio is a web development company based in Toronto, who work globally! They have set themselves apart from other web dev firms by targeting a niche market which we discuss. Have a listen and enjoy some of his insight!</p>
<h3><a href="http://www.search-this.com/2007/05/28/random-bits-podcast-with-matt-mickiewicz-and-mark-harbottle-of-sitepointcom/">Random Bits Podcast with Sitepoint Founders, Matt Mickiewicz and Mark Harbottle &#8211; Episode 3</a></h3>
<p>In this interview, Matt Mickiewicz and Mark Harbottle tell us how SitePoint.com started and how it grew from its grassroots to the thriving web community it is today. They really do demonstrate why the forum has retained such a community feel by showing that members come first.</p>
</blockquote>
<hr class="HR0" />
<blockquote><h3><a href="http://www.search-this.com/2007/05/14/random-bits-podcast-with-dan-mccomb/">Random Bits Podcast with Dan McComb, Co-founder of Biznik.com &#8211; Episode 2</a></h3>
<p>If you do not know Dan, you soon will. Dan is the co-founder of Biznik.com, a site that offers Business Networking that Doesnt Suck. Biznik.com is growing rapidly from a local Seattle group to a global community and it is definitely getting noticed. Biznik is hosting Seattles first indie business conference, BizJam on June 9, 2007. If you are in the Seattle area, definitely check it out.</p>
<h3><a href="http://www.search-this.com/2007/04/30/random-bits-podcast-with-rand-fishkin/">Random Bits Podcast with Rand Fishkin, SEOmoz.org &#8211; Episode 1</a></h3>
<p>In this, our inaugural podcast, we talk with Rand Fishkin &#8211; Search Engine Optimization specialist for SEOmoz.org. Rand gives some optimization advice to help you optimize your website. He also explains the new Premium Membership that SEOmoz.org now offers and finishes with a few personal questions! Who knew that Rand Fishkin would be iPod-less!</p>
</blockquote>
<p><a href="http://www.askapache.com/web-design/random-bits-podcast.html"></a><a href="http://www.askapache.com/web-design/random-bits-podcast.html">Random Bits, the podcast that gives you an insiders view</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/web-design/random-bits-podcast.html/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Speed Tips: Use Multiple SubDomains</title>
		<link>http://www.askapache.com/htaccess/apache-speed-subdomains.html</link>
		<comments>http://www.askapache.com/htaccess/apache-speed-subdomains.html#comments</comments>
		<pubDate>Mon, 17 Sep 2007 23:50:09 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[DreamHost]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[Linux Unix BSD]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Webmaster]]></category>
		<category><![CDATA[500]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[Cache-Control]]></category>
		<category><![CDATA[compression]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[DNS]]></category>
		<category><![CDATA[Elite]]></category>
		<category><![CDATA[Etags]]></category>
		<category><![CDATA[expires header]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[HTTP Headers]]></category>
		<category><![CDATA[Last-Modified]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[SPEED]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[stat]]></category>
		<category><![CDATA[Web Hosting]]></category>

		<guid isPermaLink="false">http://www.askapache.com/htaccess/apache-speed-subdomains.html</guid>
		<description><![CDATA[<p><strong>To make your site even faster, serve certain content from different subdomains</strong>. The reason this works is amazingly cool!</p>]]></description>
			<content:encoded><![CDATA[<div class='images'></div><p><strong>To make your site even faster, serve certain content from different subdomains</strong>.  For instance, on this site I serve <em>(html, favicon, etc.)</em> from <code>www.askapache.com</code>, <em>(css, js, images, uploads, etc.)</em> from <code>static.askapache.com</code>, and <em>(flash, flv, swf, movies, mp3, etc.)</em> from <code>f.askapache.com</code>.  The reason this works is amazingly cool!<br class="C" /></p>
<p><strong>Easy Apache Speed Tips Articles</strong></p>
<ul>
<li><a href="http://www.askapache.com/htaccess/apache-speed-compression.html" title="Turn On gzip Compression to Speed Up Apache">Turn On Compression</a></li>
<li><a href="http://www.askapache.com/htaccess/apache-speed-expires.html" title="Add Far Future Expires Headers to Speed Up Your Site">Add Future Expires Header</a></li>
<li><a href="http://www.askapache.com/htaccess/apache-speed-cache-control.html" title="Cache-Control Headers using Apache and .htaccess">Add Cache-Control Headers</a></li>
<li><a href="http://www.askapache.com/htaccess/apache-speed-etags.html" title="Remove ETag Headers to Speed up Apache">Turn Off ETags</a></li>
<li><a href="http://www.askapache.com/htaccess/apache-speed-last-modified.html" title="Remove the Last-Modified Header from Files to Speed Apache">Remove Last-Modified Header</a></li>
<li><a href="http://www.askapache.com/htaccess/apache-speed-subdomains.html" title="Multiple Subdomains for a Quicker and Faster Web Site">Use Multiple SubDomains</a></li>
</ul>
<p class="anote">A subdomain is the part of a domain that is appended to the beginning of the domain name, like a prefix. For example, my domain is &#8220;<code>askapache.com</code>,&#8221; and 3 subdomains I am using are &#8220;<code>www.askapache.com</code>,&#8221; &#8220;<code>static.askapache.com</code>,&#8221; and &#8220;<code>f.askapache.com</code>&#8220;.</p>
<h2>Speed Benefits of Multiple Subdomains</h2>
<p>Basically when a visitor comes to http://www.askapache.com/htaccess/htaccess.html, they make a DNS request for each of my 3 subdomains <code>[www/z/f].askapache.com</code> to translate them into IP addresses.  These hostname to IP address translations are then cached for that visitor, so no more DNS requests are needed.  Because the first request was for http://www.askapache.com/htaccess/htaccess.html, the browser requests the .html document from the <strong>www server</strong> first.  In the .html document the browser is told to also retrieve .css and .js files from my <strong>z server</strong>.  In the .js file I load some flash which tells the browser to fetch the flash from my <strong>f server</strong>.  So the users are able to see the content (.html) first, but thats not the only benefit to using these subdomains.</p>
<h3>Subdomain Persistant Connections Benefits</h3>
<p>The other benefit to using these subdomains is brilliant.  Instead of a browser having to make 30 tcp connections to my <strong>www server</strong> to download everything, a browser is instead instructed to download 3 items from my <strong>www server</strong>, 22 items from my <strong>z server</strong>, and 5 items from my <strong>f server</strong>.  So instead of waiting for 30 items from 1 source, it waits for 30 items from 3 different sources, drastically speeding up the transfer.  By using multiple subdomains browsers are further able to maintain persistant connections with all 3 unique servers, making the site load incredibly faster.</p>
<p>Please read about <a href="http://rfc.askapache.com/rfc2616/rfc2616-sec8.html">Persistant Connections</a> for more info.</p>
<h2>Start using Subdomains</h2>
<p>If you are an incredibly savvy and experienced web developer, no doubt you already have a DreamHost account, and so you already have the ability to add as many subdomains (for free) that you want.  I think the limit per domain is 2500.</p>
<p class="anote">If you don&#8217;t have DreamHost, it&#8217;s never to late to start experiencing what the elite webmaster already has.  For user and editorial reviews of DreamHost and other web hosts, check out <a href="http://www.webhostingsearch.com/">Web Hosting Search</a></p>
<p><a href="http://www.askapache.com/htaccess/apache-speed-subdomains.html"></a><a href="http://www.askapache.com/htaccess/apache-speed-subdomains.html">Speed Tips: Use Multiple SubDomains</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/apache-speed-subdomains.html/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Downloading Multiple Files with Curl Simultaneously</title>
		<link>http://www.askapache.com/php/curl-multi-downloads.html</link>
		<comments>http://www.askapache.com/php/curl-multi-downloads.html#comments</comments>
		<pubDate>Wed, 05 Sep 2007 07:24:37 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[301 Redirect]]></category>
		<category><![CDATA[404 Not Found]]></category>
		<category><![CDATA[503]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[askapache]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[GET]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[Mod_Rewrite]]></category>
		<category><![CDATA[Redirect]]></category>
		<category><![CDATA[Rewrite Tricks]]></category>
		<category><![CDATA[rewritecond]]></category>
		<category><![CDATA[Robot]]></category>
		<category><![CDATA[robots]]></category>
		<category><![CDATA[Socket]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[stat]]></category>

		<guid isPermaLink="false">http://www.askapache.com/php/curl-multi-downloads.html</guid>
		<description><![CDATA[<p>Wouldn't it be great if you could use php and curl to download multiple files simultaneously using built-in curl functions?  You can!</p>]]></description>
			<content:encoded><![CDATA[<div class='images'></div><p>Wouldn&#8217;t it be great if you could use php and curl to download multiple files simultaneously using built-in curl functions?  You can!</p>
<hr />
<h2>Example Code</h2>
<p>Note that this won&#8217;t work out of the box or anything, I was passing this function an array containing a bunch of mod_rewrite variables, but you can get an idea of how to use the code.</p>
<pre>function curlit_rewritecond($U,$pass){
    global $RPASS,$RSITE;
  $RPASS=$pass;

    $FF_HDR=array(&quot;Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5&quot;,
  &quot;Accept-Language: en-us,en;q=0.9,de;q=0.8,ja;q=0.8,zh;q=0.7,zh-cn;q=0.6,nl;q=0.5,fr;q=0.5,it;q=0.4,ko;q=0.3,es;q=0.2,ru;q=0.2,pt;q=0.1&quot;,
  &quot;Accept-Encoding: gzip,deflate&quot;,&quot;Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7&quot;,&quot;Keep-Alive: 300&quot;,&quot;Connection: keep-alive&quot;,&quot;Pragma:&quot;);

    if($fp = tmpfile()){
        $mh = curl_multi_init();
        foreach ($U as $i =&gt; $ur) {
      $url=$RSITE.&#039;?Q=&#039;.$ur;
            if (!$url_info = parse_url($url)) die(&#039;bad url &#039;.$url);
            $ch[$i] = curl_init($url);
            curl_setopt ($ch[$i], CURLOPT_HEADERFUNCTION, &#039;aacurlheader&#039;);
            curl_setopt ($ch[$i], CURLOPT_HEADER, 1);
            curl_setopt ($ch[$i], CURLOPT_VERBOSE, 0);
            curl_setopt ($ch[$i], CURLOPT_NOBODY, 1);
            curl_setopt ($ch[$i], CURLOPT_CUSTOMREQUEST, &#039;GET&#039;);
            curl_setopt ($ch[$i], CURLOPT_STDERR, $fp);
            curl_setopt ($ch[$i], CURLOPT_FAILONERROR, 0);
            curl_setopt ($ch[$i], CURLOPT_FOLLOWLOCATION, 0);
            curl_setopt ($ch[$i], CURLOPT_USERAGENT, &#039;Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7 (via www.askapache.com)&#039;);
            curl_setopt ($ch[$i], CURLOPT_INTERFACE, &#039;208.86.158.195&#039;);
            curl_setopt ($ch[$i], CURLOPT_HTTPHEADER, $FF_HDR);
            curl_setopt ($ch[$i], CURLOPT_REFERER, &#039;http://www.askapache.com&#039;);
            curl_setopt ($ch[$i], CURLOPT_ENCODING, 0);
            curl_setopt ($ch[$i], CURLOPT_CONNECTTIMEOUT, 45);
            curl_setopt ($ch[$i], CURLOPT_MAXCONNECTS, 5);
            curl_setopt ($ch[$i], CURLOPT_MAXREDIRS, 0);
            curl_multi_add_handle ($mh,$ch[$i]);
        }
        do { ob_start();$r=curl_multi_exec($mh,$active);$t=ob_get_clean();}
    while($r == CURLM_CALL_MULTI_PERFORM || $active);
    if ($r != CURLM_OK) die(&quot;Curl multi read error $r&quot;);
        foreach ($U as $i =&gt; $url) {
      if (curl_errno($ch[$i])) {echo curl_error($ch[$i]).&quot;-&quot;.curl_errno($ch[$i]);}
      //else $cch=curl_getinfo($ch[$i]);
            curl_multi_remove_handle($mh,$ch[$i]);
            curl_close($ch[$i]);
        }
        curl_multi_close($mh);
        fclose($fp);
    }
  sleep(1);
  return true;
}</pre>
<h2>php code example 2</h2>
<p>This code will download all the files listed in the <code>$urls</code> array to the folder specified by the <code>$saveto</code> variable.</p>
<pre>&lt;?php
&nbsp;
$urls=array(
&#039;http://f.askapache.com/mp3/12-lessons-for-those-afraid-of-css.mp3&#039;,
&#039;http://f.askapache.com/mp3/27-request-methods-for-use-with-apache-and-rewritecond-and-htaccess.mp3&#039;,
&#039;http://f.askapache.com/mp3/301-redirect-with-mod_rewrite-or-redirectmatch.mp3&#039;,
&#039;http://f.askapache.com/mp3/404-errorpages.mp3&#039;,
&#039;http://f.askapache.com/mp3/503-service-temporarily-unavailable.mp3&#039;,
&#039;http://f.askapache.com/mp3/adsense-robots.mp3&#039;,
&#039;http://f.askapache.com/mp3/alexa-toolbar-firefox.mp3&#039;,
&#039;http://f.askapache.com/mp3/allowing-access-from-1-static-ip-and-deny-the-rest.mp3&#039;,
&#039;http://f.askapache.com/mp3/apache-authentication-in-htaccess.mp3&#039;);
&nbsp;
$save_to=&#039;/home/user/public_html/mp3/&#039;;
&nbsp;
$mh = curl_multi_init();
foreach ($urls as $i =&gt; $url) {
    $g=$save_to.basename($url);
    if(!is_file($g)){
        $conn[$i]=curl_init($url);
        $fp[$i]=fopen ($g, &quot;w&quot;);
        curl_setopt ($conn[$i], CURLOPT_FILE, $fp[$i]);
        curl_setopt ($conn[$i], CURLOPT_HEADER ,0);
        curl_setopt($conn[$i],CURLOPT_CONNECTTIMEOUT,60);
        curl_multi_add_handle ($mh,$conn[$i]);
    }
}
do {
    $n=curl_multi_exec($mh,$active);
}
while ($active);
foreach ($urls as $i =&gt; $url) {
    curl_multi_remove_handle($mh,$conn[$i]);
    curl_close($conn[$i]);
    fclose ($fp[$i]);
}
curl_multi_close($mh);
?&gt;</pre>
<h2>Curl Multi Functions</h2>
<dl>
<dt><a href="http://www.php.net/manual/en/function.curl-multi-init.php">curl_multi_init</a></dt>
<dd>Returns a new cURL multi handle</dd>
<dt><a href="http://www.php.net/manual/en/function.curl-multi-add-handle.php">curl_multi_add_handle</a></dt>
<dd>Add a normal cURL handle to a cURL multi handle</dd>
<dt><a href="http://www.php.net/manual/en/function.curl-multi-exec.php">curl_multi_exec</a></dt>
<dd>Run the sub-connections of the current cURL handle</dd>
<dt><a href="http://www.php.net/manual/en/function.curl-multi-close.php">curl_multi_close</a></dt>
<dd>Close a set of cURL handles</dd>
<dt><a href="http://www.php.net/manual/en/function.curl-multi-getcontent.php">curl_multi_getcontent</a></dt>
<dd>Return the content of a cURL handle if CURLOPT_RETURNTRANSFER is set</dd>
<dt><a href="http://www.php.net/manual/en/function.curl-multi-info-read.php">curl_multi_info_read</a></dt>
<dd>Get information about the current transfers</dd>
<dt><a href="http://www.php.net/manual/en/function.curl-multi-select.php">curl_multi_select</a></dt>
<dd>Get all the sockets associated with the cURL extension, which can then be &#8220;selected&#8221;</dd>
<dt><a href="http://www.php.net/manual/en/function.curl-multi-remove-handle.php">curl_multi_remove_handle</a></dt>
<dd>Remove a multi handle from a set of cURL handles</dd>
</dl>
<p><a href="http://www.askapache.com/php/curl-multi-downloads.html"></a><a href="http://www.askapache.com/php/curl-multi-downloads.html">Downloading Multiple Files with Curl Simultaneously</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/php/curl-multi-downloads.html/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
<enclosure url="http://f.askapache.com/mp3/12-lessons-for-those-afraid-of-css.mp3" length="69632" type="audio/mpeg" />
<enclosure url="http://f.askapache.com/mp3/27-request-methods-for-use-with-apache-and-rewritecond-and-htaccess.mp3" length="65536" type="audio/mpeg" />
<enclosure url="http://f.askapache.com/mp3/301-redirect-with-mod_rewrite-or-redirectmatch.mp3" length="32768" type="audio/mpeg" />
<enclosure url="http://f.askapache.com/mp3/404-errorpages.mp3" length="32768" type="audio/mpeg" />
<enclosure url="http://f.askapache.com/mp3/503-service-temporarily-unavailable.mp3" length="32768" type="audio/mpeg" />
<enclosure url="http://f.askapache.com/mp3/adsense-robots.mp3" length="32768" type="audio/mpeg" />
<enclosure url="http://f.askapache.com/mp3/alexa-toolbar-firefox.mp3" length="61440" type="audio/mpeg" />
<enclosure url="http://f.askapache.com/mp3/allowing-access-from-1-static-ip-and-deny-the-rest.mp3" length="81920" type="audio/mpeg" />
<enclosure url="http://f.askapache.com/mp3/apache-authentication-in-htaccess.mp3" length="40960" type="audio/mpeg" />
		</item>
	</channel>
</rss>
