<?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;  experiments</title>
	<atom:link href="http://www.askapache.com/search/experiments/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>Htaccess Rewrites &#8211; Rewrite Tricks and Tips</title>
		<link>http://www.askapache.com/htaccess/modrewrite-tips-tricks.html</link>
		<comments>http://www.askapache.com/htaccess/modrewrite-tips-tricks.html#comments</comments>
		<pubDate>Sun, 10 Apr 2011 14:05:00 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Htaccess]]></category>

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

		<guid isPermaLink="false">http://www.askapache.com/?p=3861</guid>
		<description><![CDATA[<div><div style="width:260px;height:173px;display:block;overflow:hidden;border:30px solid #fff;border-top-width:0px;float:left;"><p id="bayonetta1"></p></div><p>You've probably seen this.. one of THE coolest video games I've ever seen (though I haven't played).. Its tempting me back to <acronym title="Major League Gamers">MLG</acronym>..  Games are games today, but in the future Gaming Skill will be highly sought after.. So I check in with the gaming world occasionally, I'd hate to miss something like a new Duke-Nukem (<em>cancelled after 10 years in development and no releases</em>).<br /><br />I have around 10 really nice articles I've been working on for awhile now, my problem is that I am a perfectionist, so I keep finding improvements..   worth it.<br class="C" /></p></div>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/design/grilled-cheese-jam-session-online.html"></a><a href="http://www.askapache.com/design/grilled-cheese-jam-session-online.html"><cite>AskApache.com</cite></a></p><div><div style="width:480px;height:320px;display:block;overflow:hidden;border:30px solid #fff;float:left;"><p id="bayonetta"></p></div></div>


<h3><a href="http://www.youtube.com/watch?v=AlIztDOQfn0&feature=related">Bayonetta: In For the Kill Extended Trailer</a></h3>
<p>Nice example of chaotic beats, but they make melody somehow, it's rather an addictive beat. <br /><br />What random chaos have I spent the last 6 months on?  Experiments with DNS, Fail-over technology for MySQL/DNS/WWW/MAIL servers for free or for very cheap, chrooting servers and of course testing new security idea.... But the exciting stuff for me personally is some very cool ways to make sure you are never unable to remotely access your server in case of catastrophic failure.. That's what it's all about for me you know, making things work so well that they run themselves and free up time for life!   I'm around a 1/4 of a century old..  I'm done playing around, it's time to make some cash before they put me in an old-folks home..  My time is short, my cause is just.. We will prevail!    lol..  I'm 25 and I still got jokes!<br /><br /><strong>For 2010</strong> I have a few choice articles and ideas I'm debating about publishing.. I don't want to give the wrong kind of people power, I want to give the power to the people -- but at a certain point it takes a serious investment to actually empower yourself, whereas a company could afford to actually bring it to reality.. So who does the knowledge benefit then?  No, the only way is to get serious myself and beat the profiteers to the punch so to offer a service that would be dirt-cheap if it weren't in the hands of gluttons.<br /><br />I've been pursuing research into several new areas of web technology (no not a smartphone app!) over the past year trying to increase my business profits and quailty of service, and I am becoming more aware every day that I can do it better and cheaper!  Any industry always has those at the top who enjoy knowing things that keep them on top,  and try to prevent others from doing what they did..   It's not like the information is so wizard-like that it's just not possible for average folks to comprehend..   It's just only discussed behind closed doors, masked in schools by tenure and a defined curriculum.  But since this is the Wild Wild Web the barriers can always be circumvented.   Stick around, I am <a href="http://www.askapache.com/about/#partnerup">already looking for partners</a> (both investors and linux/code kungfu masters).<br /><br /><strong>Enjoy the jam session ;)</strong><br class="C" /></p>


<div><div style="width:480px;height:320px;display:block;overflow:hidden;border:30px solid #fff;border-top-width:0px;float:left;">
<p id="bayonetta1"></p></div><p>You've probably seen this.. one of THE coolest video games I've ever seen (though I haven't played).. Its tempting me back to <acronym title="Major League Gamers">MLG</acronym>..  Games are games today, but in the future Gaming Skill will be highly sought after.. So I check in with the gaming world occasionally, I'd hate to miss something like a new Duke-Nukem (<em>cancelled after 10 years in development and no releases</em>).<br /><br />I have around 10 really nice articles I've been working on for awhile now, my problem is that I am a perfectionist, so I keep finding improvements..   worth it.<br class="C" /></p></div><p><a href="http://www.askapache.com/design/grilled-cheese-jam-session-online.html"></a><a href="http://www.askapache.com/design/grilled-cheese-jam-session-online.html">Bayonetta Trailer</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/design/grilled-cheese-jam-session-online.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>DNS Round Robin Configuration using Rsync over SSH</title>
		<link>http://www.askapache.com/linux/dns-round-robin-rsync-over-ssh.html</link>
		<comments>http://www.askapache.com/linux/dns-round-robin-rsync-over-ssh.html#comments</comments>
		<pubDate>Tue, 14 Apr 2009 05:46:20 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=2540</guid>
		<description><![CDATA[<p><a class="IFL" href="http://www.askapache.com/linux/dns-round-robin-rsync-over-ssh.html" id="id12"></a><strong>The goal is to add the HostGator server</strong> to be an exact mirror of the static.askapache.com domain, then to add that server as a 2nd A record to my DNS zone.  That way half the visitors to the size will be taking up resources and bandwidth on the <a href="http://secure.hostgator.com/cgi-bin/affiliates/clickthru.cgi?id=AskApache-rrdns">HostGator</a> server instead of mine.<br /><br /><strong>Round Robin A records</strong> in DNS are intended to evenly distribute queries between each host of the same name.  Using some tricks straight out of a hackers toolbox we can verify if the distribution is taking place.  (<a href="http://www.askapache.com/linux/dns-round-robin-rsync-over-ssh.html#dns-robin-works">It is.</a>)  <br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/linux/dns-round-robin-rsync-over-ssh.html"></a><a href="http://www.askapache.com/linux/dns-round-robin-rsync-over-ssh.html"><cite>AskApache.com</cite></a></p><p>My traffic is growing, alot, and I need to plan how I'm going to maintain scalability, high availability, and redundancy.   Scalability is an application's ability to support a growing number of users. High availability can be defined as redundancy or speed.  I decided to setup <a href="#dns-robin-round">Round Robin DNS</a> for <a href="http://static.askapache.com/">static.askapache.com</a>, which is the "static" <a href="http://www.askapache.com/htaccess/apache-speed-subdomains.html">subdomain</a> of <a href="http://www.askapache.com/">AskApache</a> that serves all the static assets like images, javascript, css, etc.. (<em>BTW, the z stands for ZAP</em>)..  All I needed to attempt setting this up was another hosting account on a separate server.  I have hosting accounts with around 10 different companies from working with various clients over the years, like <a href="http://www.powweb.com/join/index.bml?AffID=582654">Powweb</a> and I don't use them because they suck in terms of the unix environment.  Many of these web hosts are actually very fast bandwidth-wise..</p>

<h2><a id="#round-robin-concept" name="#round-robin-concept"></a>Round Robin Concept</h2>
<p><a class="IFL" href="#"><img src="http://uploads.askapache.com/2009/04/round-robin-dns.png" alt="Round Robin DNS" title="Round Robin DNS" width="396" height="335" class="size-full wp-image-2622" /></a><strong>A few months ago</strong> I was given a free hosting account on <a href="http://secure.hostgator.com/cgi-bin/affiliates/clickthru.cgi?id=AskApache-rrdns">HostGator</a> to evaluate and tempt me away from DreamHost to become a Gator.  I get a lot of these types of offers from time to time from the smaller Web companies who read AskApache.. but when I noticed the SSH access was jailed and saw how restrictive the shell was I felt like I was on a windows box..  I want a shell, cpanel sucks.  I compile and run everything from the shell so thats was a deal-breaker and I sorta forgot all about it.<br /><br /><strong>The goal is to add the HostGator server</strong> to be an <a href="http://www.askapache.com/security/mirror-using-rsync-ssh.html">exact mirror</a> of the static.askapache.com domain, then to add that server as a 2nd A record to my DNS zone.  That way half the visitors to the size will be taking up resources and bandwidth on the <a href="http://secure.hostgator.com/cgi-bin/affiliates/clickthru.cgi?id=AskApache-rrdns">HostGator</a> server instead of mine.<br /><br /><strong>Round Robin A records</strong> in DNS are intended to evenly distribute queries between each host of the same name.  Using some tricks straight out of a <a href="http://www.askapache.com/security/computer-security-toolbox-2.html">hackers toolbox</a> we can <a href="#dns-robin-works">verify if the distribution</a> is taking place.  (<a href="#dns-robin-works">It is.</a>)  <br class="C" /></p>


<h2><a id="#dns-robin-dns" name="#dns-robin-dns"></a>DNS - Domain Name System</h2>
<p>The Domain Name System is often analogized as a "phone book" for the Internet because it translates human-friendly computer hostnames into IP addresses. For example, <code>www.askapache.com</code> translates to <code>208.113.134.190</code>.  Every request for a human-friendly hostname first needs to be translated to the IP before the server can be queried.  Normally each hostname corresponds to exactly 1 IP address.  But in a Round Robin setup, the idea is to have the hostname correspond to multiple IP addresses, which are different servers that house the exact same content, resulting in some hosts requesting files from one server, and another host requesting files from the other server, resulting in less CPU resources and bandwidth.</p>
<p>Here is an the zone for <code>static.askapache.com</code> Round Robin records:</p>
<table summary="Round Robin DNS Records" id="ver-zebra"><colgroup><col class="e" /><col class="o" /><col class="e" /><col class="o" /><col class="e" /></colgroup><thead><tr><th scope="col" class="e">QUERY</th><th scope="col" class="o">TTL</th><th scope="col" class="e">CLASS</th><th scope="col" class="o">TYPE</th><th scope="col" class="e">ANSWER</th></tr></thead><tbody><tr><td>static.askapache.com</td><td>13084</td><td>IN</td><td>A</td><td>64.111.114.111</td></tr><tr><td>static.askapache.com</td><td>13084</td><td>IN</td><td>A</td><td>69.56.174.114</td></tr></tbody></table>


<h2><a id="#dns-robin-round" name="#dns-robin-round"></a>Round Robin DNS</h2>
<p>Round robin DNS is a technique of load distribution, load balancing, or fault-tolerance provisioning multiple, redundant Internet Protocol service hosts, e.g., Web servers, FTP servers, by managing the Domain Name System's (DNS) responses to address requests from client computers according to an appropriate statistical model.</p>
<p>In its simplest implementation Round-robin DNS works by responding to DNS requests not only with a single IP address, but a list of IP addresses of several servers that host identical services. The order in which IP addresses from the list are returned is the basis for the term round robin. With each DNS response, the IP address sequence in the list is permuted. Usually, basic IP clients attempt connections with the first address returned from a DNS query so that on different connection attempts clients would receive service from different providers, thus distributing the overall load among servers.</p>
<p>Round robin DNS is often used for balancing the load of geographically-distributed Web servers. For example, a company has one domain name and three identical web sites residing on three servers with three different IP addresses. When one user accesses the home page it will be sent to the first IP address. The second user who accesses the home page will be sent to the next IP address, and the third user will be sent to the third IP address. In each case, once the IP address is given out, it goes to the end of the list. The fourth user, therefore, will be sent to the first IP address, and so forth.</p>

<p>Although easy to implement, round robin DNS has problematic drawbacks, such as those arising from record caching in the DNS hierarchy itself, as well as client-side address caching and reuse, the combination of which can be difficult to manage. Round robin DNS should not solely be relied upon for service availability. If a service at one of the addresses in the list fails, the DNS will continue to hand out that address and clients will still attempt to reach the inoperable service.</p>



<h2><a id="#dns-robin-works" name="#dns-robin-works" title="Efficacy of DNS Load Balancing"></a>Does Round Robin Work</h2>
<p>Definately.  I can look at the access logs for both servers and see that they are splitting the requests nicely.   It is definately not an exact split however, look at these statistics and you'll see what I mean.</p>
<pre>$ dig @ns1.dreamhost.com +authority +all static.askapache.com
&nbsp;
;; ANSWER SECTION:
static.askapache.com.        14400   IN      A       69.56.174.114
static.askapache.com.        14400   IN      A       64.111.114.111
&nbsp;
$ dig @ns1.dreamhost.com +authority +all static.askapache.com
&nbsp;
;; ANSWER SECTION:
static.askapache.com.        14400   IN      A       64.111.114.111
static.askapache.com.        14400   IN      A       69.56.174.114</pre>

<p>The effects of caching will distort the effectiveness of any IP address allocation algorithm unless a 0 TTL is used which has the effect of significantly increasing the load on the DNS (and is not always implemented consistently). In this case the cure may be worse than the disease Good news we have good load balancing on our web servers. Bad news we need 17 more DNS servers!. Intuitively, and without running any experiments to verify, we would suggest that given a normal TTL (12 hours or more) and ANY IP allocation algorithm other than a single static list, loads should be reasonably balanced .</p>
<p><br /><strong>Full root server query</strong></p>
<pre>Tracing to static.askapache.com[a] via A.ROOT-SERVERS.NET, maximum of 3 retries
A.ROOT-SERVERS.NET [.] (198.41.0.4)
 |\___ L.GTLD-SERVERS.NET [com] (192.41.162.30)
 |     |\___ ns3.dreamhost.com [askapache.com] (66.33.216.216) Got authoritative answer
 |     |\___ ns2.dreamhost.com [askapache.com] (208.96.10.221)
 |      \___ ns1.dreamhost.com [askapache.com] (66.33.206.206) Got authoritative answer
 |\___ D.GTLD-SERVERS.NET [com] (192.31.80.30)
 |     |\___ ns3.dreamhost.com [askapache.com] (66.33.216.216) Got authoritative answer
 |     |\___ ns2.dreamhost.com [askapache.com] (208.96.10.221)
 |      \___ ns1.dreamhost.com [askapache.com] (66.33.206.206) Got authoritative answer
 |\___ J.GTLD-SERVERS.NET [com] (192.48.79.30)
 |     |\___ ns3.dreamhost.com [askapache.com] (66.33.216.216) Got authoritative answer
 |     |\___ ns2.dreamhost.com [askapache.com] (208.96.10.221)
 |      \___ ns1.dreamhost.com [askapache.com] (66.33.206.206) Got authoritative answer
 |\___ H.GTLD-SERVERS.NET [com] (192.54.112.30)
 |     |\___ ns3.dreamhost.com [askapache.com] (66.33.216.216) Got authoritative answer
 |     |\___ ns2.dreamhost.com [askapache.com] (208.96.10.221)
 |      \___ ns1.dreamhost.com [askapache.com] (66.33.206.206) Got authoritative answer
 |\___ E.GTLD-SERVERS.NET [com] (192.12.94.30)
 |     |\___ ns3.dreamhost.com [askapache.com] (66.33.216.216) Got authoritative answer
 |     |\___ ns2.dreamhost.com [askapache.com] (208.96.10.221)
 |      \___ ns1.dreamhost.com [askapache.com] (66.33.206.206) Got authoritative answer
 |\___ F.GTLD-SERVERS.NET [com] (192.35.51.30)
 |     |\___ ns3.dreamhost.com [askapache.com] (66.33.216.216) Got authoritative answer
 |     |\___ ns2.dreamhost.com [askapache.com] (208.96.10.221)
 |      \___ ns1.dreamhost.com [askapache.com] (66.33.206.206) Got authoritative answer
 |\___ I.GTLD-SERVERS.NET [com] (192.43.172.30)
 |     |\___ ns3.dreamhost.com [askapache.com] (66.33.216.216) Got authoritative answer
 |     |\___ ns2.dreamhost.com [askapache.com] (208.96.10.221)
 |      \___ ns1.dreamhost.com [askapache.com] (66.33.206.206) Got authoritative answer
 |\___ G.GTLD-SERVERS.NET [com] (192.42.93.30)
 |     |\___ ns3.dreamhost.com [askapache.com] (66.33.216.216) Got authoritative answer
 |     |\___ ns2.dreamhost.com [askapache.com] (208.96.10.221)
 |      \___ ns1.dreamhost.com [askapache.com] (66.33.206.206) Got authoritative answer
 |\___ B.GTLD-SERVERS.NET [com] (2001:0503:231d:0000:0000:0000:0002:0030) Not queried
 |\___ B.GTLD-SERVERS.NET [com] (192.33.14.30)
 |     |\___ ns3.dreamhost.com [askapache.com] (66.33.216.216) Got authoritative answer
 |     |\___ ns2.dreamhost.com [askapache.com] (208.96.10.221)
 |      \___ ns1.dreamhost.com [askapache.com] (66.33.206.206) Got authoritative answer
 |\___ A.GTLD-SERVERS.NET [com] (2001:0503:a83e:0000:0000:0000:0002:0030) Not queried
 |\___ A.GTLD-SERVERS.NET [com] (192.5.6.30)
 |     |\___ ns3.dreamhost.com [askapache.com] (66.33.216.216) Got authoritative answer
 |     |\___ ns2.dreamhost.com [askapache.com] (208.96.10.221)
 |      \___ ns1.dreamhost.com [askapache.com] (66.33.206.206) Got authoritative answer
 |\___ C.GTLD-SERVERS.NET [com] (192.26.92.30)
 |     |\___ ns3.dreamhost.com [askapache.com] (66.33.216.216) Got authoritative answer
 |     |\___ ns2.dreamhost.com [askapache.com] (208.96.10.221)
 |      \___ ns1.dreamhost.com [askapache.com] (66.33.206.206) Got authoritative answer
 |\___ M.GTLD-SERVERS.NET [com] (192.55.83.30)
 |     |\___ ns3.dreamhost.com [askapache.com] (66.33.216.216) Got authoritative answer
 |     |\___ ns2.dreamhost.com [askapache.com] (208.96.10.221)
 |      \___ ns1.dreamhost.com [askapache.com] (66.33.206.206) Got authoritative answer
  \___ K.GTLD-SERVERS.NET [com] (192.52.178.30)
       |\___ ns3.dreamhost.com [askapache.com] (66.33.216.216) Got authoritative answer
       |\___ ns2.dreamhost.com [askapache.com] (208.96.10.221)
        \___ ns1.dreamhost.com [askapache.com] (66.33.206.206) Got authoritative answer
&nbsp;
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 64.111.114.111
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 69.56.174.114
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 64.111.114.111
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 69.56.174.114
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 64.111.114.111
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 69.56.174.114
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 64.111.114.111
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 69.56.174.114
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 64.111.114.111
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 69.56.174.114
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 64.111.114.111
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 69.56.174.114
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 64.111.114.111
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 69.56.174.114
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 64.111.114.111
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 69.56.174.114
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 64.111.114.111
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 69.56.174.114
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 64.111.114.111
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 69.56.174.114
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 64.111.114.111
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 69.56.174.114
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 69.56.174.114
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 64.111.114.111
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 64.111.114.111
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 69.56.174.114
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 64.111.114.111
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 69.56.174.114
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 64.111.114.111
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 69.56.174.114
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 69.56.174.114
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 64.111.114.111
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 69.56.174.114
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 64.111.114.111
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 64.111.114.111
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 69.56.174.114
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 64.111.114.111
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 69.56.174.114
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 69.56.174.114
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 64.111.114.111
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 69.56.174.114
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 64.111.114.111
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 64.111.114.111
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 69.56.174.114
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 64.111.114.111
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 69.56.174.114
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 69.56.174.114
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 64.111.114.111
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 64.111.114.111
  ns1.dreamhost.com (66.33.206.206)       static.askapache.com -&gt; 69.56.174.114
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 64.111.114.111
  ns3.dreamhost.com (66.33.216.216)       static.askapache.com -&gt; 69.56.174.114</pre>




<h2><a id="#dns-online-tools" name="#dns-online-tools"></a>Live Online DNS Tools</h2>
<ul>
<li><a href="http://member.dnsstuff.com/amember/go.php?r=323972&i=l0">DNSstuff.com - Your Destination for DNS and Networking Tools</a></li>
<li><a href="http://www.zonecheck.fr/cgi-bin/zc.cgi?zone=askapache.com&amp;ns0=ns1.dreamhost.com&amp;ips0=&amp;ns1=ns2.dreamhost.com&amp;ips1=&amp;ns2=ns3.dreamhost.com&amp;ips2=&amp;ns3=&amp;ips3=&amp;ns4=&amp;ips4=&amp;ns5=&amp;ips5=&amp;ns6=&amp;ips6=&amp;ns7=&amp;ips7=&amp;intro=t&amp;explain=t&amp;details=t&amp;progress=counter&amp;report=byseverity&amp;format=html&amp;lang=en&amp;errorlvl=allwarning&amp;profile=automatic&amp;chkmail=t&amp;chkzone=t&amp;chkrir=t&amp;transp3=ipv4&amp;transp3=ipv6&amp;transp4=std">ZoneCheck</a></li>
<li><a href="http://pingability.com/zoneinfo.jsp?domain=askapache.com">Quick Check - Pingability.com</a></li>
<li><a href="http://www.squish.net/dnscheck/dnscheck.cgi?host=askapache.com&amp;type=ANY&amp;show_rootservers=on&amp;removebroken=on&amp;cnameprocessing=on&amp;show_mainworkings=on&amp;show_resolving=on&amp;show_allservers=on&amp;getbindversions=on&amp;retries=5&amp;querylevel=15">Squishywishywoo: complete dns traversal checking</a></li>
<li><a href="http://www.zonecut.net/dns/?domain=askapache.com&amp;find_subs=on">ZoneCut DNS</a></li>
<li><a href="http://atrey.karlin.mff.cuni.cz/~mj/sleuth/?domain=askapache.com&amp;verbose=ON&amp;server=ns1.dreamhost.com&amp;serverip=&amp;action=Submit&amp;.cgifields=verbose">DNS Sleuth</a></li>
<li><a href="http://www.pweb.cz/en/dns-test/dom.php">DNS test - Domain name DNS test - pweb.cz</a></li>
<li><a href="http://www.opendns.com/support/cache/?d=static.askapache.com">OpenDNS - Support - CacheCheck</a></li>
<li><a href="http://www.dnscolos.com/dnsreport.php">DNSReport</a></li>
<li><a href="http://freedns.afraid.org/domain/dnstrace.php?domain=askapache.com&amp;submit=Trace">DNSTrace</a></li>
<li><a href="http://www.intodns.com/askapache.com">intoDNS</a></li>
<li><a href="http://www.dnsthru.com/">DNSthru.com</a></li>
<li><a href="http://demo.dnsdoctor.org/cgi-bin/diagnose.cgi?zone=askapache.com&amp;ns0=ns1.dreamhost.com&amp;ips0=&amp;ns1=ns2.dreamhost.com&amp;ips1=&amp;ns2=ns3.dreamhost.com&amp;ips2=&amp;ns3=&amp;ips3=&amp;ns4=&amp;ips4=67.19.1.10&amp;ns5=&amp;ips5=67.19.0.10&amp;ns6=&amp;ips6=67.18.150.114&amp;ns7=&amp;ips7=&amp;intro=t&amp;format=html&amp;lang=en&amp;testname=t&amp;explain=t&amp;details=t&amp;progress=testdesc&amp;errorlvl=allwarning&amp;dontstop=nostop&amp;profile=automatic&amp;report=byseverity&amp;chkmail=t&amp;transp3=ipv4&amp;transp3=ipv6&amp;transp4=std">DNS Doctor</a></li>
<li><a href="http://www.checkdns.net/powercheck.aspx">Power Check</a></li>
</ul>












<h2><a id="#dns-links" name="#dns-links"></a>More Reading</h2>
<ul>
<li><a href="http://www.zytrax.com/books/dns/ch9/rr.html">HOWTO - Configure Load Balancing</a></li>
<li><a href="http://ntrg.cs.tcd.ie/undergrad/4ba2.01/group8/DNS.html">Load Sharing with DNS</a></li>
</ul>




<h3><a id="#dns-rfc-list" name="#dns-rfc-list"></a>RFC's related to DNS</h3>
<ul>
  <li><a href="http://rfc.askapache.com/rfc920/rfc920.html" title="protocol,signature,resource,dnssec,records,response,record,dnskey,algorithm,standards,domain,server,resolver,security">RFC 920</a>:  Specified original TLDs: .arpa, .com, .edu, .org, .gov, .mil and two-character country codes</li>
  <li><a href="http://rfc.askapache.com/rfc1032/rfc1032.html">RFC 1032</a>:  Domain administrators guide</li>
  <li><a href="http://rfc.askapache.com/rfc1033/rfc1033.html">RFC 1033</a>:  Domain administrators operations guide</li>
  <li><a href="http://rfc.askapache.com/rfc1034/rfc1034.html">RFC 1034</a>:  Domain Names - Concepts and Facilities.</li>
  <li><a href="http://rfc.askapache.com/rfc1035/rfc1035.html">RFC 1035</a>:  Domain Names - Implementation and Specification</li>
  <li><a href="http://rfc.askapache.com/rfc1101/rfc1101.html">RFC 1101</a>:  DNS Encodings of Network Names and Other Types</li>
  <li><a href="http://rfc.askapache.com/rfc1123/rfc1123.html">RFC 1123</a>:  Requirements for Internet Hosts -- Application and Support</li>
  <li><a href="http://rfc.askapache.com/rfc1912/rfc1912.html">RFC 1912</a>:  Common DNS Operational and Configuration Errors</li>
  <li><a href="http://rfc.askapache.com/rfc1995/rfc1995.html">RFC 1995</a>:  Incremental Zone Transfer in DNS</li>
  <li><a href="http://rfc.askapache.com/rfc1996/rfc1996.html">RFC 1996</a>:  A Mechanism for Prompt Notification of Zone Changes (DNS NOTIFY)</li>
  <li><a href="http://rfc.askapache.com/rfc2136/rfc2136.html">RFC 2136</a>:  Dynamic Updates in the domain name system (DNS UPDATE)</li>
  <li><a href="http://rfc.askapache.com/rfc2181/rfc2181.html">RFC 2181</a>:  Clarifications to the DNS Specification</li>
  <li><a href="http://rfc.askapache.com/rfc2182/rfc2182.html">RFC 2182</a>:  Selection and Operation of Secondary DNS Servers</li>
  <li><a href="http://rfc.askapache.com/rfc2308/rfc2308.html">RFC 2308</a>:  Negative Caching of DNS Queries (DNS NCACHE)</li>
  <li><a href="http://rfc.askapache.com/rfc2317/rfc2317.html">RFC 2317</a>:  Classless IN-ADDR.ARPA delegation</li>
  <li><a href="http://rfc.askapache.com/rfc2671/rfc2671.html">RFC 2671</a>:  Extension Mechanisms for DNS (EDNS0)</li>
  <li><a href="http://rfc.askapache.com/rfc3597/rfc3597.html">RFC 3597</a>:  Handling of Unknown DNS Resource Record (RR) Types</li>
  <li><a href="http://rfc.askapache.com/rfc3696/rfc3696.html">RFC 3696</a>:  Application Techniques for Checking and Transformation of Names</li>
  <li><a href="http://rfc.askapache.com/rfc4343/rfc4343.html">RFC 4343</a>:  Domain Name System (DNS) Case Insensitivity Clarification</li>
  <li><a href="http://rfc.askapache.com/rfc4592/rfc4592.html">RFC 4592</a>:  The Role of Wildcards in the Domain Name System</li>
  <li><a href="http://rfc.askapache.com/rfc4892/rfc4892.html">RFC 4892</a>:  Requirements for a Mechanism Identifying a Name Server Instance</li>
  <li><a href="http://rfc.askapache.com/rfc5001/rfc5001.html">RFC 5001</a>:  DNS Name Server Identifier Option (NSID)</li>
  <li>RFC 5395:  Domain Name System (DNS) IANA Considerations</li>
</ul>



<p class="wikicop">This page contains content by <a rel="nofollow" href="http://en.wikipedia.org/w/index.php?title=Round_robin_DNS&amp;action=history">Author</a> of <a href="http://en.wikipedia.org/wiki/Round_robin_DNS" rel="nofollow">Article</a> from <a href="http://en.wikipedia.org/wiki/Main_Page" rel="nofollow">Wikipedia</a> and is licensed under the <a href="http://www.askapache.com/gnu-fdl.txt" rel="nofollow">GNU FDL</a>.</p>

<p><br /><strong>Table of Contents</strong></p>
<ul>
<li><a href="#round-robin-concept">Round Robin Concept</a></li>
<li><a href="#dns-robin-dns">DNS - Domain Name System</a></li>
<li><a href="#dns-robin-round">Round Robin DNS</a></li>
<li><a href="#dns-robin-works">Efficacy of DNS Load Balancing</a></li>
<li><a href="#dns-online-tools">Live Online DNS Tools</a></li>
<li><a href="#dns-links">More Reading</a></li>
<li><a href="#dns-rfc-list">RFC's related to DNS</a></li>
</ul><p><a href="http://www.askapache.com/linux/dns-round-robin-rsync-over-ssh.html"></a><a href="http://www.askapache.com/linux/dns-round-robin-rsync-over-ssh.html">DNS Round Robin Configuration using Rsync over SSH</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/linux/dns-round-robin-rsync-over-ssh.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Mod_Rewrite Basic Examples</title>
		<link>http://www.askapache.com/htaccess/mod_rewrite-basic-examples.html</link>
		<comments>http://www.askapache.com/htaccess/mod_rewrite-basic-examples.html#comments</comments>
		<pubDate>Tue, 07 Nov 2006 11:49:56 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Htaccess]]></category>

		<guid isPermaLink="false">http://www.askapache.com.com/htaccess-forum/mod_rewrite-basic-examples.html</guid>
		<description><![CDATA[<p>mod_rewrite is very useful in many situations. Yet some behaviors were not so obvious when I started to mess with it.  After many testings, I understand it much better, now. Having said that, I do not pretend to know it perfectly. I also make mistakes.</p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/htaccess/mod_rewrite-basic-examples.html"></a><a href="http://www.askapache.com/htaccess/mod_rewrite-basic-examples.html"><cite>AskApache.com</cite></a></p><p>mod_rewrite is very useful in many situations. Yet some behaviors were not so obvious when I started to mess with it.  After many testings, I understand it much better, now. Having said that, I do not pretend to know it perfectly. I also make mistakes.</p>
<p>So, although I tested all these on my local server and PowWeb, do not trust what I say blindly. Rather, please use it as a suggestion or bases for your own experiments. </p>
<hr />

<h2>First thing</h2>
You need these lines before any rules.

<pre># You need this in your .htaccess on some servers.
# You don&#039;t need it on PowWeb because it&#039;s already set.
&nbsp;
# You must put this line &#039;&#039;&#039;once&#039;&#039;&#039; before to put RewrteRule.
&nbsp;
# You don&#039;t have to put this in many cases.
# But specifying it can reduce the risk of endless looping.
#
# Also, certain internal redirect rules and conditions
# will not work well if you don&#039;t use this line.
# So, put it, and forget about adding / at the beginning of the
# substitute string
&nbsp;
# With "RewriteBase /",  substitute string of RewriteRule will have
# forward slash added automatically.
#
# But this have no effect on %{REQUEST_URI}, and it starts with
# forward slash unlike URL of RewriteRule.
#
# RewriteRule URL: "/" is stripped automatically.
# RewriteRule substitute: "/" is added automatically.
# %(REQUEST_URI}: always start with "/".
&nbsp;
# RewriteRule have following format.
# Each part separated by a space.
&nbsp;
# REGEX  is Perl compatible Regular expression.
&nbsp;
# ex. RewriteRule ^(abc.*)$ xxx$1 [R]
#
#  ^ == beginning of URL
#  $ == end of URL
#  . (period) == matches any one character
#  * == matches with zero or more of previous character.
#
#  The URL is matched against REGEX without "http://host.com/",
#  and the QUERY_STRING part (the part after ? ) stripped.
#  ie. The address: http://zoro.com
&#039;&#039;&#039;/faint.cgi&#039;&#039;&#039;?a=2&amp;amp;b=xxx
#  The URL used in the rule: &#039;&#039;&#039;/faint.cgi&#039;&#039;&#039;
#
#  So, this matches any URL starting with "abc".
#  And entire URL is grouped by ( ) to be used in the substitution
#  (referenced by) $1.
#  As an option, this specify external redirect 302 (Temorary)
&nbsp;
# RewriteRules may have additional Conditions.
&nbsp;
RewriteCond STRING expression [optional flags]
RewriteRule REGEX substitution [optional flags]</pre>


# For the details of REGEX, expressions, substitutions and options,
# you should read Apache module mod_rewrite documentation.

<a href="http://httpd.apache.org/docs/mod/mod_rewrite.html">
mod_rewrite documentation</a>
<a href="http://httpd.apache.org/docs/misc/rewriteguide.html">URL rewriting Guide</a>


<strong>What happens when the rules modify URL (in .htaccess)</strong>

When RewriteRule that changes URL is matched,
modified URL will go through Next roud of processing
from the beginning of the rule sets, again.
This is a very important point.

It's because of the way Apache handles per-directory context
 (.htaccess, or in &lt;directory&gt; tab).
It has to do per-directory auth and other processes for the newly generated path.

In per-server or virtual host context (in httpd.conf), this doesn't happen.


ex.

In this example, URL is modified and the RewriteRule will be
applied again.


ex.

In this example, URL is unchanged.
(For this document, URL is the part of address
without "http://host.com/" and "?QUERY_STRING" portion.)

Thus, it will not go through 2nd round of processing
(the modification on QUERY_STRING does not affect this),
unless it's a URL for a directory and transformed according to
the DirectoryIndex directive or when resulting filepath doesn't exist.


<pre>RewriteRule ^xxx/(.*)$ yyy/$1</pre>

As the 1st rule changes URL, modified URL "/xxx/abcSomething"
will go through next round and checked against from the
1st rule, again.

So, even the 1st rule has [L] (last) option to indicate following
rules to be skipped, '''in the 2nd round''', the URL will match
the next rule, and modified to "/yyy/abcSomething".

Then, this URL will go through 3rd round.
But it will not match any rules, and the processing stops there.

<strong>How to avoid endless processing </strong>

If you make a mistake and processing go into endless loop, Apache will stop after
 preset numbers of times and issue 500 (Internal Server Error) with a log entry saying

"mod_rewrite: maximum number of internal redirects reached. ....".

If you want to see that, try this. (on your home machine...)

ex.

One of the easiest method to avoid endless looping is using %{ENV:REDIRECT_STATUS}


ex1.# Add loop stoper condition
<pre>RewriteRule ^(.*)\.html xyz/whatever.cgi?$1&nbsp; [L]</pre>


ex2.# The loop stopper rule for many following rules
<pre>RewriteRule ^ - [L]</pre>

<pre>RewriteRule ^(.*)/abc\.html$ abc/$1 [L]
RewriteRule ^(.*)$ xyz/$1 [L]</pre>
....

Often RewriteCond with %{REQUEST_URI} has been used.


ex.
<pre>RewriteRule ^(.*)$ xyz/$1</pre>

Note 1. We don't need to put / in front of xyz in the right side of RewriteRule line,
with RewriteBase /.
If we put it, it does not harm most of the cases.
But it will create endless loop easier,
and it will break other rules that does not expect
multiple / in front of URL.
So, it's better not to put it.

Note 2. REQUEST_URI contains "/" + URL
To check from the beginning og REQUEST_URI,
we must use "/" like: ^/something

However, the example code can be writteh like this, saving one REGEX processing.


ex2.

Or, RewriteRule (that does not change URL) and [L] option will do the same.


ex.
<pre>RewriteRule ^(.*)$ xyz/$1</pre>


ex2.
<pre>RewriteRule ^(.*)$ index.php?p=$1</pre>

Often, PHP people uses many many way too many RewriteRules
to achieve SEO friendly URL hype.
By placing a simple rule that exclude any URL with a dot from
being processed, you can save lots of wasteful REGEX processing
for narmal files, such as .html, .jpg, .css.


Example of this loop stopping method:
Generic .htaccess Method for sub/pointed domains

However, you can't use these tricks in some cases.
(a.html =&gt; b.html, b.html =&gt; a.html)


ex.
<pre>RewriteRule b.html a.html</pre>

One alternative is using %{THE_REQUEST}


ex.
<pre>RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /b.html
RewriteRule b.html a.html</pre>

THE_REQUEST contains the first line of HTTP request header.
It is something like "GET /index.html HTTP/1.1".
So, by verifying this variable, we can make sure that
the URL of "b.html" is not coming from the internal redirect
but from the original request.

Note. To match a string with a space, just escape with "\"
as shown in the example above.

We can use %{QUERY_STRING} to check if it is the first round or subsequent
one in some cases. But this method alone can't treat some cases.


# And remove that string from QUERY_STRING
# ($1 is from RewriteRule line, and %1 is from RewriteCond line.)
#
# The first Rule is needed to stop the URL that ends with slashe.
#
<pre>RewriteCond %{QUERY_STRING} __XXX__$
RewriteRule /$ - [L]
RewriteCond %{QUERY_STRING} ^(.*)__XXX__$
RewriteRule ^(.*)$ $1?%1 [L]
&nbsp;
# Add key string to the QUERY_STRING
RewriteRule ^(.*)$ $1?%{QUERY_STRING}__XXX__
&nbsp;
# Following rules will be checked only onece,
# as long as QUERY_STRING is unmodified or the key string is kept.
&nbsp;
# No modification to the QUERY_STRING
RewriteRule ^(other.*)$ rules/$1
&nbsp;
# QUERY_STRING is conserved
RewriteRule ^(more.*)$ rules.cgi?$1%{QUERY_STRING}
&nbsp;
# key string is placed, explicitly.
RewriteRule ^(yetmore.*)$ rules.cgi?$1__XXX___
&nbsp;
I tried to use [E=ENVVAR:STRING] to distinguish the subsequest round but ENV
variables seem to be reset on each round... So, following example for preventing 2nd round does not work.
&nbsp;
RewriteRule ^.*$ - [L]
&nbsp;
RewriteRule ^.*$ - [L,E=DONE:YES]
</pre>
This trick can be used to check if a certain rule is matched in the same round, though.


<pre>RewriteRule ^pattern1$ substitute1
RewriteRule ^pattern2$ substitute2
RewriteRule ^pattern3$ substitute3
&nbsp;
RewriteCond %{ENV:DONE} YES
RewriteRule ^patternX$ substituteX</pre>

But you can use [S] (skip) and/or [C] (chain) in most cases instead of this
%{ENV:VAR} trick.

Rant

I think mod_rewrite is BADLY designed.
It doesn't have definitive way to control looping,
and we can't use variables in the right had side of the RewriteCond.
Also, the fact ENV variables get reset on each round is stupid ...

How to give new ENV variable to cgi

Note. On a server with suExec, most env variables are cleansed by suExec.
You should prefix the env var with 'HTTP_' and it will survive!

We can put any information we want to pass to CGI in QUERY_STRING, though.

[E=VAR:STRING] option can be used to set ENV variable. But it will not go to cgi
if it's set in the URL changing rule, or in the round that has URL changing rule.

These rules should be placed at the beginning of the ruleset so that they are set
again withoutt fail at the final round.


<pre># As this is not usually available to CGI program,
# it is very useful in DIY authentication with CGI.
RewriteRule ^.*$ - [E=HTTP_AUTH:%{HTTP:Authorization}]
&nbsp;
# available in RewriteRules.
RewriteRule ^.*$ - [E=HTTP_TIME:%{TIME}]
&nbsp;
QUERY_STRING can be used for passing parameters, too.
&nbsp;
RewriteRule ^(.*)$ $1?AUTH=%{HTTP:Authorization} [QSA]</pre>
or


__SEPARATOR__ can be anything you want. You don't need it if QUERY_STRING is empty.

You can pass any ENV variable, such as THE_REQUEST or TIME, this way.

This can be usefull for debugging RewriteRule

How to make rules more efficient

It is similar to other programing language.

Identify the resource consuming part, and try to minimize the trafic that goes through that part.

For RewriteCond, "=" is probably the least time consuming of all, and -f, -d, -s, and others more
time consuming. -U and -F could be the most costly one.

REGEX maybe pretty heavy if the string checked is long and the pattern is complex.
 Checking against REQUEST_URI can be heavy because it inclueds both URL part and
QUERY_STRING, which can be very very long...

By using ^ to do forward matching, it may require less backtracking, thus more efficient.
(On powerful servers, the difference can be invisible...)


<pre>RewriteRule ^(.*)$ subdir/$1
&nbsp;
# This is not efficient...and may not work sometime
# because the REQUEST_URI may contain "subdir/"
# in a part of QUERY_STRING, and also it matches
# "/sub/sub-subdir" and "/abcdefgsubdir/" and so on.
&nbsp;
RewriteRule ^(.*)$ subdir/$1</pre>

# Now, it is more efficient and no room for confusion.

Secret directory

I wrote a separate page for secret directory. secretdir.html (

This can be used with CGI Authentication and other tricks.

Anti-Leech, bandwidth saving, Referer blocking

I understand the desire to do these thing. However, it's not really effective, and it often
causes more headaches.

I do not recommend it unless you know well about rewriting and the limited effectiveness
 and potential problems.

If you are a user of PowWeb, we have enough bandwidth allowance to cope with usual
 "Leeching".

If you dislike leeching, maybe you can add your URL on the picture using ImageMagik
or sitebuilder tool soon available from PowWeb!

More about Anti-Leech measures

However, kicking off certain robots is a good practice. Some robots will access well
over several hundreds items per minutes. If your script is hit like this, the server may
experience lots of load. Although there seems to be a built-in safety cut off mechanism
 of PowWeb, we can do our part in this.

## Keep bad robots off.
## Give them blank page instead of 403. Cost less for thr server

<pre>RewriteEngine on
RewriteBase /
&nbsp;
RewriteRule ^blank\.txt - [L]
&nbsp;
RewriteCond %{HTTP_USER_AGENT}
 (MSIECrawler|Ninja|Microsoft|MSFront|WebCopier|Pockey) [NC]
RewriteRule ^(.*)$&nbsp; blank.txt [L]</pre>

Usually, the last rule is like this, "RewriteRule ^(.*)$ - [F]" and it gives 403
Forbidden error with error_log entry.

I don't like to see massive entries in my error_log because detecting more serious
 trouble will be harder due to too many garbage entries.

So, I decided to send them a nice white blank page without any data.

This saves bit of bandwidth, simplifies my error_log, and cost a little less for the
 server because there is no need to make two log entries.

And as it is a little more polite to send blank page with 200 OK response code than
403 Forbidden, it may even reduce the risk of atacks by frustrated youth.

Search Engine friendly URL

It seems to be another hot topics among PHP users.

I think it's better to parse the URL in PHP rather than
trying to do something with mod_rewrite.

The idea is, using such a URL

http://host.net/aa/bb/cc/dd

is better than usual php thing


http://host.net/index.php?aa=bb&amp;cc=dd

And with mod_rewrite,

<pre>RewriteRule ^/*(([^/]+)/+([^/]+)/+([^/]+)/*(.*)$ index.php?$1=$2&amp;amp;$3=$4 [L]</pre>

do something like this.

While simple example like this works, more complex rule could be tricky.
Although the string parsing power of mod_rewrite is not that bad,
it should be much easier to do your own parsing in php
using $_SERVER{QUERY_STRING} or $_SERVER{REQUEST_URI} and other variables.

Samething apllies to Perl and other language.
But php people seem to be more eager to do this...somehow.

Maybe they don't want to change their script or they don't know
what to change, how to change...

Oh well, here is very inefficient but flexible version.
This one can treat any number of parameters.
But I think it is a resource consuming hog.


<pre>RewriteRule ^/*([^/]+)/+([^/]+)(.*)/*$ $3?$1=$2 [L,QSA]
RewriteRule ^([^/]+)$ index.php?$1 [L,QSA]</pre>

Tring to double the parameters treated in one round.


<pre>RewriteRule ^/*([^/]+)/+([^/]+)/+([^/]+)/+([^/]+)(.*)/*$ $5?$1=$2&amp;amp;$3=$4 [L,QSA]
RewriteRule ^([^/]+)$ index.php?$1 [L,QSA]</pre>

A little better idea is, using such a URL

http://host.net/bb/dd (instead of
 http://host.net/aa/bb/cc/dd)

to obtain this.


http://host.net/index.php?aa=bb&amp;cc=dd


<pre>RewriteRule ^/*(([^/]+)/+([^/]+)/*(.*)$ index.php?aa=$1&amp;amp;bb=$2&amp;amp;$3 [L]</pre>

While the URL looks better and more efficient, this one is not flexible.

Serve dynamic page statically

Generating a page for each and every request is a pure waste of server resources unless
there is a good reason.

Most of the time, exactly same page can be served many times. So, it makes sense to
 implement "generate once, serve many times" system.

I wrote an example of such system (very simple one) for someone.

Please take a look if you are intersted. [cache.html]

ampescape ?

I saw a question about RewriteMap, recently. As we can't use RewriteMap in .htaccess,
I wrote a RewriteRule that escape &amp; to %26, as ampescape would do.


<pre>RewriteRule ^([^&amp;amp;]*)&amp;amp;(.*)$ $1\%26$2 [NE,N]
RewriteRule ^([^&amp;amp;]*)$ whatever.php?title=$1 [L]</pre>

Some wiki and php scripts have difficulity with a URL with &amp; because it will split
QUERY_STRING with it.

But this solution is not so efficient.

You had better modify script with this type of rule.



And use $_SERVER{'QUERY_STIRING'} in place of

$_GET{'title'},$_POST{'title'},or $REQUEST{'title'}.

Note. $_SERVER{'QUERY_STIRING'} may contain "%20" in it. If so, you may have to
replace it with ' '(space). (php may URI_decode %20 automatically...

but I don't know well about php.)

Banner rotation

Simple (and not so simple) banner rotation can be done with rewriterule.

See BannerRotation

Trouble shooting

If the rewrite has external redirect, it essential to have a tool that shows response headers.

See RedirectProblems

What else?

You had better consult mod_rewrite documents and mod_rewrite Guide, as well as other
web pages and forums.

<a href="http://httpd.apache.org/docs/mod/mod_rewrite.html">mod_rewrite documentation</a>

<a href="http://httpd.apache.org/docs/misc/rewriteguide.html">URL rewriting Guide</a>

<a href="http://www.htaccesselite.com/commonly-used-htaccess-code-examples-vt119.html">
Commonly Used htaccess Code examples</a></p><p><a href="http://www.askapache.com/htaccess/mod_rewrite-basic-examples.html"></a><a href="http://www.askapache.com/htaccess/mod_rewrite-basic-examples.html">Mod_Rewrite Basic Examples</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/mod_rewrite-basic-examples.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

