<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.3" -->
<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/"
	>

<channel>
	<title>edrackham &#187; .htaccess</title>
	<link>http://edrackham.com</link>
	<description>PHP, MySQL, and Other Web Snippets!</description>
	<pubDate>Wed, 25 Jun 2008 13:38:14 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
	<language>en</language>
			<item>
		<title>Online .htpasswd Generator</title>
		<link>http://edrackham.com/apache/online-htpasswd-generator/</link>
		<comments>http://edrackham.com/apache/online-htpasswd-generator/#comments</comments>
		<pubDate>Fri, 07 Mar 2008 13:51:25 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
		
		<category><![CDATA[.htaccess]]></category>

		<category><![CDATA[Apache]]></category>

		<category><![CDATA[Tools]]></category>
<category>generator</category><category>htpasswd</category><category>prevent access</category><category>secure directory</category><category>Tools</category>
		<guid isPermaLink="false">http://edrackham.com/apache/online-htpasswd-generator/</guid>
		<description><![CDATA[Use the following .htpasswd generator to secure your Apache web directories.
Your browser does not support IFRAMES. Please view the generator at http://edrackham.com/tutorials/online-htpasswd-generator/
Make sure you have a .htaccess and .htpasswd file in the directory you want to secure, then add the entries once you&#039;ve generated your password.






]]></description>
			<content:encoded><![CDATA[<p>Use the following .htpasswd generator to secure your Apache web directories.</p>
<p><iframe id="htpasswd_generator" name="htpasswd_generator" width="460" scrolling="no" height="130" frameborder="0" src="http://edrackham.com/tutorials/online-htpasswd-generator/?iframe">Your browser does not support IFRAMES. Please view the generator at http://edrackham.com/tutorials/online-htpasswd-generator/</iframe></p>
<p>Make sure you have a .htaccess and .htpasswd file in the directory you want to secure, then add the entries once you&#039;ve generated your password.</p>
<p>
<div align="center"><script type="text/javascript"><!--
google_ad_client = "pub-4159646232668987";
/* 468x60, created 3/10/08 */
google_ad_slot = "7234899452";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
</p>
]]></content:encoded>
			<wfw:commentRss>http://edrackham.com/apache/online-htpasswd-generator/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Top 10 .htaccess Tips and Tricks</title>
		<link>http://edrackham.com/apache/top-10-htaccess-tips-and-tricks/</link>
		<comments>http://edrackham.com/apache/top-10-htaccess-tips-and-tricks/#comments</comments>
		<pubDate>Thu, 06 Mar 2008 00:23:39 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
		
		<category><![CDATA[.htaccess]]></category>

		<category><![CDATA[Apache]]></category>

		<category><![CDATA[tips]]></category>

		<category><![CDATA[tricks]]></category>
<category>.htaccess</category><category>apache</category><category>tips</category><category>tricks</category>
		<guid isPermaLink="false">http://edrackham.com/apache/top-10-htaccess-tips-and-tricks/</guid>
		<description><![CDATA[Custom Error Documents
Creating custom documents gives your site a more professional look, as not only are you providing a &#039;net&#039; to catch unsuspecting visitors when they follow a bad link and such like, but they also allow you to customise the style of the page so you can maintain your basic site design by adding [...]]]></description>
			<content:encoded><![CDATA[<h4>Custom Error Documents</h4>
<p>Creating custom documents gives your site a more professional look, as not only are you providing a &#039;net&#039; to catch unsuspecting visitors when they follow a bad link and such like, but they also allow you to customise the style of the page so you can maintain your basic site design by adding HTML.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="co1"># custom error documents</span><br />
<span class="kw1">ErrorDocument</span> <span class="nu0">401</span> /error/<span class="nu0">401</span>.php<br />
<span class="kw1">ErrorDocument</span> <span class="nu0">403</span> /error/<span class="nu0">403</span>.php<br />
<span class="kw1">ErrorDocument</span> <span class="nu0">404</span> /error/<span class="nu0">404</span>.php<br />
<span class="kw1">ErrorDocument</span> <span class="nu0">500</span> /error/<span class="nu0">500</span>.php</div>
</div>
<p>
<div align="center"><script type="text/javascript"><!--
google_ad_client = "pub-4159646232668987";
/* 468x60, created 3/10/08 */
google_ad_slot = "7234899452";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
</p>
<h4>Control Access</h4>
<p>Being able to control access to certain areas of your server can be very useful. The following example demonstrates how to only allow access from those connecting from a 192.168.0 LAN IP pool. This could be easily modified to only allow access from a single remote IP address or addresses.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="co1"># no nasty crackers in here!</span><br />
<span class="kw1">order</span> <span class="kw1">deny</span>,<span class="kw1">allow</span><br />
<span class="kw1">deny</span> <span class="kw1">from</span> <span class="kw1">all</span><br />
<span class="kw1">allow</span> <span class="kw1">from</span> <span class="nu0">192</span>.<span class="nu0">168</span>.<span class="nu0">0</span>.<span class="nu0">0</span>/<span class="nu0">24</span><br />
<span class="co1"># this would do the same thing..</span><br />
<span class="co1">#allow from 192.168.0 </span><br />
&nbsp;</div>
</div>
<h4>Hide and Deny Files</h4>
<p>Hiding and denying access to files is crucial to servers that have sensitive data held within files that may be accessible via the website(s) on it. The following example demonstrates how to prevent acces to any files ending with .log - and is case insensitive (i.e. .LoG / .lOG / .loG).</p>
<div class="codesnip-container" >
<div class="codesnip">&lt;Files ~ <span class="st0">&#034;^.*<span class="es0">\.</span>([Ll][Oo][Gg])&#034;</span>&gt;<br />
&nbsp;<span class="kw1">Order</span> <span class="kw1">allow</span>,<span class="kw1">deny</span><br />
&nbsp;<span class="kw1">Deny</span> <span class="kw1">from</span> <span class="kw1">all</span><br />
&nbsp;<span class="kw1">Satisfy</span> <span class="kw1">All</span><br />
&lt;/Files&gt;</div>
</div>
<h4>Basic Rewriting</h4>
<p>I have written a <a href="http://edrackham.com/apache/beginners-mod_rewrite-tutorial/" title="mod_rewrite tutorial">mod_rewrite tutorial</a>, but this is worth a mention as a top 10 tip for .htaccess files as it&#039;s becoming more and more commonly used these days - primarily for SEO purposes.</p>
<p>This example will redirect a request for <strong>http://edrackham.com/page_one.htm</strong> to <strong>http://edrackham.com/page_one.php</strong>. The <em>r=301</em> tells apache to send a proper HTTP <em>Permanently Moved</em> redirection (301), which will update the address bar in the browser window to show &#039;page_one.php&#039;. Without this, you&#039;d still see &#039;page_one.htm&#039; even though you&#039;re seeing a PHP page. This helps SEO, as spiders and search engines will update their listings to reflect the PHP versions.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw1">Options</span> +<span class="kw2">FollowSymlinks</span><br />
<span class="kw1">RewriteEngine</span> <span class="kw2">on</span><br />
<span class="kw1">RewriteRule</span> ^<span class="br0">&#40;</span>.+<span class="br0">&#41;</span>\.htm$ http://edrackham.com/$<span class="nu0">1</span>.php <span class="br0">&#91;</span>r=<span class="nu0">301</span>,nc<span class="br0">&#93;</span></div>
</div>
<p>
<div align="center"><script type="text/javascript"><!--
google_ad_client = "pub-4159646232668987";
/* 468x60, created 3/10/08 */
google_ad_slot = "7234899452";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
</p>
<h4>Shorter URLs</h4>
<p>Shorter URLs are beneficial, as visitors that persist in typing full URLs won&#039;t have to type as much, and they&#039;re more memorable. Do they benefit SEO, even though the full URL contains the same keywords? I don&#039;t know, maybe someone can tell me.</p>
<p>This example will rewrite a page requested as <strong>http://edrackham.com/files/code/apache.zip</strong> to <strong>http://edrackham.com/download.php?type=code&amp;file=apache</strong>.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw1">Options</span> +<span class="kw2">FollowSymlinks</span><br />
<span class="kw1">RewriteEngine</span> <span class="kw2">on</span><br />
<span class="kw1">RewriteRule</span> ^<span class="kw1">files</span>/<span class="br0">&#40;</span>.+<span class="br0">&#41;</span>/<span class="br0">&#40;</span>.+<span class="br0">&#41;</span>.zip download.php?type=$<span class="nu0">1</span>&amp;file=$<span class="nu0">2</span> <span class="br0">&#91;</span>nc<span class="br0">&#93;</span></div>
</div>
<h4>Prevent Hotlinking</h4>
<p>Preventing hotlinking can reduce bandwidth, by disallowing other websites from displaying images hosted on your server. The following rule basically says that if the referer is NOT edrackham.com, run the following rule. The rule (on the next line) says that if the request is for a .gif, .jpg or.png then redirect the visitor to http://edrackham.com/img/hotlink_f_o.png. I&#039;ll leave you to work out what the &#039;f_o&#039; stands for.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw1">Options</span> +<span class="kw2">FollowSymlinks</span><br />
<span class="co1"># no hot-linking</span><br />
<span class="kw1">RewriteEngine</span> <span class="kw2">On</span><br />
<span class="kw1">RewriteCond</span> %<span class="br0">&#123;</span>HTTP_REFERER<span class="br0">&#125;</span> !^$<br />
<span class="kw1">RewriteCond</span> %<span class="br0">&#123;</span>HTTP_REFERER<span class="br0">&#125;</span> !^http://<span class="br0">&#40;</span>www\.<span class="br0">&#41;</span>?edrackham\.com/ <span class="br0">&#91;</span>nc<span class="br0">&#93;</span><br />
<span class="kw1">RewriteRule</span> .*\.<span class="br0">&#40;</span>gif|jpg|png<span class="br0">&#41;</span>$ http://edrackham.com/img/hotlink_f_o.png <span class="br0">&#91;</span>nc<span class="br0">&#93;</span></div>
</div>
<h4>Hiding Page Extension</h4>
<p>Similar to the mod_rewrite code above, this will redirect a request for <strong>product-<em>3</em>.html</strong> to <strong>products.php?id=<em>3</em></strong>. As we&#039;re not using <em>r=301</em>, the requested page will remain in the browser&#039;s address bar.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw1">Options</span> +<span class="kw2">FollowSymlinks</span><br />
<span class="kw1">RewriteEngine</span> <span class="kw2">on</span><br />
<span class="kw1">RewriteRule</span> ^product-<span class="br0">&#40;</span><span class="br0">&#91;</span><span class="nu0">0</span>-<span class="nu0">9</span><span class="br0">&#93;</span>+<span class="br0">&#41;</span>\.html$ products.php?id=$<span class="nu0">1</span></div>
</div>
<h4>Ban Selected User Agents</h4>
<p>In my opinion, it&#039;d be ace to block all requests from a Microsoft user agent, but alas, that wouldn&#039;t be too cool as some people are still hell-bent on using a non-standards compliant browser. Having said that, Microsoft is making their new <a href="http://edrackham.com/web-standards/standards-compliant-internet-explorer-ie8/" title="Microsoft to release standards compliant browser. Yes really!">IE8 release standards compliant</a> by default.</p>
<p>The following provides some examples for blocking requests to your server from certain user agents.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="co1">#####################################</span><br />
<span class="co1"># Deny Useragents</span><br />
<span class="co1">#####################################</span></p>
<p><span class="kw1">RewriteCond</span> %<span class="br0">&#123;</span>HTTP_USER_AGENT<span class="br0">&#125;</span> ^FrontPage <span class="br0">&#91;</span>NC,OR<span class="br0">&#93;</span><br />
<span class="kw1">RewriteCond</span> %<span class="br0">&#123;</span>HTTP_USER_AGENT<span class="br0">&#125;</span> ^Java.* <span class="br0">&#91;</span>NC,OR<span class="br0">&#93;</span><br />
<span class="kw1">RewriteCond</span> %<span class="br0">&#123;</span>HTTP_USER_AGENT<span class="br0">&#125;</span> ^Microsoft.URL <span class="br0">&#91;</span>NC,OR<span class="br0">&#93;</span><br />
<span class="kw1">RewriteCond</span> %<span class="br0">&#123;</span>HTTP_USER_AGENT<span class="br0">&#125;</span> ^MSFrontPage <span class="br0">&#91;</span>NC,OR<span class="br0">&#93;</span><br />
<span class="kw1">RewriteCond</span> %<span class="br0">&#123;</span>HTTP_USER_AGENT<span class="br0">&#125;</span> ^Offline.Explorer <span class="br0">&#91;</span>NC,OR<span class="br0">&#93;</span><br />
<span class="kw1">RewriteCond</span> %<span class="br0">&#123;</span>HTTP_USER_AGENT<span class="br0">&#125;</span> ^<span class="br0">&#91;</span>Ww<span class="br0">&#93;</span>eb<span class="br0">&#91;</span>Bb<span class="br0">&#93;</span>andit <span class="br0">&#91;</span>NC,OR<span class="br0">&#93;</span><br />
<span class="kw1">RewriteCond</span> %<span class="br0">&#123;</span>HTTP_USER_AGENT<span class="br0">&#125;</span> ^Zeus <span class="br0">&#91;</span>NC<span class="br0">&#93;</span><br />
<span class="kw1">RewriteRule</span> ^.*$ - <span class="br0">&#91;</span>F<span class="br0">&#93;</span></div>
</div>
<h4>Making Other Filetypes Executable</h4>
<p>Ever wanted to make your site look like it runs off a new language such as .w00t files? Well you can with .htaccess! Adding this neat one-liner, you can request .w00t files, which will be served and interpreted as .php type files.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="kw1">AddType</span> application/x-httpd-php .w00t</div>
</div>
<p>
<div align="center"><script type="text/javascript"><!--
google_ad_client = "pub-4159646232668987";
/* 468x60, created 3/10/08 */
google_ad_slot = "7234899452";
google_ad_width = 468;
google_ad_height = 60;
google_cpa_choice = ""; // on file
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
</p>
<h4>Force Media Downloads</h4>
<p>Sometimes, when clicking on media files, the browser wants to play or stream it directly from itself. Using the following rules, media files (.avi/.mpg/.wmv/.mp3 in this example) will provide a download dialog box instead.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="co1"># instruct browser to download multimedia files</span><br />
<span class="kw1">AddType</span> application/octet-stream .avi<br />
<span class="kw1">AddType</span> application/octet-stream .mpg<br />
<span class="kw1">AddType</span> application/octet-stream .wmv<br />
<span class="kw1">AddType</span> application/octet-stream .mp3</div>
</div>
<h4>Require SSL</h4>
<p>Sometimes you will require an SSL connection. This following snippet will do just that!</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="co1"># require SSL</span><br />
SSLOptions +StrictRequire<br />
SSLRequireSSL<br />
SSLRequire %<span class="br0">&#123;</span>HTTP_HOST<span class="br0">&#125;</span> eq <span class="st0">&#034;domain.tld&#034;</span><br />
<span class="kw1">ErrorDocument</span> <span class="nu0">403</span> https://domain.tld</p>
<p><span class="co1"># require SSL without mod_ssl</span><br />
<span class="kw1">RewriteCond</span> %<span class="br0">&#123;</span>HTTPS<span class="br0">&#125;</span> !=<span class="kw2">on</span> <span class="br0">&#91;</span>NC<span class="br0">&#93;</span><br />
<span class="kw1">RewriteRule</span> ^.*$ https://%<span class="br0">&#123;</span>SERVER_NAME<span class="br0">&#125;</span>%<span class="br0">&#123;</span>REQUEST_URI<span class="br0">&#125;</span> <span class="br0">&#91;</span>R,L<span class="br0">&#93;</span></div>
</div>
<p>Sources:<br />
http://corz.org/serv/tricks/htaccess.php<br />
http://roshanbh.com.np/2008/02/hide-php-url-rewriting-htaccess.html<br />
http://expressproducts.net/htaccess.htm<br />
http://perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/#usa4<br />
http://phpsecurity.wordpress.com/2007/12/22/htaccess-tips-and-tricks/</p>
]]></content:encoded>
			<wfw:commentRss>http://edrackham.com/apache/top-10-htaccess-tips-and-tricks/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Beginner&#039;s Mod_Rewrite Tutorial</title>
		<link>http://edrackham.com/apache/beginners-mod_rewrite-tutorial/</link>
		<comments>http://edrackham.com/apache/beginners-mod_rewrite-tutorial/#comments</comments>
		<pubDate>Wed, 07 Nov 2007 14:26:38 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
		
		<category><![CDATA[.htaccess]]></category>

		<category><![CDATA[Apache]]></category>
<category>.htaccess</category><category>mod rewrite</category>
		<guid isPermaLink="false">http://blog.edrackham.com/apache/beginners-mod_rewrite-tutorial/</guid>
		<description><![CDATA[Have you seen those websites such as Digg and SVP that use fancy URLs such as http://domain.com/page_content? Yeah, sure this could be nearly achieved by simply renaming your pages to something like page_content.htm - but that would result in you having to change every page on your site to a suitably written filename, as well [...]]]></description>
			<content:encoded><![CDATA[<p>Have you seen those websites such as <a href="http://digg.com" title="Community based popularity website.">Digg</a> and <a href="http://svp.co.uk" title="Cheap computer consumables, hardware and media.">SVP</a> that use fancy URLs such as http://domain.com/<strong>page_content</strong>? Yeah, sure this could be <em>nearly </em>achieved by simply renaming your pages to something like <strong>page_content.htm</strong> - but that would result in you having to change every page on your site to a suitably written filename, as well as relying on static pages. I&#039;m going to attempt to demonstrate just how easy it really is to utilise mod_rewrite to have fancy - even &#034;web 2.0&#034; - URLs within your site.</p>
<p> <a href="http://edrackham.com/apache/beginners-mod_rewrite-tutorial/#more-7" class="more-link">(more&#8230;)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://edrackham.com/apache/beginners-mod_rewrite-tutorial/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
