<?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;  mod_setenvif</title>
	<atom:link href="http://www.askapache.com/search/mod_setenvif/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.askapache.com</link>
	<description>Advanced Web Development</description>
	<lastBuildDate>Thu, 26 Apr 2012 11:29:28 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Securing php.ini and php.cgi with .htaccess</title>
		<link>http://www.askapache.com/htaccess/php-cgi-redirect_status.html</link>
		<comments>http://www.askapache.com/htaccess/php-cgi-redirect_status.html#comments</comments>
		<pubDate>Fri, 25 Jun 2010 03:01:05 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Htaccess]]></category>

		<guid isPermaLink="false">http://www.askapache.com/htaccess/php-cgi-redirect_status.html</guid>
		<description><![CDATA[<p><a class="IFL hs hs18" rel="lb" href='http://uploads.askapache.com/2008/01/jail-bars-1.png' title='Locking down your php.ini and php cgi with .htaccess'></a>If you have a php.cgi or php.ini file in your /cgi-bin/ directory or other pub directory, try requesting them from your web browser.  If your php.ini shows up or worse you are able to execute your php cgi, you'll need to secure it ASAP.  This shows several ways to secure these files, and other interpreters like perl, fastCGI, bash, csh, etc.<br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/htaccess/php-cgi-redirect_status.html"></a><a href="http://www.askapache.com/htaccess/php-cgi-redirect_status.html"><cite>AskApache.com</cite></a></p><p><a class="IFL hs hs18" rel="lb" href='http://uploads.askapache.com/2008/01/jail-bars-1.png' title='Locking down your php.ini and php cgi with .htaccess'></a>To execute CGI scripts, a Web server must be able to access the interpreter used for that script.  But what if you directly request <code>site.com/cgi-bin/php.ini</code> or <code>site.com/cgi-bin/php.cgi?index.php</code>?  If either show up thats a major problem, try it on your site.<br class="C" /></p>

<p>The solution is that when you request /index.php, Apache or whatever server you are using does a subrequest/internal request to the php interpreter at <code>/cgi-bin/php.cgi</code>, and when it does an internal request like that it adds some special environment variables that are normal variables prefixed with a <code>REDIRECT_</code>.</p>


<h2>.htaccess Solution</h2>

<p>We only want internal/sub redirected requests to be allowed to access <code>/cgi-bin/php.ini</code> and <code>/cgi-bin/php.cgi</code>, and .htaccess provides several methods to achieve this type of access control.</p>

<h3>Only allow if <strong>REDIRECT_STATUS</strong> is set</h3>

<p>By using the <strong>AddHandler</strong> and <strong>Action</strong> directives below, we are setting up Apache to automatically set the REDIRECT_STATUS <em>(also PATH_TRANSLATED which is important for suEXEC among other things).</em></p>
<pre>AddHandler php-cgi .php
Action php-cgi /cgi-bin/php.cgi</pre>

<h3>Using access control</h3>

<p>Since we now know that we only want requests that have the REDIRECT_STATUS environment variable set, we can issue a 403 Forbidden to anything else.  You can place this in your /cgi-bin/.htaccess file.</p>

<pre>Order Deny,Allow
Deny from All
Allow from env=REDIRECT_STATUS</pre>

<h3>Or combine with FilesMatch</h3>

<p>This can go in your /.htaccess file and uses regex to apply to <code>php[0-9].(ini|cgi)</code></p>
<pre>&lt;filesMatch "^php5?\.(ini|cgi)$"&gt;
Order Deny,Allow
Deny from All
Allow from env=REDIRECT_STATUS
&lt;/filesMatch&gt;</pre>

<h3>Only allowing for REDIRECT_STATUS=200</h3>

<p>You may also use mod_rewrite's power to further tighten the access by only allowing for redirects with a 200 Status code.  This could come into play if your default ErrorDocuments are themselves php scripts.  An ErrorDocument 403 /error.php will have a REDIRECT_STATUS of 403.</p>

<pre>ErrorDocument 403 /error.php
&nbsp;
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^.*\.(php|cgi)$
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule .* - [F]</pre>

<h2>PHP Security Documentation</h2>

<blockquote cite="http://php.net/security.cgi-bin"> <p><a href="http://php.net/security.cgi-bin">CGI-BIN security</a></p> Using PHP as a CGI binary is an option for setups that for some reason do not wish to integrate PHP as a module into server software (like Apache), or will use PHP with different kinds of CGI wrappers to create safe chroot and setuid environments for scripts. This setup usually involves installing executable PHP binary to the web server cgi-bin directory.</blockquote>

<h2>Apache's Solution</h2>

<blockquote cite="http://httpd.apache.org/docs/trunk/custom-error.html"> Each new variable will have the prefix REDIRECT_. REDIRECT_ environment variables are created from the CGI environment variables which existed prior to the redirect, they are renamed with a REDIRECT_ prefix, i.e., HTTP_USER_AGENT becomes REDIRECT_HTTP_USER_AGENT. In addition to these new variables, Apache will define REDIRECT_URL and REDIRECT_STATUS to help the script trace its origin. Both the original URL and the URL being redirected to can be logged in the access log. </blockquote>


<h2>suEXEC "Safe" Variables list</h2>

<blockquote cite="http://httpd.apache.org/docs/trunk/suexec.html"><p><a href="http://httpd.apache.org/docs/trunk/suexec.html">suEXEC support</a></p> The <strong>suEXEC</strong> feature provides Apache users the ability to run CGI and SSI programs under user IDs different from the user ID of the calling web server. Normally, when a CGI or SSI program executes, it runs as the same user who is running the web server.

    Used properly, this feature can reduce considerably the security risks involved with allowing users to develop and run private CGI or SSI programs. However, if suEXEC is improperly configured, it can cause any number of problems and possibly create new holes in your computer's security. If you aren't familiar with managing setuid root programs and the security issues they present, we highly recommend that you not consider using suEXEC. </blockquote>

<p>From <a href="http://static.askapache.com/httpd/support/suexec.c">suexec.c</a>.</p>

<pre class='prec'>static const char *const safe_env_lst[] =
{
    /* variable name starts with */
    "HTTP_",
    "SSL_",
&nbsp;
    /* variable name is */
    "AUTH_TYPE=",
    "CONTENT_LENGTH=",
    "CONTENT_TYPE=",
    "DATE_GMT=",
    "DATE_LOCAL=",
    "DOCUMENT_NAME=",
    "DOCUMENT_PATH_INFO=",
    "DOCUMENT_ROOT=",
    "DOCUMENT_URI=",
    "GATEWAY_INTERFACE=",
    "HTTPS=",
    "LAST_MODIFIED=",
    "PATH_INFO=",
    "PATH_TRANSLATED=",
    "QUERY_STRING=",
    "QUERY_STRING_UNESCAPED=",
    "REMOTE_ADDR=",
    "REMOTE_HOST=",
    "REMOTE_IDENT=",
    "REMOTE_PORT=",
    "REMOTE_USER=",
    "REDIRECT_HANDLER=",
    "REDIRECT_QUERY_STRING=",
    "REDIRECT_REMOTE_USER=",
    "REDIRECT_STATUS=",
    "REDIRECT_URL=",
    "REQUEST_METHOD=",
    "REQUEST_URI=",
    "SCRIPT_FILENAME=",
    "SCRIPT_NAME=",
    "SCRIPT_URI=",
    "SCRIPT_URL=",
    "SERVER_ADMIN=",
    "SERVER_NAME=",
    "SERVER_ADDR=",
    "SERVER_PORT=",
    "SERVER_PROTOCOL=",
    "SERVER_SIGNATURE=",
    "SERVER_SOFTWARE=",
    "UNIQUE_ID=",
    "USER_NAME=",
    "TZ=",
    NULL
};</pre>


<h2>CERT Advisory</h2>

<blockquote cite="http://www.cert.org/advisories/CA-1996-11.html"> Many sites that maintain a Web server support CGI programs. Often these programs are scripts that are run by general-purpose interpreters, such as /bin/sh or PERL. If the interpreters are located in the CGI bin directory along with the associated scripts, intruders can access the interpreters directly and arrange to execute arbitrary commands on the Web server system.

    All programs in the CGI bin directory can be executed with arbitrary arguments, so it is important to carefully design the programs to permit only the intended actions regardless of what arguments are used. This is difficult enough in general, but is a special problem for general-purpose interpreters since they are designed to execute arbitrary programs based on their arguments. *All* programs in the CGI bin directory must be evaluated carefully, even relatively limited programs such as gnu-tar and find. </blockquote>
<h3>Impact and Solution</h3>
<blockquote cite="http://www.cert.org/advisories/CA-1996-11.html"> If general-purpose interpreters are accessible in a Web server's CGI bin directory, then a remote user can execute any command the interpreters can execute on that server.

    The solution to this problem is to ensure that the CGI bin directory does not include any general-purpose interpreters, for example: PERL, Tcl, UNIX shells (sh, csh, ksh, etc.) </blockquote>
<h2>Apache Nuts and Bolts</h2>
<p>If you really want the details, start with <a href="http://static.askapache.com/httpd/modules/http/http_request.c">modules/http/http_request.c</a> of the apache source code.</p>

<pre class='prec'>AP_DECLARE(void) ap_die(int type, request_rec *r)
{
int error_index = ap_index_of_response(type);
char *custom_response = ap_response_code_string(r, error_index);
int recursive_error = 0;
request_rec *r_1st_err = r;
&nbsp;
if (type == AP_FILTER_ERROR) {
return;
}
&nbsp;
if (type == DONE) {
ap_finalize_request_protocol(r);
return;
}
&nbsp;
/*
* The following takes care of Apache redirects to custom response URLs
* Note that if we are already dealing with the response to some other
* error condition, we just report on the original error, and give up on
* any attempt to handle the other thing "intelligently"...
*/
if (r-&gt;status != HTTP_OK) {
recursive_error = type;
&nbsp;
while (r_1st_err-&gt;prev &amp;&amp; (r_1st_err-&gt;prev-&gt;status != HTTP_OK))
r_1st_err = r_1st_err-&gt;prev;  /* Get back to original error */
&nbsp;
if (r_1st_err != r) {
/* The recursive error was caused by an ErrorDocument specifying
* an internal redirect to a bad URI.  ap_internal_redirect has
* changed the filter chains to point to the ErrorDocument&#039;s
* request_rec.  Back out those changes so we can safely use the
* original failing request_rec to send the canned error message.
*
* ap_send_error_response gets rid of existing resource filters
* on the output side, so we can skip those.
*/
update_r_in_filters(r_1st_err-&gt;proto_output_filters, r, r_1st_err);
update_r_in_filters(r_1st_err-&gt;input_filters, r, r_1st_err);
}
&nbsp;
custom_response = NULL; /* Do NOT retry the custom thing! */
}
&nbsp;
r-&gt;status = type;
&nbsp;
/*
* This test is done here so that none of the auth modules needs to know
* about proxy authentication.  They treat it like normal auth, and then
* we tweak the status.
*/
if (HTTP_UNAUTHORIZED == r-&gt;status &amp;&amp; PROXYREQ_PROXY == r-&gt;proxyreq) {
r-&gt;status = HTTP_PROXY_AUTHENTICATION_REQUIRED;
}
&nbsp;
/* If we don&#039;t want to keep the connection, make sure we mark that the
* connection is not eligible for keepalive.  If we want to keep the
* connection, be sure that the request body (if any) has been read.
*/
if (ap_status_drops_connection(r-&gt;status)) {
r-&gt;connection-&gt;keepalive = AP_CONN_CLOSE;
}
&nbsp;
/*
* Two types of custom redirects --- plain text, and URLs. Plain text has
* a leading &#039;"&#039;, so the URL code, here, is triggered on its absence
*/
if (custom_response &amp;&amp; custom_response[0] != &#039;"&#039;) {
&nbsp;
if (ap_is_url(custom_response)) {
/*
* The URL isn&#039;t local, so lets drop through the rest of this
* apache code, and continue with the usual REDIRECT handler.
* But note that the client will ultimately see the wrong
* status...
*/
r-&gt;status = HTTP_MOVED_TEMPORARILY;
apr_table_setn(r-&gt;headers_out, "Location", custom_response);
}
else if (custom_response[0] == &#039;/&#039;) {
const char *error_notes;
r-&gt;no_local_copy = 1;       /* Do NOT send HTTP_NOT_MODIFIED for
* error documents! */
/*
* This redirect needs to be a GET no matter what the original
* method was.
*/
apr_table_setn(r-&gt;subprocess_env, "REQUEST_METHOD", r-&gt;method);
&nbsp;
/*
* Provide a special method for modules to communicate
* more informative (than the plain canned) messages to us.
* Propagate them to ErrorDocuments via the ERROR_NOTES variable:
*/
if ((error_notes = apr_table_get(r-&gt;notes,
"error-notes")) != NULL) {
apr_table_setn(r-&gt;subprocess_env, "ERROR_NOTES", error_notes);
}
r-&gt;method = apr_pstrdup(r-&gt;pool, "GET");
r-&gt;method_number = M_GET;
ap_internal_redirect(custom_response, r);
return;
}
else {
/*
* Dumb user has given us a bad url to redirect to --- fake up
* dying with a recursive server error...
*/
recursive_error = HTTP_INTERNAL_SERVER_ERROR;
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"Invalid error redirection directive: %s",
custom_response);
}
}
ap_send_error_response(r_1st_err, recursive_error);
}
&nbsp;
static apr_table_t *
(apr_pool_t *p, apr_table_t *t)
{
const apr_array_header_t *env_arr = apr_table_elts(t);
const apr_table_entry_t *elts = (const apr_table_entry_t *) env_arr-&gt;elts;
apr_table_t *new = apr_table_make(p, env_arr-&gt;nalloc);
int i;
&nbsp;
for (i = 0; i &lt; env_arr-&gt;nelts; ++i) {
if (!elts[i].key)
continue;
apr_table_setn(new, apr_pstrcat(p, "REDIRECT_", elts[i].key, NULL),
elts[i].val);
}
&nbsp;
return new;
}
&nbsp;
static request_rec *internal_internal_redirect(const char *new_uri,
request_rec *r) {
int access_status;
request_rec *new;
&nbsp;
if (ap_is_recursion_limit_exceeded(r)) {
ap_die(HTTP_INTERNAL_SERVER_ERROR, r);
return NULL;
}
&nbsp;
new = (request_rec *) apr_pcalloc(r-&gt;pool, sizeof(request_rec));
&nbsp;
new-&gt;connection = r-&gt;connection;
new-&gt;server     = r-&gt;server;
new-&gt;pool       = r-&gt;pool;
&nbsp;
/*
* A whole lot of this really ought to be shared with http_protocol.c...
* another missing cleanup.  It&#039;s particularly inappropriate to be
* setting header_only, etc., here.
*/
&nbsp;
new-&gt;method          = r-&gt;method;
new-&gt;method_number   = r-&gt;method_number;
new-&gt;allowed_methods = ap_make_method_list(new-&gt;pool, 2);
ap_parse_uri(new, new_uri);
&nbsp;
new-&gt;request_config = ap_create_request_config(r-&gt;pool);
&nbsp;
new-&gt;per_dir_config = r-&gt;server-&gt;lookup_defaults;
&nbsp;
new-&gt;prev = r;
r-&gt;next   = new;
&nbsp;
/* Must have prev and next pointers set before calling create_request
* hook.
*/
ap_run_create_request(new);
&nbsp;
/* Inherit the rest of the protocol info... */
&nbsp;
new-&gt;the_request = r-&gt;the_request;
&nbsp;
new-&gt;allowed         = r-&gt;allowed;
&nbsp;
new-&gt;status          = r-&gt;status;
new-&gt;assbackwards    = r-&gt;assbackwards;
new-&gt;header_only     = r-&gt;header_only;
new-&gt;protocol        = r-&gt;protocol;
new-&gt;proto_num       = r-&gt;proto_num;
new-&gt;hostname        = r-&gt;hostname;
new-&gt;request_time    = r-&gt;request_time;
new-&gt;main            = r-&gt;main;
&nbsp;
new-&gt;headers_in      = r-&gt;headers_in;
new-&gt;headers_out     = apr_table_make(r-&gt;pool, 12);
new-&gt;err_headers_out = r-&gt;err_headers_out;
new-&gt;subprocess_env  = rename_original_env(r-&gt;pool, r-&gt;subprocess_env);
new-&gt;notes           = apr_table_make(r-&gt;pool, 5);
new-&gt;allowed_methods = ap_make_method_list(new-&gt;pool, 2);
&nbsp;
new-&gt;htaccess        = r-&gt;htaccess;
new-&gt;no_cache        = r-&gt;no_cache;
new-&gt;expecting_100   = r-&gt;expecting_100;
new-&gt;no_local_copy   = r-&gt;no_local_copy;
new-&gt;read_length     = r-&gt;read_length;     /* We can only read it once */
new-&gt;vlist_validator = r-&gt;vlist_validator;
&nbsp;
new-&gt;proto_output_filters  = r-&gt;proto_output_filters;
new-&gt;proto_input_filters   = r-&gt;proto_input_filters;
&nbsp;
new-&gt;output_filters  = new-&gt;proto_output_filters;
new-&gt;input_filters   = new-&gt;proto_input_filters;
&nbsp;
if (new-&gt;main) {
/* Add back the subrequest filter, which we lost when
* we set output_filters to include only the protocol
&nbsp;
*/
ap_add_output_filter_handle(ap_subreq_core_filter_handle,
NULL, new, new-&gt;connection);
}
&nbsp;
update_r_in_filters(new-&gt;input_filters, r, new);
update_r_in_filters(new-&gt;output_filters, r, new);
&nbsp;
apr_table_setn(new-&gt;subprocess_env, "REDIRECT_STATUS",
apr_itoa(r-&gt;pool, r-&gt;status));
&nbsp;
/*
* XXX: hmm.  This is because mod_setenvif and mod_unique_id really need
* to do their thing on internal redirects as well.  Perhaps this is a
* misnamed function.
*/
if ((access_status = ap_run_post_read_request(new))) {
ap_die(access_status, new);
return NULL;
}
&nbsp;
return new;
}</pre><p><a href="http://www.askapache.com/htaccess/php-cgi-redirect_status.html"></a><a href="http://www.askapache.com/htaccess/php-cgi-redirect_status.html">Securing php.ini and php.cgi with .htaccess</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/php-cgi-redirect_status.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>An AskApache Plugin Upgrade to Rule them All</title>
		<link>http://www.askapache.com/wordpress/an-askapache-plugin-upgrade-to-rule-them-all.html</link>
		<comments>http://www.askapache.com/wordpress/an-askapache-plugin-upgrade-to-rule-them-all.html#comments</comments>
		<pubDate>Wed, 29 Jul 2009 17:59:07 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=3062</guid>
		<description><![CDATA[<p><a class="IFL" href="http://uploads.askapache.com/2009/07/apache-server-status.png"><img src="http://uploads.askapache.com/2009/07/apache-server-status-350x164.png" alt="apache-server-status" title="apache-server-status" width="350" height="164" class="alignnone size-medium wp-image-3070" /></a>So my blog as been rather quiet for almost a year now, and very few updates if any have been released for my Password Protection PLugin, my Google 404 Plugin, and definately not for my AskApache CrazyCache plugin, which I will be releasing last...  So for all of you who've helped me out by sending me suggestions and notifying me of errors and sticking with it...  Just wanted to <strong>say sorry about that, and thanks for all the great ideas.. </strong> Well, I've been sticking with it as well believe it our not.  I manage to get free days once in a while, and then its <strong>time to jam</strong>.<br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/wordpress/an-askapache-plugin-upgrade-to-rule-them-all.html"></a><a href="http://www.askapache.com/wordpress/an-askapache-plugin-upgrade-to-rule-them-all.html"><cite>AskApache.com</cite></a></p><p><a class="IFL" href="http://uploads.askapache.com/2009/07/apache-server-status.png"><img src="http://uploads.askapache.com/2009/07/apache-server-status-350x164.png" alt="An AskApache Plugin Upgrade to Rule them All" title="apache-server-status" width="350" height="164" class="alignnone size-medium wp-image-3070" /></a>So my blog as been rather quiet for almost a year now, and very few updates if any have been released for my Password Protection PLugin, my Google 404 Plugin, and definately not for my AskApache CrazyCache plugin, which I will be releasing last...  So for all of you who've helped me out by sending me suggestions and notifying me of errors and sticking with it...  Just wanted to <strong>say sorry about that, and thanks for all the great ideas.. </strong> Well, I've been sticking with it as well believe it our not.  I manage to get free days once in a while, and then its <strong>time to jam</strong>.</p>
 <p>I've used just about every CMS/Blog/Forum/Trac/Gallery/etc) and really didn't like a lot of the way they coded...  I could use php but I didn't KNOW php.. so I've had to learn php also, and it was tough to learn the advanced class usage and all the other language specific (but similar) constructs for php.  It was especially difficult (but fun and challenging) to program so as to be compatible with php4 and php5 (Such is WordPress).    But I kept at it, and soon you can decide for yourself what to make of it.</p>
<p>I can code in plenty of languages (bash, lua, windows .bat and vbs,  ocaml, big fan of all things shell) and can work my way through C and even sorta somewhat with assembly.  Assembly is the hardest, by far,  I'm into easy and powerful languages like Python, Javascript, perl, php, ruby, and CGI. I've used PHP for a long time to do various things,  but never to build software projects like this.  Once I noticed WordPress's core .php files and the excellent programming I wanted to try and learn hot to do it.   The WordPress code is some of the best I've seen.  It appears the way they built it was planned, and not just dreamt up while typing that I can't help but do.    Every time I read through the core code I learn a new trick or very nice way to do something.  Those guys are really good, and I think WordPress is going to dominate for a long long time.</p>


<h2>The Strategy</h2>
<p>The Password Protection (passpro) plugin has a lot of complex stuff going on, especially for a newbie to PHP and WordPress like me, so after refactoring the whole thing at least 5 times I decided to modify my approach, and wrote the AskApache Google 404 Plugin as a way to practice on a simpler piece of code, while at the same time providing a plugin of value.   Eventually I stopped thinking I could just code the whole thing in one sit-down with a stream-of-consciousness, and had to instead modularize the code and focus in on each part before moving to the next (I go without a plan because its fun, just not the most productive, but again, I'm not a programmer in the scientific sense.).</p>
<p>So I decided I had to really learn how WordPress Plugins work, filters, hooks, actions, and basically comfortability at reverse-engineering code, (Im a beginner for the last time), and so with the upcoming release of the AskApache Google 404 Plugin I have succeeded in making an incredibly stable plugin.  That way I only have to worry about what the aapasspro plugin is doing, instead of trying to fit it into a framework.  </p>


<h2>AskApache Google 404 Upgrade</h2>
<p>I think its rather unusual to develop a nice plugin like this 404 handler merely for the purpose of improving upon another plugin, but hey it worked.  As of <em>08/03/2009 14:06PM EST</em> I have about 1 hour left of finishing touches to release this upgrade.  But as you cantell by my badly edited posts, I don't have a lot of time to myself.  An hour here and there is about it.  So it could be up to 2 weeks before I actually have the time to commit the release to the repo.  On a sidenote, have you checked out <a href="http://windows7news.com/" title="Windows 7 News">Windows 7 News</a>?  I've been contracted to do some technical work for them and thought they had an excellent site.</p>
<p><a href="http://uploads.askapache.com/2009/07/askapache-google-upgrade-ss1.png"><img src="http://uploads.askapache.com/2009/07/askapache-google-upgrade-ss1-344x350.png" alt="An AskApache Plugin Upgrade to Rule them All" title="askapache-google-upgrade-ss1" width="344" height="350" class="alignnone size-medium wp-image-3139" /></a></p>
<p><a href="http://uploads.askapache.com/2009/07/askapache-google-upgrade-ss2.png"><img src="http://uploads.askapache.com/2009/07/askapache-google-upgrade-ss2-293x350.png" alt="An AskApache Plugin Upgrade to Rule them All" title="askapache-google-upgrade-ss2" width="293" height="350" class="alignnone size-medium wp-image-3138" /></a></p>
<p>But keep in mind, the 404 PLugin is just where I practice for the passpro plugin, which truly does have features that no other software like it has ever had.  I understand the technology behind this plugin, and know it would really have a great impact on improving the Web (esp. WordPress) for all of us, I've just had to learn how to make it.</p>

<h2>AskApache Password Protection</h2>
<p>Probably still a couple weeks away, this plugin is the ultimate culmination of apache hackers dreams, at least those on shared servers (who may be interested in learning how to bypass security of said servers)..  So this is something I have much too fun with doing what I like to do.. network/protocol-level security.  I've examined the source code for many software packages that I use or have used to audit a server's security, and this simple php plugin in most instances can enumerate with accuraccy most of the server's setup in about a minute.  The catch (and the file permission problems I had to find a workaround too) is that this software is launched on the server, not remotely against the server.</p>
<p>Some of the software I examined was whiskers, nessus, nmap, hping, mozilla source, wireshark, ncftp, netcat, etc..  The closest comparison to the socket-level class I've hacked together to those is wireshark.  Except that wireshark only interprets (captures) the data passing over the wire, while this class does that and in fact sends and receives the data like netcat or nmap.  Its really more similar to metasploit, and can easily be used to send hex, binary, ascii, or any type of payload to the remote or local host.</p>


<h2>The Upgrades Begin</h2>
<p>Well I started working on them a long time ago.  Both the Password Protection plugin and the Google 404 plugin needed serious work.   And I finally have it all figured out.  Essentially I would work on one and finish an upgrade, but I just wasn't happy with it and I wold start all over again, refactoring the code.   So as I put the finishing touches on those 2 plugins keep an eye out.  They are major upgrades.   I was able to meet all the goals I had for them, and came up with a lot of more improvements during the process.One of the main things I needed was a socket-level class to perform all kinds of checks and tests on.  I need this also for my crazy cache plugin, which my blog is currently using ,  and I have a 2 more really nice pplugins I use that also needed  access to a network class.  I wrote about what I was doing with fsockopen, and I've been improving on that example ever since.  I use this class to do some really powerful and exciting stuff, but you'll see it soon enough.  As an indication of 'getting it right' for the Password Protection plugin, the plugin will now work on Windows, Apache, IIS, Lighthttpd, and will even work running on a blackberry web server.  So now everyone using wordpress can at least get some security()



<p class="enote">Many of the the other improvements focus on using the fsockopen class and .htaccess tricks to basically enumerate and discover all the different capabilities of your particular server;  That way you can learn about all the features and security that are possible for your specific server, and the securty modules wi8ll be geared for that as well.  FINALLY this plugin is going to be stable, and I just cant wait to see how people react when they learn all great capability their Apache-based Server has that they didn't have a clue about.   Its amazing in that sense, and hackers will love theh way it works.. but your server admins will love it even more because its entirely 100% focused on helping you to set your site up (if you have Apache) to keep spammers out, to keep virii-serving robots and their log-hogging exploit requests and CPU/Mem robiing 404 errors off of your servers for real.  This will have a noticeable affect to whoever is running the server.   As you can tell.. I am pumped!</br></p>


<hr class="C" />
Apache is easy to configure and use, but only when you have root access.  Most people on shared and private hosting aren't even able to view the main config file, let alone execute the Apache binaries to see what features are available and what configuration is being used.<br class="C" /></p>

<p>Apache can only be influenced by the main server configs and by .htaccess files.  Not by php, not by perl, and the main configs are almost never accessible to the masses.  But .htaccess files are.  And many hosting providers allow and enable .htaccess files, a configuration file for your web server.  The advanced features and capabilities of Apache were out of reach for most of us, it just wasn't possible to enumerate or access, and most hosting providers are infamous for their lack of .htaccess (customer) support.  This plugin goes around those problems to give the power back to the people.<br class="C" /></p>y creating custom .htaccess files containing unpublished .htaccess tricks and techniques and combining that with the use of socket-level networking from WordPress (PHP) using <a href="http://www.askapache.com/php/fsockopen-socket.html">fsockopen</a>, we can effectively enumerate and discover an incredible amount of features and settings you will be able to control and use with this plugin.</p>

<p>Here are a few examples of the capabilities of this plugin, some of which I believe no other software can do..  <em>(Open source free to copy!)</em>.</p>
<ol>
<li>Current Version of Apache (<strong>Down to the API Version</strong>)</li>
<li>List of <strong>ALL Modules currently enabled</strong> by Apache (Such as Mod_Rewrite)</li>
<li>List of <strong>ALL Directives enabled by EACH enabled Module.</strong></li>
<li>Enumerate .htaccess Overrides, Context Permissions</li>
<li>Test for any builtin Handlers (like the <a href="http://uploads.askapache.com/2009/07/apache-server-status.png">status handler screenshot</a>)</li>
<li>Configure SSI (<a href="http://www.askapache.com/htaccess/advanced-htaccess-ssi.html#htaccess-ssi-security">http://www.askapache.com/htaccess/advanced-htaccess-ssi.html#htaccess-ssi-security</a>)</li>
</ol>


<blockquote cite="http://www.askapache.com/htaccess/password-protection-plugin-status.html"><div class="inote"><cite><a href="http://www.askapache.com/htaccess/password-protection-plugin-status.html"></a></cite><p><strong>March 1, 2009</strong><br /><strong>I would focus on the method that WordPress uses</strong>.  The code they have now (2.8 bleeding-edge) still isn't where it needs to be, but this is some difficult stuff and <strong>they have a brilliant start, it'll work.. just a question of when</strong>.</p>
<p><a class="IFL" href="http://uploads.askapache.com/2009/03/apache-security-model-tall1.png"><img src="http://uploads.askapache.com/2009/03/apache-security-model-tall1-250x123.png" alt="Apache Security Model - In Color" title="apache-security-model-wide" width="250" height="123" /></a><strong>The main issue</strong> with the password protection plugin working for some people and not others is due to <a title="detailed file permission article" href="http://www.askapache.com/security/chmod-stat.html">file permission configurations</a>.  The plugin attempts to write/modify files in your blog's root directory.<br class="C" /></p></div></blockquote>
<hr class="C" />

<blockquote cite="http://www.askapache.com/htaccess/htaccess-plugin-blocks-spam-hackers-and-password-protects-blog.html"><div class="inote"><cite><a href="http://www.askapache.com/htaccess/htaccess-plugin-blocks-spam-hackers-and-password-protects-blog.html"></a></cite><p><strong>November 05, 2008</strong><br />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.11, I then compiled each version and built a HTTPD from source for all these apache versions.</p>
<div><div style="width:100px;overflow:hidden;float:left;"><ul><li>1.3.0</li><li>1.3.1</li><li>1.3.11</li><li>1.3.12</li><li>1.3.14</li><li>1.3.17</li><li>1.3.19</li><li>1.3.2</li><li>1.3.20</li><li>1.3.22</li><li>1.3.23</li><li>1.3.24</li><li>1.3.27</li><li>1.3.28</li></ul></div><div style="width:100px;overflow:hidden;float:left;"><ul><li>1.3.29</li><li>1.3.3</li><li>1.3.31</li><li>1.3.32</li><li>1.3.33</li><li>1.3.34</li><li>1.3.35</li><li>1.3.36</li><li>1.3.37</li><li>1.3.39</li><li>1.3.4</li><li>1.3.41</li><li>1.3.6</li><li>1.3.9</li></ul></div>
<div style="width:100px;overflow:hidden;float:left;"><ul><li>2.0.35</li><li>2.0.36</li><li>2.0.39</li><li>2.0.40</li><li>2.0.42</li><li>2.0.43</li><li>2.0.44</li><li>2.0.45</li><li>2.0.46</li><li>2.0.47</li><li>2.0.48</li><li>2.0.49</li><li>2.0.50</li><li>2.0.51</li></ul></div><div style="width:150px;overflow:hidden;float:left;"><ul><li>2.0.52</li><li>2.0.53</li><li>2.0.54</li><li>2.0.55</li><li>2.0.58</li><li>2.0.59</li><li>2.0.61</li><li>2.0.63</li><li>2.1.3-beta</li><li>2.1.6-alpha</li><li>2.1.7-beta</li><li>2.1.8-beta</li><li>2.1.9-beta</li></ul></div><div style="width:100px;overflow:hidden;float:left;"><ul><li>2.2.0</li><li>2.2.10</li><li>2.2.2</li><li>2.2.3</li><li>2.2.4</li><li>2.2.6</li><li>2.2.8</li><li>2.2.9</li><li><strong>2.2.10</strong></li><li><strong>2.2.11</strong></li></ul></div><br class="C" /></div>
<p>Then I went through each version and determined the compatible modules for that version, and I'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>.  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.  So this is so awesome because now we can enable all sorts of additional security features.</p>
</div>
</blockquote>
<hr class="C" />




<blockquote cite="http://www.askapache.com/htaccess/htaccess.html#htaccess-modules"><cite><a href="http://www.askapache.com/htaccess/htaccess.html#htaccess-modules">Htaccess enabled Modules</a></cite><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="http://www.askapache.com/servers/mod_actions.c.html">mod_actions</a>, <a href="http://www.askapache.com/servers/mod_alias.c.html">mod_alias</a>, <a href="http://www.askapache.com/servers/mod_asis.c.html">mod_asis</a>, <a href="http://www.askapache.com/servers/mod_auth_basic.c.html">mod_auth_basic</a>, <a href="http://www.askapache.com/servers/mod_auth_digest.c.html">mod_auth_digest</a>, <a href="http://www.askapache.com/servers/mod_authn_anon.c.html">mod_authn_anon</a>, <a href="http://www.askapache.com/servers/mod_authn_dbd.c.html">mod_authn_dbd</a>, <a href="http://www.askapache.com/servers/mod_authn_dbm.c.html">mod_authn_dbm</a>, <a href="http://www.askapache.com/servers/mod_authn_default.c.html">mod_authn_default</a>, <a href="http://www.askapache.com/servers/mod_authn_file.c.html">mod_authn_file</a>, <a href="http://www.askapache.com/servers/mod_authz_dbm.c.html">mod_authz_dbm</a>, <a href="http://www.askapache.com/servers/mod_authz_default.c.html">mod_authz_default</a>, <a href="http://www.askapache.com/servers/mod_authz_groupfile.c.html">mod_authz_groupfile</a>, <a href="http://www.askapache.com/servers/mod_authz_host.c.html">mod_authz_host</a>, <a href="http://www.askapache.com/servers/mod_authz_owner.c.html">mod_authz_owner</a>, <a href="http://www.askapache.com/servers/mod_authz_user.c.html">mod_authz_user</a>, <a href="http://www.askapache.com/servers/mod_autoindex.c.html">mod_autoindex</a>, <a href="http://www.askapache.com/servers/mod_cache.c.html">mod_cache</a>, <a href="http://www.askapache.com/servers/mod_cern_meta.c.html">mod_cern_meta</a>, <a href="http://www.askapache.com/servers/mod_cgi.c.html">mod_cgi</a>, <a href="http://www.askapache.com/servers/mod_dav.c.html">mod_dav</a>, <a href="http://www.askapache.com/servers/mod_dav_fs.c.html">mod_dav_fs</a>, <a href="http://www.askapache.com/servers/mod_dbd.c.html">mod_dbd</a>, <a href="http://www.askapache.com/servers/mod_deflate.c.html">mod_deflate</a>, <a href="http://www.askapache.com/servers/mod_dir.c.html">mod_dir</a>, <a href="http://www.askapache.com/servers/mod_disk_cache.c.html">mod_disk_cache</a>, <a href="http://www.askapache.com/servers/mod_dumpio.c.html">mod_dumpio</a>, <a href="http://www.askapache.com/servers/mod_env.c.html">mod_env</a>, <a href="http://www.askapache.com/servers/mod_expires.c.html">mod_expires</a>, <a href="http://www.askapache.com/servers/mod_ext_filter.c.html">mod_ext_filter</a>, <a href="http://www.askapache.com/servers/mod_file_cache.c.html">mod_file_cache</a>, <a href="http://www.askapache.com/servers/mod_filter.c.html">mod_filter</a>, <a href="http://www.askapache.com/servers/mod_headers.c.html">mod_headers</a>, <a href="http://www.askapache.com/servers/mod_ident.c.html">mod_ident</a>, <a href="http://www.askapache.com/servers/mod_imagemap.c.html">mod_imagemap</a>, <a href="http://www.askapache.com/servers/mod_include.c.html">mod_include</a>, <a href="http://www.askapache.com/servers/mod_info.c.html">mod_info</a>, <a href="http://www.askapache.com/servers/mod_log_config.c.html">mod_log_config</a>, <a href="http://www.askapache.com/servers/mod_log_forensic.c.html">mod_log_forensic</a>, <a href="http://www.askapache.com/servers/mod_logio.c.html">mod_logio</a>, <a href="http://www.askapache.com/servers/mod_mem_cache.c.html">mod_mem_cache</a>, <a href="http://www.askapache.com/servers/mod_mime.c.html">mod_mime</a>, <a href="http://www.askapache.com/servers/mod_mime_magic.c.html">mod_mime_magic</a>, <a href="http://www.askapache.com/servers/mod_negotiation.c.html">mod_negotiation</a>, <a href="http://www.askapache.com/servers/mod_proxy.c.html">mod_proxy</a>, <a href="http://www.askapache.com/servers/mod_proxy_ajp.c.html">mod_proxy_ajp</a>, <a href="http://www.askapache.com/servers/mod_proxy_balancer.c.html">mod_proxy_balancer</a>, <a href="http://www.askapache.com/servers/mod_proxy_connect.c.html">mod_proxy_connect</a>, <a href="http://www.askapache.com/servers/mod_proxy_ftp.c.html">mod_proxy_ftp</a>, <a href="http://www.askapache.com/servers/mod_proxy_http.c.html">mod_proxy_http</a>, <a href="http://www.askapache.com/servers/mod_rewrite.c.html">mod_rewrite</a>, <a href="http://www.askapache.com/servers/mod_setenvif.c.html">mod_setenvif</a>, <a href="http://www.askapache.com/servers/mod_speling.c.html">mod_speling</a>, <a href="http://www.askapache.com/servers/mod_ssl.c.html">mod_ssl</a>, <a href="http://www.askapache.com/servers/mod_status.c.html">mod_status</a>, <a href="http://www.askapache.com/servers/mod_substitute.c.html">mod_substitute</a>, <a href="http://www.askapache.com/servers/mod_unique_id.c.html">mod_unique_id</a>, <a href="http://www.askapache.com/servers/mod_userdir.c.html">mod_userdir</a>, <a href="http://www.askapache.com/servers/mod_usertrack.c.html">mod_usertrack</a>, <a href="http://www.askapache.com/servers/mod_version.c.html">mod_version</a>, <a href="http://www.askapache.com/servers/mod_vhost_alias.c.html">mod_vhost_alias</a></p></blockquote>
<hr class="C" /><hr class="C" />




<h2>Debugging HTTP protocol</h2>
<p>Check this out!  I'm particularly happy about this feature, which outputs an exact trace of any requests made by the plugin (such as during the testing phase) by saving the actual raw data sent out on the wire using fsockopen, RX and TX.  This is useful for a number of reasons, viewing your headers, finding Redirect Loops, testing RewriteRules, and following the request hop-by-hop for debugging.  The below example shows 2 requests for 2 URIs.  The first URI is protected using Digest Authentication, the 2nd shows Basic.</p>
<pre> ______________
|  RAW TRACE   |
==================================================================================================================================
GET /htaccess/index.txt?testing=query HTTP/1.1
Host: www.askapache.com
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1) AA_PassPro/1.9 (http://www.askapache.com/)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: close
Referer: http://www.askapache.com/
&nbsp;
HTTP/1.1 401 Authorization Required
Date: Wed, 22 Jul 2009 06:29:58 GMT
Server: Apache
WWW-Authenticate: Digest realm="do or die", nonce="03328f3ec7c7b", algorithm=MD5, domain="/", qop="auth"
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 882
Connection: close
Content-Type: text/html; charset=UTF-8
&nbsp;
GET /htaccess/index.txt?testing=query HTTP/1.1
Host: www.askapache.com
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1) AA_PassPro/1.9 (http://www.askapache.com/)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: close
Referer: http://www.askapache.com/
Authorization: Digest username="test",realm="do or die",nonce="03328f3ec7c7b",uri="/htaccess/index.txt?testing=query",
cnonce="82d057852a9dc497",nc=00000001,algorithm=MD5,response="9d476e9ea3",qop="auth"
&nbsp;
HTTP/1.1 200 OK
Date: Wed, 22 Jul 2009 06:29:58 GMT
Server: Apache
Authentication-Info: rspauth="9051b01ee26dd62b3e2b40dada694f45", cnonce="82d057852a9dc497", nc=00000001, qop=auth
Last-Modified: Tue, 21 Jul 2009 23:56:00 GMT
Accept-Ranges: bytes
Cache-Control: max-age=3600
Expires: Wed, 22 Jul 2009 07:29:58 GMT
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 27
Connection: close
Content-Type: text/plain; charset=UTF-8
```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
&nbsp;
 ______________
|  RAW TRACE   |
==================================================================================================================================
GET /htaccess/po.txt?testing=query HTTP/1.1
Host: www.askapache.com
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1) AA_PassPro/1.9 (http://www.askapache.com/)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: close
Referer: http://www.askapache.com/
&nbsp;
HTTP/1.1 401 Authorization Required
Date: Wed, 22 Jul 2009 06:29:58 GMT
Server: Apache
WWW-Authenticate: Basic realm="Po Pimping"
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 878
Connection: close
Content-Type: text/html; charset=UTF-8
&nbsp;
GET /htaccess/po.txt?testing=query HTTP/1.1
Host: www.askapache.com
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1) AA_PassPro/1.9 (http://www.askapache.com/)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: close
Referer: http://www.askapache.com/
Authorization: Basic adfAGAltcA==
&nbsp;
HTTP/1.1 200 OK
Date: Wed, 22 Jul 2009 06:29:58 GMT
Server: Apache
Last-Modified: Wed, 22 Jul 2009 05:54:39 GMT
Accept-Ranges: bytes
Cache-Control: max-age=3600
Expires: Wed, 22 Jul 2009 07:29:58 GMT
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 27
Connection: close
Content-Type: text/plain; charset=UTF-8
```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````</pre>














<h2>.htaccess Directives</h2>
<p>AcceptFilter, AcceptMutex, AcceptPathInfo, AccessFileName, Action, AddAlt, AddAltByEncoding, AddAltByType, AddCharset, AddDefaultCharset, AddDescription, AddEncoding, AddHandler, AddIcon, AddIconByEncoding, AddIconByType, AddInputFilter, AddLanguage, AddModuleInfo, AddOutputFilter, AddOutputFilterByType, AddType, Alias, AliasMatch, AllowCONNECT, AllowEncodedSlashes, AllowOverride, Anonymous, Anonymous_Authoritative, Anonymous_LogEmail, Anonymous_MustGiveEmail, Anonymous_NoUserID, Anonymous_NoUserId, Anonymous_VerifyEmail, AssignUserId, AuthAuthoritative, AuthBasicAuthoritative, AuthBasicProvider, AuthDBDUserPWQuery, AuthDBDUserRealmQuery, AuthDBM, AuthDBMAuthoritative, AuthDBMGroupFile, AuthDBMType, AuthDBMUserFile, AuthDefaultAuthoritative, AuthDigestAlgorithm, AuthDigestDomain, AuthDigestFile, AuthDigestGroupFile, AuthDigestNcCheck, AuthDigestNonceFormat, AuthDigestNonceLifetime, AuthDigestProvider, AuthDigestQop, AuthDigestShmemSize, AuthGroupFile, AuthLDAPAuthzEnabled, AuthLDAPBindDN, AuthLDAPBindON, AuthLDAPBindPassword, AuthLDAPCharsetConfig, AuthLDAPCompareDNOnServer, AuthLDAPDereferenceAliases, AuthLDAPEnabled, AuthLDAPFrontPageHack, AuthLDAPGroupAttribute, AuthLDAPGroupAttributeIsDN, AuthLDAPRemoteUserAttribute, AuthLDAPRemoteUserIsDN, AuthLDAPStartTLS, AuthLDAPURL, AuthLDAPUrl, AuthName, AuthType, AuthUserFile, AuthzDBMAuthoritative, AuthzDBMType, AuthzDefaultAuthoritative, AuthzGroupFileAuthoritative, AuthzLDAPAuthoritative, AuthzOwnerAuthoritative, AuthzUserAuthoritative, BS2000Account, BalancerMember, BrowserMatch, BrowserMatchNoCase, BufferedLogs, CGIMapExtension, CacheDefaultExpire, CacheDirLength, CacheDirLevels, CacheDisable, CacheEnable, CacheExpiryCheck, CacheFile, CacheForceCompletion, CacheGcClean, CacheGcDaily, CacheGcInterval, CacheGcMemUsage, CacheGcUnused, CacheIgnoreCacheControl, CacheIgnoreHeaders, CacheIgnoreNoLastMod, CacheLastModifiedFactor, CacheMaxExpire, CacheMaxFileSize, CacheMaxStreamingBuffer, CacheMinFileSize, CacheNegotiatedDocs, CacheRoot, CacheSize, CacheStoreNoStore, CacheStorePrivate, CacheTimeMargin, CharsetDefault, CharsetOptions, CharsetSourceEnc, CheckCaseOnly, CheckSpelling, ChildPerUserId, ContentDigest, CookieDomain, CookieExpires, CookieLog, CookieName, CookieStyle, CookieTracking, CoreDumpDirectory, CustomLog, DAV, DAVDepthInfinity, DAVGenericLockDB, DAVMinTimeout, DBDExptime, DBDKeep, DBDMax, DBDMin, DBDParams, DBDPersist, DBDPrepareSQL, DBDriver, Dav, DavDepthInfinity, DavGenericLockDB, DavLockDB, DavMinTimeout, DefaultIcon, DefaultLanguage, DefaultType, DeflateBufferSize, DeflateCompressionLevel, DeflateFilterNote, DeflateMemLevel, DeflateWindowSize, Directory, DirectoryIndex, DirectoryMatch, DirectorySlash, DocumentRoot, DumpIOInput, DumpIOOutput, EnableExceptionHook, EnableMMAP, EnableSendfile, ErrorDocument, ErrorLog, Example, ExpiresActive, ExpiresByType, ExpiresDefault, ExtFilterDefine, ExtFilterOptions, ExtendedStatus, FancyIndexing, FileETag, Files, FilesMatch, FilterChain, FilterDeclare, FilterProtocol, FilterProvider, FilterTrace, ForceLanguagePriority, ForceType, ForensicLog, GprofDir, GracefulShutdownTimeout, Group, Header, HeaderName, HostNameLookups, HostnameLookups, ISAIPFakeAsync, ISAPIAppendLogToErrors, ISAPIAppendLogToQuery, ISAPICacheFile, ISAPIFakeAsync, ISAPILogNotSupported, ISAPIReadAheadBuffer, IdentityCheck, IdentityCheckTimeout, IfDefine, IfModule, IfVersion, ImapBase, ImapDefault, ImapMenu, Include, IndexIgnore, IndexOptions, IndexOrderDefault, IndexStyleSheet, KeepAlive, KeepAliveTimeout, LDAPCacheEntries, LDAPCacheTTL, LDAPCertDBPath, LDAPConnectionTimeout, LDAPOpCacheEntries, LDAPOpCacheTTL, LDAPSharedCacheFile, LDAPSharedCacheSize, LDAPTrustedClientCert, LDAPTrustedGlobalCert, LDAPTrustedMode, LDAPVerifyServerCert, LanguagePriority, Limit, LimitExcept, LimitInternalRecursion, LimitRequestBody, LimitRequestFields, LimitRequestFieldsize, LimitRequestLine, LimitXMLRequestBody, Listen, ListenBacklog, LoadFile, LoadModule, Location, LocationMatch, LockFile, LogFormat, LogLevel, MCacheMaxObjectCount, MCacheMaxObjectSize, MCacheMaxStreamingBuffer, MCacheMinObjectSize, MCacheRemovalAlgorithm, MCacheSize, MMapFile, MaxClients, MaxKeepAliveRequests, MaxMemFree, MaxRequestsPerChild, MaxSpareServers, MaxSpareThreads, MaxSpareThreadsPerChild, MaxThreads, MetaDir, MetaFiles, MetaSuffix, MimeMagicFile, MinSpareServers, MinSpareThreads, ModMimeUsePathInfo, MultiviewsMatch, NWSSLTrustedCerts, NWSSLUpgradeable, NameVirtualHost, NoProxy, NumServers, Options, PassEnv, PerlAccessHandler, PerlAuthenHandler, PerlAuthzHandler, PerlChildExitHandler, PerlChildInitHandler, PerlCleanupHandler, PerlDispatchHandler, PerlFixupHandler, PerlFreshRestart, PerlHandler, PerlHeaderParserHandler, PerlInitHandler, PerlLogHandler, PerlModule, PerlPassEnv, PerlPostReadRequestHandler, PerlRequire, PerlRestartHandler, PerlSendHeader, PerlSetEnv, PerlSetVar, PerlSetupEnv, PerlTaintCheck, PerlTransHandler, PerlTypeHandler, PerlWarn, PidFile, Port, Protocol, ProtocolEcho, Proxy, ProxyBadHeader, ProxyBlock, ProxyDomain, ProxyErrorOverride, ProxyFtpDirCharset, ProxyIOBufferSize, ProxyMatch, ProxyMaxForwards, ProxyPass, ProxyPassInterpolateEnv, ProxyPassMatch, ProxyPassReverse, ProxyPassReverseCookieDomain, ProxyPassReverseCookiePath, ProxyPreserveHost, ProxyReceiveBufferSize, ProxyRemote, ProxyRemoteMatch, ProxyRequests, ProxySet, ProxyStatus, ProxyTimeout, ProxyVia, RLimitCPU, RLimitMEM, RLimitNPROC, ReadmeName, Redirect, RedirectMatch, RedirectPermanent, RedirectTemp, RemoveCharset, RemoveEncoding, RemoveHandler, RemoveInputFilter, RemoveLanguage, RemoveOutputFilter, RemoveType, RequestHeader, Require, RewriteBase, RewriteCond, RewriteEngine, RewriteLock, RewriteLog, RewriteLogLevel, RewriteMap, RewriteOptions, RewriteRule, SSIAccessEnable, SSIEndTag, SSIErrorMsg, SSIStartTag, SSITimeFormat, SSIUndefinedEcho, SSLCACertificateFile, SSLCACertificatePath, SSLCADNRequestFile, SSLCADNRequestPath, SSLCARevocationFile, SSLCARevocationPath, SSLCertificateChainFile, SSLCertificateFile, SSLCertificateKeyFile, SSLCipherSuite, SSLCryptoDevice, SSLEngine, SSLHonorCipherOrder, SSLLog, SSLLogLevel, SSLMutex, SSLOptions, SSLPassPhraseDialog, SSLProtocol, SSLProxyCACertificateFile, SSLProxyCACertificatePath, SSLProxyCARevocationFile, SSLProxyCARevocationPath, SSLProxyCipherSuite, SSLProxyEngine, SSLProxyMachineCertificateFile, SSLProxyMachineCertificatePath, SSLProxyProtocol, SSLProxyVerify, SSLProxyVerifyDepth, SSLRandomSeed, SSLRequire, SSLRequireSSL, SSLSessionCache, SSLSessionCacheTimeout, SSLUserName, SSLVerifyClient, SSLVerifyDepth, Satisfy, ScoreBoardFile, Script, ScriptAlias, ScriptAliasMatch, ScriptInterpreterSource, ScriptLog, ScriptLogBuffer, ScriptLogLength, ScriptStock, SecureListen, SendBufferSize, ServerAdmin, ServerAlias, ServerLimit, ServerName, ServerPath, ServerRoot, ServerSignature, ServerTokens, SetEnv, SetEnvIf, SetEnvIfNoCase, SetHandler, SetInputFilter, SetOutputFilter, StartServers, StartThreads, Substitute, SuexecUserGroup, ThreadLimit, ThreadStackSize, ThreadsPerChild, TimeOut, Timeout, TraceEnable, TransferLog, TypeAuthDBMUserFile, TypesConfig, UnsetEnv, UseCanonicalName, UseCanonicalPhysicalPort, User, UserDir, VirtualDocumentRoot, VirtualDocumentRootIP, VirtualHost, VirtualScriptAlias, VirtualScriptAliasIP, Win32DisableAcceptEx, XBitHack, allow, deny, order, php_admin_flag, php_admin_value, php_flag, php_value</p>



<p class="anote">You can view the <a href="http://www.askapache.com/htaccess/htaccess-security-block-spam-hackers.html">plugins home page</a>, <a href="http://www.askapache.com/wordpress/htaccess-password-protect.html#aadl">old</a>, or <a href="http://wordpress.org/extend/plugins/askapache-password-protect/">view it on the wordpress.org site</a>.</p><p><a href="http://www.askapache.com/wordpress/an-askapache-plugin-upgrade-to-rule-them-all.html"></a><a href="http://www.askapache.com/wordpress/an-askapache-plugin-upgrade-to-rule-them-all.html">An AskApache Plugin Upgrade to Rule them All</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/wordpress/an-askapache-plugin-upgrade-to-rule-them-all.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[Htaccess]]></category>

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

		<guid isPermaLink="false">http://www.askapache.com/htaccess/setenvif.html</guid>
		<description><![CDATA[<p>SetEnv, SetEnvIf, and SetEnvIfNoCase directives conditionally set environment variables accessible by scripts and apache based on HTTP Headers, Variables, and Request information.</p>
<ul class="TOCC">
	<li><a href="http://www.askapache.com/htaccess/setenvif.html#setenvif-variables" title="Unique mod_setenvif Variables">Unique mod_setenvif Variables</a></li>
	<li><a href="http://www.askapache.com/htaccess/setenvif.html#http-headers" title="Populates HTTP_MY_ Variables with mod_setenvif variable values">Populates HTTP_MY_ Variables with mod_setenvif variable values</a></li>
	<li><a href="http://www.askapache.com/htaccess/setenvif.html#remote-host" title="Set REMOTE_HOST to Server_Name">Set REMOTE_HOST to HTTP_HOST</a></li>
	<li><a href="http://www.askapache.com/htaccess/setenvif.html#allow-host" title="Allows only if HOST Header is present in request">Allows only if HOST Header is present in request</a></li>
	<li><a href="http://www.askapache.com/htaccess/setenvif.html#header-copy" title="Add values from HTTP Headers">Add values from HTTP Headers</a></li>
	<li><a href="http://www.askapache.com/htaccess/setenvif.html#redirect-status" title="Set the REDIRECT_STATUS for Interpreter Security">Set the REDIRECT_STATUS for Interpreter Security</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/htaccess/setenvif.html"></a><a href="http://www.askapache.com/htaccess/setenvif.html"><cite>AskApache.com</cite></a></p><p><strong>SetEnvIf</strong> and <strong>SetEnvIfNoCase</strong> are really useful directives supplied by the <a href="http://httpd.apache.org/docs/2.2/mod/mod_setenvif.html">mod_setenvif module</a> that allow you to conditionally set environment variables accessible by scripts and apache based on the value of HTTP Headers, Other Variables, and Request information.</p>

<p class="anote">For debugging, you may want to use my <a href="http://www.askapache.com/shellscript/apache-printenv-improvement.html">server environment variable debugging script</a></p>
<ul class="TOCC">
	<li><a href="http://www.askapache.com/htaccess/setenvif.html#setenvif-variables" title="Unique mod_setenvif Variables">Unique mod_setenvif Variables</a></li>
	<li><a href="http://www.askapache.com/htaccess/setenvif.html#http-headers" title="Populates HTTP_MY_ Variables with mod_setenvif variable values">Populates HTTP_MY_ Variables with mod_setenvif variable values</a></li>
	<li><a href="http://www.askapache.com/htaccess/setenvif.html#remote-host" title="Set REMOTE_HOST to Server_Name">Set REMOTE_HOST to HTTP_HOST</a></li>
	<li><a href="http://www.askapache.com/htaccess/setenvif.html#allow-host" title="Allows only if HOST Header is present in request">Allows only if HOST Header is present in request</a></li>
	<li><a href="http://www.askapache.com/htaccess/setenvif.html#header-copy" title="Add values from HTTP Headers">Add values from HTTP Headers</a></li>
	<li><a href="http://www.askapache.com/htaccess/setenvif.html#redirect-status" title="Set the REDIRECT_STATUS for Interpreter Security">Set the REDIRECT_STATUS for Interpreter Security</a></li>
</ul>


<h2><a href="#setenvif-variables" id="setenvif-variables" title="Unique mod_setenvif Variables">Unique mod_setenvif Variables</a></h2>
<p>These can be used for <code>attribute</code>.</p>
<dl>
	<dt>Remote_Host</dt>
	<dd>the hostname (if available) of the client making the request - <code>crawl-66-249-70-24.googlebot.com</code></dd>
	<dt>Remote_Addr</dt>
	<dd>IP address of the client making the request - <code>66.249.70.24</code></dd>
	<dt>Server_Addr</dt>
	<dd>IP address of the server on which the request was received - <code>208.113.183.103</code></dd>
	<dt>Request_Method</dt>
	<dd>name of the method being used - <code>GET</code></dd>
	<dt>Request_Protocol</dt>
	<dd>name and version of the protocol with which the request was made - <code>HTTP/1.1</code></dd>
	<dt>Request_URI</dt>
	<dd>the resource requested on the HTTP request line -- generally the portion of the URL following the scheme and host portion without the query string - <code>/robots.txt</code></dd>
</dl>



<blockquote cite="http://httpd.apache.org/docs/2.2/mod/mod_setenvif.html"><p>Syntax: </p><pre>SetEnvIf attribute regex [!]env-variable[=value] [[!]env-variable[=value]] ...</pre></blockquote>



<h2><a href="#http-headers" id="http-headers" title="Populates HTTP_MY_ Variables with mod_setenvif variable values">Populates HTTP_MY_ Variables with mod_setenvif variable values</a></h2>
<pre>SetEnvIfNoCase Remote_Host "(.*)" HTTP_MY_REMOTE_HOST=$1
SetEnvIfNoCase Remote_Addr "(.*)" HTTP_MY_REMOTE_ADDR=$1
SetEnvIfNoCase Server_Addr "(.*)" HTTP_MY_SERVER_ADDR=$1
SetEnvIfNoCase Request_Method "(.*)" HTTP_MY_REQUEST_METHOD=$1
SetEnvIfNoCase Request_Protocol "(.*)" HTTP_MY_REQUEST_PROTOCOL=$1
SetEnvIfNoCase Request_URI "(.*)" HTTP_MY_REQUEST_URI=$1</pre>


<h2><a href="#remote-host" id="remote-host" title="Set REMOTE_HOST to HTTP_HOST">Set REMOTE_HOST to HTTP_HOST</a></h2>
<p>Sets REMOTE_HOST to www.askapache.com if Remote_Addr=208.113.183.103.  This can be useful if your server doesn't automatically do a reverse lookup on a remote address, so this way you can tell if the request was internal/from your server.</p>
<pre>SetEnvIf Remote_Addr 208\.113\.183\.103 REMOTE_HOST=www.askapache.com</pre>


<h2><a href="#allow-host" id="allow-host" title="Allows only if HOST Header is present in request">Allows only if HOST Header is present in request</a></h2>
<pre>SetEnvIfNoCase ^HOST$ .+ HTTP_MY_HAS_HOST
Order Deny,Allow
Deny from All
Allow from env=HTTP_MY_HAS_HOST</pre>
<p>or</p>
<pre>SetEnvIfNoCase Host .+ HTTP_MY_HAS_HOST
Order Deny,Allow
Deny from All
Allow from env=HTTP_MY_HAS_HOST</pre>


<h2><a href="#header-copy" id="header-copy" title="Add values from HTTP Headers">Add values from HTTP Headers</a></h2>
<pre>SetEnvIfNoCase ^If-Modified-Since$ "(.+)" HTTP_IF_MODIFIED_SINCE=$1
SetEnvIfNoCase ^If-None-Match$ "(.+)" HTTP_IF_NONE_MATCH=$1
SetEnvIfNoCase ^Cache-Control$ "(.+)" HTTP_CACHE_CONTROL=$1
SetEnvIfNoCase ^Connection$ "(.+)" HTTP_CONNECTION=$1
SetEnvIfNoCase ^Keep-Alive$ "(.+)" HTTP_KEEP_ALIVE=$1
SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
SetEnvIfNoCase ^Cookie$ "(.+)" HTTP_MY_COOKIE=$1</pre>


<h2><a href="#redirect-status" id="redirect-status" title="Set the REDIRECT_STATUS for Interpreter Security">Set the REDIRECT_STATUS for Interpreter Security</a></h2>
<p>This is useful in disallowing direct access to interpreters like shell scripts, cgi scripts, and other interpreters.  Only works this way if you have a static IP for your server.  So the only way to access these files is by instructing the server itself to request the file, using an Action directive or by requesting the file through a .php or other script using curl or wget, or something like fsockopen.</p>
<pre>&lt;filesMatch "\.(cgi|sh|pl)$"&gt;
SetEnvIfNoCase Remote_Addr 208\.113\.183\.103 REDIRECT_STATUS
&nbsp;
Order Deny,Allow
Deny from All
Allow from env=REDIRECT_STATUS
&lt;/filesMatch&gt;</pre>


<h2>Block Bad Bots</h2>
<p>Can be useful if your site is getting hammered by spambots. Some nice examples from around the net are at <a href="http://www.askapache.com/htaccess/fight-blog-spam-with-apache.html">Fight Blog Spam With Apache</a>...  Keep in mind the HTTP_USER_AGENT is directly from the client, so its easy to spoof / change.  Instead use <a href="http://www.askapache.com/htaccess/mod_security-htaccess-tricks.html">mod_security</a> for a much better solution.</p>
<pre>SetEnvIfNoCase User-Agent "^Bandit" bad_bot
SetEnvIfNoCase User-Agent "^Baiduspider" bad_bot
SetEnvIfNoCase User-Agent "^BatchFTP" bad_bot
SetEnvIfNoCase User-Agent "^Bigfoot" bad_bot
SetEnvIfNoCase User-Agent "^Black.Hole" bad_bot
&nbsp;
Order Allow,Deny
Allow from All
Deny from env=bad_bot</pre>


<h2>Allow Search robots</h2>
<p>This does the opposite of above, allowing ONLY these web robots access.  Other than rogue robots, configuring your <a href="http://www.askapache.com/seo/updated-robotstxt-for-wordpress.html">robots.txt file</a> correctly will keep most robots where you want them.</p>
<pre>SetEnvIfNoCase User-Agent .*google.* search_robot
SetEnvIfNoCase User-Agent .*yahoo.* search_robot
SetEnvIfNoCase User-Agent .*bot.* search_robot
SetEnvIfNoCase User-Agent .*ask.* search_robot
&nbsp;
Order Deny,Allow
Deny from All
Allow from env=search_robot</pre>

<h2>SetEnvIf Directive</a></h2>
<table>
  <tbody>
    <tr>
      <th><a href="#setenvif-description">Description:</a></th>
      <td>Sets environment variables based on attributes of the request </td>
    </tr>
    <tr>
      <th><a href="#setenvif-syntax">Syntax:</a></th>
      <td><code>SetEnvIf attribute regex [!]env-variable[=value] [[!]env-variable[=value]] ...</code></td>
    </tr>
    <tr>
      <th><a href="#setenvif-context">Context:</a></th>
      <td>server config, virtual host, directory, .htaccess</td>
    </tr>
    <tr>
      <th><a href="#setenvif-override">Override:</a></th>
      <td>FileInfo</td>
    </tr>
    <tr>
      <th><a href="#setenvif-status">Status:</a></th>
      <td>Base</td>
    </tr>
    <tr>
      <th><a href="#setenvif-module">Module:</a></th>
      <td>mod_setenvif</td>
    </tr>
  </tbody>
</table>
<p>The <code>SetEnvIf</code> directive defines environment variables based on attributes of the request. The attribute specified in the first argument can be one of three things:</p>
<ol>
  <li>An HTTP request header field (see <a href="http://www.rfc-editor.org/rfc/rfc2616.txt">RFC2616</a> for more information about these); for example: <code>Host</code>, <code>User-Agent</code>, <code>Referer</code>, and <code>Accept-Language</code>.  A regular expression may be used to specify a set of request headers.</li>
  <li>One of the following aspects of the request:
    <ul>
      <li><code>Remote_Host</code> - the hostname (if available) of the client making the request</li>
      <li><code>Remote_Addr</code> - the IP address of the client making the request</li>
      <li><code>Server_Addr</code> - the IP address of the server on which the request was received (only with versions later than 2.0.43)</li>
      <li><code>Request_Method</code> - the name of the method being used (<code>GET</code>, <code>POST</code>, et cetera)</li>
      <li><code>Request_Protocol</code> - the name and version of the protocol with which the request was made (e.g., "HTTP/0.9", "HTTP/1.1", etc.)</li>
      <li><code>Request_URI</code> - the resource requested on the HTTP  request line -- generally the portion of the URL following the scheme and host portion without the query string. See the <code>RewriteCond</code> directive of <code>mod_rewrite</code> for extra information on how to match your query string.</li>
    </ul>
  </li>
  <li>The name of an environment variable in the list of those associated with the request. This allows <code>SetEnvIf</code> directives to test against the result of prior matches. Only those environment variables defined by earlier <code>SetEnvIf[NoCase]</code> directives are available for testing in this manner. 'Earlier' means that they were defined at a broader scope (such as server-wide) or previously in the current directive's scope. Environment variables will be considered only if there was no match among request characteristics and a regular expression was not used for the attribute.</li>
</ol>

<p>The second argument (regex) is a regular expression.  If the regex matches against the attribute, then the remainder of the arguments are evaluated.</p>
<p>The rest of the arguments give the names of variables to set, and optionally values to which they should be set. These take the form of</p>
<ol>
  <li><code>varname</code></li>
  <li><code>!varname</code></li>
  <li><code>varname=value</code></li>
</ol>
<p>In the first form, the value will be set to "1". The second will remove the given variable if already defined, and the third will set the variable to the literal value given by <code>value</code>. <em>Since version 2.0.51</em> Apache will recognize occurrences of <code>$1</code>..<code>$9</code> within <var>value</var> and replace them by parenthesized subexpressions of <var>regex</var>.</p>

<h4>SetEnvIf Example:</h4>
<pre>SetEnvIf Request_URI "\.gif$" object_is_image=gif
SetEnvIf Request_URI "\.jpg$" object_is_image=jpg
SetEnvIf Request_URI "\.xbm$" object_is_image=xbm
SetEnvIf Referer www\.askapache\.com intra_site_referral
SetEnvIf object_is_image xbm XBIT_PROCESSING=1
SetEnvIf ^SETENVIF*  ^[a-z].*  HAS_SETENVIF</pre>
<p>The first three will set the environment variable <code>object_is_image</code> if the request was for an image file, and the fourth sets <code>intra_site_referral</code> if the referring page was somewhere on the <code>www.askapache.com</code> Web site.</p>
<p>The last example will set environment variable <code>HAS_SETENVIF</code> if the request contains any headers that begin with "SETENVIF" whose values begins with any character in the set [a-z].</p>


<hr class="HR0" />
<h2>htaccess Guide Sections</h2>
<ul class="ou">
	<li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/htaccess-for-webmasters.html" title="Apache HTTP Web Server htaccess tips and tricks">htaccess tricks for Webmasters</a></li>
	<li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/using-http-headers-with-htaccess.html" title="Creating and using HTTP Headers with htaccess">HTTP Header control with htaccess</a></li>
	<li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/php-htaccess-tips-and-tricks.html" title="mod_php or php as a cgi with htaccess tips, htaccess php tricks">PHP on Apache tips and tricks</a></li>
	<li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/seo-search-engine-friendly-redirects-without-mod_rewrite.html" title="SEO-Friendly 301 Redirects without mod_rewrite">SEO Redirects without mod_rewrite</a></li>
	<li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html" title="mod_rewrite tips and tricks with RewriteEngine, RewriteBase, RewriteRule, and RewriteCond">mod_rewrite examples, tips, and tricks</a></li>
	<li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/speed-up-your-site-with-caching-and-cache-control.html" title="Caching, cache-control, cache, expires, and optimizing htaccess">HTTP Caching and Site Speedups</a></li>
	<li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/apache-authentication-in-htaccess.html" title="htaccess and Apache authentication with htpasswd, 401, and 403">Authentication on Apache</a></li>
	<li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/security-with-htaccess.html" title="Security, hacking, and anti-hacking tips and tricks for htaccess">htaccess Security Tricks and Tips</a></li>
	<li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/ssl-example-usage-in-htaccess.html" title="Apache SSL examples">SSL tips and examples</a></li>
	<li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/apache-variable-fun-in-htaccess.html" title="Apache variables info, tricks, and tips">Variable Fun (mod_env) Section</a></li>
	<li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/mod_security-htaccess-tricks.html" title="mod_security Guide and sample mod_Security diretive usage in .htaccess">.htaccess Security with MOD_SECURITY</a></li>
	<li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/setenvif.html" title="SetEnvIf and SetEnvIfNoCase Examples for conditionally setting variables in Apache .htaccess">SetEnvIf and SetEnvIfNoCase Examples</a></li>
</ul>
<hr class="HR0" />


<p class="ment"><a rel="prev" href="http://www.askapache.com/htaccess/mod_security-htaccess-tricks.html" title="mod_security Guide and sample mod_Security directive usage in .htaccess">&laquo;  .htaccess Security with MOD_SECURITY</a> | <a href="http://www.askapache.com/htaccess/htaccess.html" class="acd1" rel="Contents Index Start" title=".htaccess tutorial">.htaccess Tutorial Index</a></p><p><a href="http://www.askapache.com/htaccess/setenvif.html"></a><a href="http://www.askapache.com/htaccess/setenvif.html">Htaccess SetEnvIf and SetEnvIfNoCase Examples</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/setenvif.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>.htaccess Plugin Blocks Spam, Hackers, and Password Protects Blog</title>
		<link>http://www.askapache.com/wordpress/htaccess-plugin-blocks-spam-hackers-password-protects-blog.html</link>
		<comments>http://www.askapache.com/wordpress/htaccess-plugin-blocks-spam-hackers-password-protects-blog.html#comments</comments>
		<pubDate>Sat, 22 Nov 2008 15:18:12 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[WordPress]]></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[<p><a href="http://www.askapache.com/wordpress/htaccess-plugin-blocks-spam-hackers-password-protects-blog.html"></a><a href="http://www.askapache.com/wordpress/htaccess-plugin-blocks-spam-hackers-password-protects-blog.html"><cite>AskApache.com</cite></a></p><p><a class="IFL" href="http://uploads.askapache.com/2008/11/htaccess-plugin-2.png"><img src="http://uploads.askapache.com/2008/11/htaccess-plugin-2.png" alt=".htaccess security plugin 2" title=".htaccess security plugin 2" /></a><br /><br />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+<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>



<h2>Screenshot Unreleased 4.7</h2>
<p>I'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... "How does knowing the modules help?"</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"><img src="http://uploads.askapache.com/2008/11/htaccess-plugin-1.png" alt=".htaccess security plugin 1" title=".htaccess security plugin 1" /></a><br /><a href="http://uploads.askapache.com/2008/11/htaccess-plugin-3.png"><img src="http://uploads.askapache.com/2008/11/htaccess-plugin-3.png" alt=".htaccess security plugin 3" title=".htaccess security plugin 3" /></a><br /><a href="http://uploads.askapache.com/2008/11/htaccess-plugin-4.png"><img src="http://uploads.askapache.com/2008/11/htaccess-plugin-4.png" alt=".htaccess security plugin 4" title=".htaccess security plugin 4" /></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"><cite><a href="http://wordpress.org/support/rss/topic/214390">http://wordpress.org/support/rss/topic/214390</a></cite><br />
I'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.

To that effect I am succeeding marvelously, first I've converted the plugin to a class (4+5 compat), I've replaced my error_handling with WordPress's WP_Error class, and the coolest change is the new tests I've added.

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.

<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>


Then I went through each version and determined the compatible modules for that version, and I'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>.

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.

So this is so awesome because now we can enable all sorts of additional security features.

Other big changes are:
<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>
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..

<strong>Release will come before 2009.. I have some vacations to take and business to finish first. </strong>
</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 "Protected By AskApache"
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 "Protected By AskApache"
AuthUserFile /home/askapache.com/.htpasswda1
AuthType Basic
Require valid-user
&nbsp;
&lt;filesMatch "\.(ico|pdf|flv|jpg|jpeg|mp3|mpg|mp4|mov|wav|wmv|png|gif|swf|css|js)$"&gt;
Allow from All
&lt;/filesMatch&gt;
&nbsp;
&lt;filesMatch "(async-upload)\.php$"&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 "a-zA-Z0-9.+/-?=&"  - 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'><img src="http://uploads.askapache.com/2008/07/http-security-askapache1.png" alt=".htaccess Plugin Blocks Spam, Hackers, and Password Protects Blog" title="http-security-askapache1" /></a></p><p><a href="http://www.askapache.com/wordpress/htaccess-plugin-blocks-spam-hackers-password-protects-blog.html"></a><a href="http://www.askapache.com/wordpress/htaccess-plugin-blocks-spam-hackers-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/wordpress/htaccess-plugin-blocks-spam-hackers-password-protects-blog.html/feed</wfw:commentRss>
		<slash:comments>45</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[Htaccess]]></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[<p><a href="http://www.askapache.com/htaccess/powweb-htaccess.html"></a><a href="http://www.askapache.com/htaccess/powweb-htaccess.html"><cite>AskApache.com</cite></a></p><p><a class="IFL" 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' title="pow head logo htaccess" /></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.<br /></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
&nbsp;
# 1 MONTH
&lt;filesMatch "\.(ico|gif|jpe?g|png|flv|pdf|swf|mov|mp3|wmv|ppt)$"&gt;
ExpiresDefault A2419200
Header append Cache-Control "public"
&lt;/filesMatch&gt;
&nbsp;
# 2 HOURS
&lt;filesMatch "\.(xml|txt|html|js|css)$"&gt;
ExpiresDefault A7200
Header append Cache-Control "private, must-revalidate"
&lt;/filesMatch&gt;
&nbsp;
# NEVER CACHE
&lt;filesMatch "\.(php|cgi|pl|htm)$"&gt;
ExpiresDefault A0
Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
Header set Pragma "no-cache"
&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 "(.*)" ASKAPACHE_HOST=$1
SetEnvIfNoCase Remote_Addr "(.*)" ASKAPACHE_REMOTE_ADDR=$1
SetEnvIfNoCase Server_Addr "(.*)" ASKAPACHE_SERVER_ADDR=$1
SetEnvIf Request_Method "(.*)" ASKAPACHE_REQUEST_METHOD=$1
SetEnvIf Request_Protocol "(.*)" ASKAPACHE_REQUEST_PROTOCOL=$1
SetEnvIf Request_URI "(.*)" 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 "\.(html|htm)$"&gt;
AddDefaultCharset utf-8
DefaultLanguage en-us
&lt;/filesMatch&gt;
&nbsp;
AuthName "Blog"
Require user admin
AuthUserFile /home/users/web/b646/pow.askapache/.htpasswd
AuthType basic
&nbsp;
#                  CACHING                   #
##############################################
#   YEAR
&lt;filesMatch "\.(ico|gif|jpg|jpeg|png|flv)$"&gt;
Header set Cache-Control "max-age=29030400"
&lt;/filesMatch&gt;
#   MONTH
&lt;filesMatch "\.(js|css|pdf|txt|swf)$"&gt;
Header set Cache-Control "max-age=2592000"
&lt;/filesMatch&gt;
#   HOUR
&lt;filesMatch "\.(html|htm)$"&gt;
Header set Cache-Control "max-age=3600"
&lt;/filesMatch&gt;
#   DONT CACHE</pre><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>Apache Directives and Modules on DreamHost</title>
		<link>http://www.askapache.com/hosting/dreamhost-modules-directives.html</link>
		<comments>http://www.askapache.com/hosting/dreamhost-modules-directives.html#comments</comments>
		<pubDate>Fri, 23 Nov 2007 12:23:09 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Hosting]]></category>

		<guid isPermaLink="false">http://www.askapache.com/htaccess/dreamhost-modules-directives.html</guid>
		<description><![CDATA[<p>Apache .htaccess Directives and Loaded Modules allowed on <a href="http://dreamhost.com/" title="Best Web Hosting Host" class="hilite">DreamHost</a> Apache Server 2 Setups.</p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/hosting/dreamhost-modules-directives.html"></a><a href="http://www.askapache.com/hosting/dreamhost-modules-directives.html"><cite>AskApache.com</cite></a></p><p>For those of you web insiders smart enough to be using <a href="http://dreamhost.com/" title="Best Web Hosting Host" class="hilite">DreamHost</a>, here's a list of available modules and directives allowed.  They should help you utilize all the incredible features available on the Apache 2 install.  See the <a href="http://askapache.info/2.2/mod/quickreference.html">Directive Quick Reference</a> for detailed <strong>.htaccess directive</strong> info, or <a href="http://askapache.info/2.2/mod/index.html">Apache Module Reference</a> for module information.<br class="C" /></p>


<h2>Available Modules on DreamHosts Apache 2 Servers</h2>
<dl>
    <dt><a href="http://askapache.info/2.0/mod/mod_access.html" title="mod_access" id="mod_access" name="mod_access">mod_access</a></dt>
    <dd>Provides access control based on client hostname, IP address, or other characteristics of the client request.</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_actions.html" title="mod_actions" id="mod_actions" name="mod_actions">mod_actions</a></dt>
    <dd>This module provides for executing CGI scripts based on media type or request method.</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_alias.html" title="mod_alias" id="mod_alias" name="mod_alias">mod_alias</a></dt>
    <dd>Provides for mapping different parts of the host filesystem in the document tree and for URL redirection</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_asis.html" title="mod_asis" id="mod_asis" name="mod_asis">mod_asis</a></dt>
    <dd>Sends files that contain their own HTTP headers</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_auth.html" title="mod_auth" id="mod_auth" name="mod_auth">mod_auth</a></dt>
    <dd>User authentication using text files</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_auth_anon.html" title="mod_auth_anon" id="mod_auth_anon" name="mod_auth_anon">mod_auth_anon</a></dt>
    <dd>Allows "anonymous" user access to authenticated areas</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_auth_dbm.html" title="mod_auth_dbm" id="mod_auth_dbm" name="mod_auth_dbm">mod_auth_dbm</a></dt>
    <dd>Provides for user authentication using DBM files</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_auth_digest.html" title="mod_auth_digest" id="mod_auth_digest" name="mod_auth_digest">mod_auth_digest</a></dt>
    <dd>User authentication using MD5 Digest Authentication.</dd>
    <dt><a href="http://www.heuer.org/mod_auth_mysql/" title="mod_auth_mysql" id="mod_auth_mysql" name="mod_auth_mysql">mod_auth_mysql</a></dt>
    <dd>MySQL-based authentication module with VirtualHost support (you need only one database for all VirtualHosts), now with SSL Support for the Connection to the MySQL-Server</dd>
    <dt><a href="http://people.apache.org/~rooneg/talks/version-control/version-control.html" title="mod_auth_svn" id="mod_auth_svn" name="mod_auth_svn">mod_auth_svn</a></dt>
    <dd>This module grabs the various opaque URLs passing from client to server, asks mod_dav_svn to decode them, and then possibly vetoes requests based on access policies defined in a configuration file.</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_autoindex.html" title="mod_autoindex" id="mod_autoindex" name="mod_autoindex">mod_autoindex</a></dt>
    <dd>Generates directory indexes, automatically, similar to the Unix ls command or the Win32 dir shell command</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_cache.html" title="mod_cache" id="mod_cache" name="mod_cache">mod_cache</a></dt>
    <dd>Content cache keyed to URIs.</dd>
    <dt><a href="http://www.howtoforge.com/mod_cband_apache2_bandwidth_quota_throttling" title="mod_cband" id="mod_cband" name="mod_cband">mod_cband</a></dt>
    <dd>mod_cband is an Apache 2 module provided to solve the problem of limiting users' and virtualhosts' bandwidth usage. The current versions can set virtualhosts' and users' bandwidth quotas, maximal download speed (like in mod_bandwidth), requests-per-second speed and the maximal number of simultanous IP connections (like in mod_limitipconn)</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_cern_meta.html" title="mod_cern_meta" id="mod_cern_meta" name="mod_cern_meta">mod_cern_meta</a></dt>
    <dd>CERN httpd metafile semantics</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_cgi.html" title="mod_cgi" id="mod_cgi" name="mod_cgi">mod_cgi</a></dt>
    <dd>Execution of CGI scripts</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_dav.html" title="mod_dav" id="mod_dav" name="mod_dav">mod_dav</a></dt>
    <dd>Distributed Authoring and Versioning (<a href="http://www.webdav.org/">WebDAV</a>) functionality</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_dav_fs.html" title="mod_dav_fs" id="mod_dav_fs" name="mod_dav_fs">mod_dav_fs</a></dt>
    <dd>filesystem provider for <a href="http://askapache.info/2.0/mod/mod_dav.html">mod_dav</a></dd>
    <dt><a href="http://www.heuer.org/mod_auth_mysql/" title="mod_dav_svn" id="mod_dav_svn" name="mod_dav_svn">mod_dav_svn</a></dt>
    <dd>Serving Subversion repositories through Apache HTTP Server.</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_deflate.html" title="mod_deflate" id="mod_deflate" name="mod_deflate">mod_deflate</a></dt>
    <dd>Compress content before it is delivered to the client</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_dir.html" title="mod_dir" id="mod_dir" name="mod_dir">mod_dir</a></dt>
    <dd>Provides for "trailing slash" redirects and serving directory index files</dd>
    <dt><a href="http://webdav.todo.gr.jp/" title="mod_encoding" id="mod_encoding" name="mod_encoding">mod_encoding</a></dt>
    <dd>For non-ascii filename interoperability.  This module improves non-ascii filename interoperability of apache (and mod_dav).  It seems many WebDAV clients send filename in their platform-local encoding. But since mod_dav expects everything, even HTTP request line, to be in UTF-8, this causes an interoperability problem.</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_env.html" title="mod_env" id="mod_env" name="mod_env">mod_env</a></dt>
    <dd>Modifies the environment which is passed to CGI scripts and SSI pages</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_expires.html" title="mod_expires" id="mod_expires" name="mod_expires">mod_expires</a></dt>
    <dd>Generation of Expires and Cache-Control HTTP headers according to user-specified criteria</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_ext_filter.html" title="mod_ext_filter" id="mod_ext_filter" name="mod_ext_filter">mod_ext_filter</a></dt>
    <dd>Pass the response body through an external program before delivery to the client</dd>
    <dt><a href="http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html" title="mod_fastcgi" id="mod_fastcgi" name="mod_fastcgi">mod_fastcgi</a></dt>
    <dd>This 3rd party module provides support for the FastCGI protocol. FastCGI is a language independent, scalable, open extension to CGI that provides high performance and persistence without the limitations of server specific APIs.</dd>
    <dt><a href="http://fastcgi.coremail.cn/" title="mod_fcgid" id="mod_fcgid" name="mod_fcgid">mod_fcgid</a></dt>
    <dd>A binary compatibility alternative to Apache module mod_fastcgi.  mod_fcgid has a new process management strategy, which concentrates on reducing the number of fastcgi server, and kick out the corrupt fastcgi server as soon as possible. </dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_headers.html" title="mod_headers" id="mod_headers" name="mod_headers">mod_headers</a></dt>
    <dd>Customization of HTTP request and response headers</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_imap.html" title="mod_imap" id="mod_imap" name="mod_imap">mod_imap</a></dt>
    <dd>Server-side imagemap processing</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_include.html" title="mod_include" id="mod_include" name="mod_include">mod_include</a></dt>
    <dd>Server-parsed html documents (Server Side Includes)</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_info.html" title="mod_info" id="mod_info" name="mod_info">mod_info</a></dt>
    <dd>Provides a comprehensive overview of the server configuration</dd>
    <dt><a href="http://dominia.org/djao/limitipconn2.html" title="mod_limitipconn" id="mod_limitipconn" name="mod_limitipconn">mod_limitipconn</a></dt>
    <dd>Limits the maximum number of simultaneous connections per IP address. Allows inclusion and exclusion of files based on MIME type.</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_log_config.html" title="mod_log_config" id="mod_log_config" name="mod_log_config">mod_log_config</a></dt>
    <dd>Logging of the requests made to the server</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_log_forensic.html" title="mod_log_forensic" id="mod_log_forensic" name="mod_log_forensic">mod_log_forensic</a></dt>
    <dd>Forensic Logging of the requests made to the server</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_logio.html" title="mod_logio" id="mod_logio" name="mod_logio">mod_logio</a></dt>
    <dd>Logging of input and output bytes per request</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_mime.html" title="mod_mime" id="mod_mime" name="mod_mime">mod_mime</a></dt>
    <dd>Associates the requested filename's extensions with the file's handlers and filters and mime-type, language, character set and encoding</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_mime_magic.html" title="mod_mime_magic" id="mod_mime_magic" name="mod_mime_magic">mod_mime_magic</a></dt>
    <dd>Determines the MIME type of a file by looking at a few bytes of its contents</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_negotiation.html" title="mod_negotiation" id="mod_negotiation" name="mod_negotiation">mod_negotiation</a></dt>
    <dd>Provides for <a href="http://askapache.info/2.0/content-negotiation.html">content negotiation</a></dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_rewrite.html" title="mod_rewrite" id="mod_rewrite" name="mod_rewrite">mod_rewrite</a></dt>
    <dd>Provides a rule-based rewriting engine to rewrite requested URLs on the fly</dd>
    <dt><a href="http://www.modsecurity.org/projects/modsecurity/apache/index.html" title="mod_security" id="mod_security" name="mod_security">mod_security</a></dt>
    <dd>HTTP Traffic Logging, Real-Time Attack monitoring and detection, Attack Prevention and just-in-time patching</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_setenvif.html" title="mod_setenvif" id="mod_setenvif" name="mod_setenvif">mod_setenvif</a></dt>
    <dd>Allows the setting of environment variables based on characteristics of the request</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_speling.html" title="mod_speling" id="mod_speling" name="mod_speling">mod_speling</a></dt>
    <dd>Attempts to correct mistaken URLs that users might have entered by ignoring capitalization and by allowing up to one misspelling</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_ssl.html" title="mod_ssl" id="mod_ssl" name="mod_ssl">mod_ssl</a></dt>
    <dd>Strong cryptography using the Secure Sockets Layer (SSL) and Transport Layer Security (TLS) protocols</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_status.html" title="mod_status" id="mod_status" name="mod_status">mod_status</a></dt>
    <dd>Provides information on server activity and performance</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_suexec.html" title="mod_suexec" id="mod_suexec" name="mod_suexec">mod_suexec</a></dt>
    <dd>Allows CGI scripts to run as a specified user and Group</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_unique_id.html" title="mod_unique_id" id="mod_unique_id" name="mod_unique_id">mod_unique_id</a></dt>
    <dd>Provides an environment variable with a unique identifier for each request</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_userdir.html" title="mod_userdir" id="mod_userdir" name="mod_userdir">mod_userdir</a></dt>
    <dd>User-specific directories</dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_usertrack.html" title="mod_usertrack" id="mod_usertrack" name="mod_usertrack">mod_usertrack</a></dt>
    <dd> <em>Clickstream</em> logging of user activity on a site </dd>
    <dt><a href="http://askapache.info/2.0/mod/mod_vhost_alias.html" title="mod_vhost_alias" id="mod_vhost_alias" name="mod_vhost_alias">mod_vhost_alias</a></dt>
    <dd>Provides for dynamically configured mass virtual hosting</dd>
</dl>


<p>This list goes in order of which module was loaded first.  This is important to know sometimes.  At any rate these are the available modules for <a href="http://www.dreamhost.com/" title="Best Web Hosting Host">DreamHost</a> Apache 2 Servers</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_dbm</li>
<li>mod_auth_digest</li>
<li>mod_auth_mysql</li>
<li>mod_authz_svn</li>
<li>mod_autoindex</li>
<li>mod_cache</li>
<li>mod_cband</li>
<li>mod_cern_meta</li>
<li>mod_cgi</li>
<li>mod_dav</li>
<li>mod_dav_fs</li>
<li>mod_dav_svn</li>
<li>mod_deflate</li>
<li>mod_dir</li>
<li>mod_encoding</li>
<li>mod_env</li>
<li>mod_expires</li>
<li>mod_ext_filter</li>
<li>mod_fastcgi</li>
<li>mod_fcgid</li>
<li>mod_headers</li>
<li>mod_imap</li>
<li>mod_include</li>
<li>mod_info</li>
<li>mod_limitipconn</li>
<li>mod_log_config</li>
<li>mod_log_forensic</li>
<li>mod_logio</li>
<li>mod_mime</li>
<li>mod_mime_magic</li>
<li>mod_negotiation</li>
<li>mod_rewrite</li>
<li>mod_security</li>
<li>mod_setenvif</li>
<li>mod_speling</li>
<li>mod_ssl</li>
<li>mod_status</li>
<li>mod_suexec</li>
<li>mod_unique_id</li>
<li>mod_userdir</li>
<li>mod_usertrack</li>
<li>mod_vhost_alias</li>
</ul>

<ol>
<li>security_module</li>
<li>access_module</li>
<li>auth_module</li>
<li>auth_anon_module</li>
<li>auth_dbm_module</li>
<li>auth_digest_module</li>
<li>cache_module</li>
<li>ext_filter_module</li>
<li>include_module</li>
<li>deflate_module</li>
<li>log_config_module</li>
<li>log_forensic_module</li>
<li>logio_module</li>
<li>env_module</li>
<li>mime_magic_module</li>
<li>cern_meta_module</li>
<li>expires_module</li>
<li>headers_module</li>
<li>usertrack_module</li>
<li>unique_id_module</li>
<li>setenvif_module</li>
<li>mime_module</li>
<li>dav_module</li>
<li>status_module</li>
<li>autoindex_module</li>
<li>asis_module</li>
<li>info_module</li>
<li>suexec_module</li>
<li>cgi_module</li>
<li>dav_fs_module</li>
<li>vhost_alias_module</li>
<li>negotiation_module</li>
<li>dir_module</li>
<li>imap_module</li>
<li>actions_module</li>
<li>speling_module</li>
<li>userdir_module</li>
<li>alias_module</li>
<li>rewrite_module</li>
</ol>



<h2>Available Configuration Directives</h2>
<p><strong>LEGEND</strong><br />
<dfn title="Directory">D</dfn>-<em>&lt;Directory&gt;</em>, <dfn title="Files">F</dfn>-<em>&lt;Files&gt;</em> or <dfn title="Location">L</dfn>-<em>&lt;Location&gt;</em></p>

<h3>Directory <em>core.c</em></h3>
<p>Container for directives affecting resources located in the specified directories.</p>
<h3>Location <em>core.c</em></h3>
<p>Container for directives affecting resources accessed through the specified URL paths.</p>
<h3>VirtualHost <em>core.c</em></h3>
<p>Container to map directives to a particular virtual host, takes one or more host addresses.</p>
<h3>Files <em>core.c</em></h3>
<p>Container for directives affecting files matching specified patterns.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>Limit <em>core.c</em></h3>
<p>Container for authentication directives when accessed using specified HTTP methods.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>LimitExcept <em>core.c</em></h3>
<p>Container for authentication directives to be applied when any HTTP method other than those specified is used to access the resource.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>IfModule <em>core.c</em></h3>
<p>Container for directives based on existance of specified modules.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>IfDefine <em>core.c</em></h3>
<p>Container for directives based on existance of command line defines.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>DirectoryMatch <em>core.c</em></h3>
<p>Container for directives affecting resources located in the specified directories.</p>
<h3>LocationMatch <em>core.c</em></h3>
<p>Container for directives affecting resources accessed through the specified URL paths.</p>
<h3>FilesMatch <em>core.c</em></h3>
<p>Container for directives affecting files matching specified patterns.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>AuthType <em>core.c</em></h3>
<p>An HTTP authorization type (e.g., "Basic").  Allowed in <code>httpd.conf</code> inside D, F, and L, also in <strong>.htaccess</strong></p>
<h3>AuthName <em>core.c</em></h3>
<p>The authentication realm (e.g. "Members Only").  Allowed in <code>httpd.conf</code> inside D, F, and L, also in <strong>.htaccess</strong></p>
<h3>Require <em>core.c</em></h3>
<p>Selects which authenticated users or groups may access a protected space.  Allowed in <code>httpd.conf</code> inside D, F, and L, also in <strong>.htaccess</strong></p>
<h3>Satisfy <em>core.c</em></h3>
<p>access policy if both allow and require used ('all' or 'any').  Allowed in <code>httpd.conf</code> inside D, F, and L, also in <strong>.htaccess</strong></p>
<h3>AddDefaultCharset <em>core.c</em></h3>
<p>The name of the default charset to add to any Content-Type without one or 'Off' to disable.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>AcceptPathInfo <em>core.c</em></h3>
<p>Set to on or off for PATH_INFO to be accepted by handlers, or default for the per-handler preference.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>AccessFileName <em>core.c</em></h3>
<p>Name(s) of per-directory config files (default: <strong>.htaccess</strong>).</p>
<h3>DocumentRoot <em>core.c</em></h3>
<p>Root directory of the document tree.</p>
<h3>ErrorDocument <em>core.c</em></h3>
<p>Change responses for HTTP errors.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>AllowOverride <em>core.c</em></h3>
<p>Controls what groups of directives can be configured by per-directory config files.  Allowed in <code>httpd.conf</code> inside D, F, and L</p>
<h3>Options <em>core.c</em></h3>
<p>Set a number of attributes for a given directory.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>DefaultType <em>core.c</em></h3>
<p>the default MIME type for untypable files.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>FileETag <em>core.c</em></h3>
<p>Specify components used to construct a file's ETag.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>EnableMMAP <em>core.c</em></h3>
<p>Controls whether memory-mapping may be used to read files.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>EnableSendfile <em>core.c</em></h3>
<p>Controls whether sendfile may be used to transmit files.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>Port <em>core.c</em></h3>
<p>Port was replaced with Listen in Apache 2.0.</p>
<h3>HostnameLookups <em>core.c</em></h3>
<p>"on" to enable, "off" to disable reverse DNS lookups, or "double" to enable double-reverse DNS lookups.  Allowed in <code>httpd.conf</code> anywhere</p>
<h3>ServerAdmin <em>core.c</em></h3>
<p>The email address of the server administrator.</p>
<h3>ServerName <em>core.c</em></h3>
<p>The hostname and port of the server.</p>
<h3>ServerSignature <em>core.c</em></h3>
<p>En-/disable server signature (on|off|email).  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>ServerRoot <em>core.c</em></h3>
<p>Common directory of server-related files (logs, confs, etc.).</p>
<h3>ErrorLog <em>core.c</em></h3>
<p>The filename of the error log.</p>
<h3>ServerAlias <em>core.c</em></h3>
<p>A name or names alternately used to access the server.</p>
<h3>ServerPath <em>core.c</em></h3>
<p>The pathname the server can be reached at.</p>
<h3>Timeout <em>core.c</em></h3>
<p>Timeout duration (sec).</p>
<h3>IdentityCheck <em>core.c</em></h3>
<p>Enable identd (RFC 1413) user lookups - SLOW.  Allowed in <code>httpd.conf</code> anywhere</p>
<h3>ContentDigest <em>core.c</em></h3>
<p>whether or not to send a Content-MD5 header with each request.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>UseCanonicalName <em>core.c</em></h3>
<p>How to work out the ServerName : Port when constructing URLs.  Allowed in <code>httpd.conf</code> anywhere</p>
<h3>Include <em>core.c</em></h3>
<p>Name of the config file to be included.  Allowed in <code>httpd.conf</code> anywhere</p>
<h3>LogLevel <em>core.c</em></h3>
<p>Level of verbosity in error logging.</p>
<h3>NameVirtualHost <em>core.c</em></h3>
<p>A numeric IP address:port, or the name of a host.</p>
<h3>ServerTokens <em>core.c</em></h3>
<p>Determine tokens displayed in the Server: header - Min(imal), OS or Full.</p>
<h3>LimitRequestLine <em>core.c</em></h3>
<p>Limit on maximum size of an HTTP request line.</p>
<h3>LimitRequestFieldsize <em>core.c</em></h3>
<p>Limit on maximum size of an HTTP request header field.</p>
<h3>LimitRequestFields <em>core.c</em></h3>
<p>Limit (0 = unlimited) on max number of header fields in a request message.</p>
<h3>LimitRequestBody <em>core.c</em></h3>
<p>Limit (in bytes) on maximum size of request message body.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>LimitXMLRequestBody <em>core.c</em></h3>
<p>Limit (in bytes) on maximum size of an XML-based request body.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>RLimitCPU <em>core.c</em></h3>
<p>Soft/hard limits for max CPU usage in seconds.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>RLimitMEM <em>core.c</em></h3>
<p>Soft/hard limits for max memory usage per process.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>RLimitNPROC <em>core.c</em></h3>
<p>soft/hard limits for max number of processes per uid.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>LimitInternalRecursion <em>core.c</em></h3>
<p>maximum recursion depth of internal redirects and subrequests.</p>
<h3>ForceType <em>core.c</em></h3>
<p>a mime type that overrides other configured type.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>SetHandler <em>core.c</em></h3>
<p>a handler name that overrides any other configured handler.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>SetOutputFilter <em>core.c</em></h3>
<p>filter (or ; delimited list of filters) to be run on the request content.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>SetInputFilter <em>core.c</em></h3>
<p>filter (or ; delimited list of filters) to be run on the request body.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>AddOutputFilterByType <em>core.c</em></h3>
<p>output filter name followed by one or more content-types.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>AllowEncodedSlashes <em>core.c</em></h3>
<p>Allow URLs containing '/' encoded as '%2F'.</p>
<h3>PidFile <em>core.c</em></h3>
<p>A file for logging the server process ID.</p>
<h3>ScoreBoardFile <em>core.c</em></h3>
<p>A file for Apache to maintain runtime process management information.</p>
<h3>LockFile <em>core.c</em></h3>
<p>The lockfile used when Apache needs to lock the accept() call.</p>
<h3>MaxRequestsPerChild <em>core.c</em></h3>
<p>Maximum number of requests a particular child serves before dying.</p>
<h3>CoreDumpDirectory <em>core.c</em></h3>
<p>The location of the directory Apache changes to before dumping core.</p>
<h3>AcceptMutex <em>core.c</em></h3>
<p>Valid accept mutexes for this platform and MPM are: default, flock, fcntl, sysvsem.</p>
<h3>MaxMemFree <em>core.c</em></h3>
<p>Maximum number of 1k blocks a particular childs allocator may hold.</p>
<h3>User <em>prefork.c</em></h3>
<p>Effective user id for this server.</p>
<h3>Group <em>prefork.c</em></h3>
<p>Effective group id for this server.</p>
<h3>ListenBacklog <em>prefork.c</em></h3>
<p>Maximum length of the queue of pending connections, as used by listen(2).</p>
<h3>SetInputFilter <em>core.c</em></h3>
<p>filter (or ; delimited list of filters) to be run on the request body.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>AddOutputFilterByType <em>core.c</em></h3>
<p>output filter name followed by one or more content-types.  Allowed in <code>httpd.conf</code> and <strong>.htaccess</strong></p>
<h3>AllowEncodedSlashes <em>core.c</em></h3>
<p>Allow URLs containing '/' encoded as '%2F'.</p>
<h3>PidFile <em>core.c</em></h3>
<p>A file for logging the server process ID.</p>
<h3>ScoreBoardFile <em>core.c</em></h3>
<p>A file for Apache to maintain runtime process management information.</p>
<h3>LockFile <em>core.c</em></h3>
<p>The lockfile used when Apache needs to lock the accept() call.</p>
<h3>MaxRequestsPerChild <em>core.c</em></h3>
<p>Maximum number of requests a particular child serves before dying.</p>
<h3>CoreDumpDirectory <em>core.c</em></h3>
<p>The location of the directory Apache changes to before dumping core.</p>
<h3>AcceptMutex <em>core.c</em></h3>
<p>Valid accept mutexes for this platform and MPM are: default, flock, fcntl, sysvsem.</p>
<h3>MaxMemFree <em>core.c</em></h3>
<p>Maximum number of 1k blocks a particular childs allocator may hold.</p>
<h3>User <em>prefork.c</em></h3>
<p>Effective user id for this server.</p>
<h3>Group <em>prefork.c</em></h3>
<p>Effective group id for this server.</p>
<h3>ListenBacklog <em>prefork.c</em></h3>
<p>Maximum length of the queue of pending connections, as used by listen(2).</p>
<h3>Listen <em>prefork.c</em></h3>
<p>A port number or a numeric IP address and a port number.</p>
<h3>SendBufferSize <em>prefork.c</em></h3>
<p>Send buffer size in bytes.</p>
<h3>StartServers <em>prefork.c</em></h3>
<p>Number of child processes launched at server startup.</p>
<h3>MinSpareServers <em>prefork.c</em></h3>
<p>Minimum number of idle children, to handle request spikes.</p>
<h3>MaxSpareServers <em>prefork.c</em></h3>
<p>Maximum number of idle children.</p>
<h3>MaxClients <em>prefork.c</em></h3>
<p>Maximum number of children alive at the same time.</p>
<h3>ServerLimit <em>prefork.c</em></h3>
<p>Maximum value of MaxClients for this run of Apache.</p>
<h3>KeepAliveTimeout <em>http_core.c</em></h3>
<p>Keep-Alive timeout duration (sec).</p>
<h3>MaxKeepAliveRequests <em>http_core.c</em></h3>
<p>Maximum number of Keep-Alive requests per connection, or 0 for infinite.</p>
<h3>KeepAlive <em>http_core.c</em></h3>
<p>Whether persistent connections should be On or Off.</p>
<h3>LoadModule <em>mod_so.c</em></h3>
<p>a module name and the name of a shared object file to load it from.</p>
<h3>LoadFile <em>mod_so.c</em></h3>
<p>shared object file or library to load into the server at runtime.</p><p><a href="http://www.askapache.com/hosting/dreamhost-modules-directives.html"></a><a href="http://www.askapache.com/hosting/dreamhost-modules-directives.html">Apache Directives and Modules on DreamHost</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/hosting/dreamhost-modules-directives.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

