<?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>Scattered Thoughts &#187; htaccess</title>
	<atom:link href="http://www.kunaal84.com/blog/category/htaccess/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kunaal84.com/blog</link>
	<description>where you go when not looking for the answer to life, the universe and everything</description>
	<lastBuildDate>Tue, 15 Dec 2009 14:04:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Using .htaccess to password protect a directory</title>
		<link>http://www.kunaal84.com/blog/2007/09/13/using-htaccess-to-password-protect-a-directory/</link>
		<comments>http://www.kunaal84.com/blog/2007/09/13/using-htaccess-to-password-protect-a-directory/#comments</comments>
		<pubDate>Thu, 13 Sep 2007 15:18:25 +0000</pubDate>
		<dc:creator>Kunaal Ramchandani</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[tips&tricks]]></category>
		<category><![CDATA[directory_listings]]></category>
		<category><![CDATA[password_protection]]></category>

		<guid isPermaLink="false">http://www.kunaal84.com/blog/2007/09/13/using-htaccess-to-password-protect-a-directory/</guid>
		<description><![CDATA[I came across this issue a few days ago, I was required to create a secure area on a web server where I could upload large files. The directory where these files were uploaded should be password protected so that only someone authorised can access it, and as a further protection, the directory should have [...]]]></description>
			<content:encoded><![CDATA[<p>I came across this issue a few days ago, I was required to create a secure area on a web server where I could upload large files. The directory where these files were uploaded should be password protected so that only someone authorised can access it, and as a further protection, the directory should have its directory listings display turned off. Client Side password protection like using Javascript is not very good, because it can be disabled<br />
Figured this might make someone else&#8217;s life easier in the future</p>
<ul>
<li>Using a FTP client, login to your server.</li>
<li>Create a new directory in your public folder (www, public_html etc). Remember to keep the name something people will not be able to guess. something like &#8220;S3cr3tF0ld3r&#8221; maybe</li>
<li>Create an empty .htaccess file and upload it to that directory</li>
<li>The first and easiest step to carry out is to disable directory listings. Use the following code (also described <a href="http://www.kunaal84.com/blog/2007/08/27/tips-and-tricks-with-the-htaccess-file-part-1/">here</a>)
<pre><code>Options All -Indexes</code></pre>
</li>
<li>Now comes the slightly trickier part, password protecting the directory:<br />
I first add the following lines to the .htaccess file<br/></p>
<pre><code>AuthUserFile /path/to/.htpasswd
AuthName "My own Login Area"
AuthType Basic</code></pre>
</li>
<li>I then add the username and encrypted password to the .htpasswd file and place it in the same place mentioned in the htaccess above.<br />
The little script below generates the uname:password combination<br/></p>
<p><script type="text/javascript" src="/php_scripts/aja.js"></script></p>
<form name="f1" action="">
  username:<br />
<input name="uname" type="text" /><br/><br />
  password:<br />
<input name="word" type="text" /> <br/> </p>
<input value="Encrypt" type="button" onclick='JavaScript:xmlhttpPost("http://www.kunaal84.com/php_scripts/htpasswd_encrypt.php")' />
<div id="result"></div>
</form>
</li>
<li>You can test this <a href="http://www.kunaal84.com/S3cr3tF0ld3r/d.txt">here</a>, username and password are both &#8216;test&#8217;</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.kunaal84.com/blog/2007/09/13/using-htaccess-to-password-protect-a-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tips and tricks with the .htaccess file &#8211; Part 1</title>
		<link>http://www.kunaal84.com/blog/2007/08/27/tips-and-tricks-with-the-htaccess-file-part-1/</link>
		<comments>http://www.kunaal84.com/blog/2007/08/27/tips-and-tricks-with-the-htaccess-file-part-1/#comments</comments>
		<pubDate>Mon, 27 Aug 2007 14:46:15 +0000</pubDate>
		<dc:creator>Kunaal Ramchandani</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[tips&tricks]]></category>

		<guid isPermaLink="false">http://www.kunaal84.com/blog/2007/08/27/tips-and-tricks-with-the-htaccess-file-part-1/</guid>
		<description><![CDATA[.htaccess (which stands for Hypertext Access) are text files that are used to make configuration changes on an Apache Server. It contains a series of &#8216;directives&#8217; for the server to follow, these directives are then applied to the folder the .htaccess file is placed in and also to all its sub-folders.For htaccess novices, it is [...]]]></description>
			<content:encoded><![CDATA[<p>.htaccess (which stands for <em>Hypertext Access</em>) are text files that are used to make configuration changes on an Apache Server. It contains a series of  &#8216;directives&#8217; for the server to follow, these directives are then applied to the folder the .htaccess file is placed in and also to all its sub-folders.For htaccess novices, it is important to note that small syntax errors can result at times in serious issues, so it is always a good idea to always backup your site before making major changes to the .htaccess file. I am no expert in .htaccess, but here are some directives I have found really useful.<br />
<span id="more-5"></span><br />
The following are some of the most useful directives I have used:</p>
<h4>1. URL Canonicalisation</h4>
<p>Some search engines treat www.yoursite.com and yoursite.com as 2 separate sites, now if you are interested in SEO (and pretty much everyone nowadays is) this could lead to bigger issues. Using .htaccess you can make sure that all users will see the url you want them to see.</p>
<pre><code>RewriteEngine On

RewriteCond %{HTTP_HOST} ^kunaal84.com$ [NC]

RewriteRule ^(.*)$ http://www.kunaal84.com/$1 [L,R=301]</code></pre>
<p>The above piece of code returns a 301 permanent redirect error if it receives a request for &#8220;kunaal84.com&#8221; and redirects the user to &#8220;www.kunaal84.com&#8221;.</p>
<h4>2. Restrict access</h4>
<h5> A Single File</h5>
<pre><code><files>order allow,deny

deny from all

</files></code></pre>
<p>Add the above block of code and replace the file name &#8220;restricted_file.html&#8221;, with the name of the file you want to restrict access to.</p>
<h5>File Types</h5>
<pre><code><filesmatch>Order Allow,Deny

Deny from all

</filesmatch></code></pre>
<p>Add the above block of code to restrict access to all files of type &#8220;.php and .css&#8221;, add more files as you see fit.</p>
<h4>3. Disable Directory Listing</h4>
<p>If you are missing a default page in your root folder, everything in it becomes visible and accessible to any visitor, the following code directive prevents the directory from listing its files and returns a &#8220;Forbidden&#8221; message</p>
<pre><code>Options All -Indexes</code></pre>
<h4>4. Change Default Index Page</h4>
<p>You can tell your server to show another file as the default index file instead of the usual index.html/index.htm<br />
For example to show new_index_file.html as the default file use</p>
<pre><code>DirectoryIndex new_index_file.html</code></pre>
<h4>5. Parse an Html File Using the PHP Parser</h4>
<p>Sometimes you might need to parse your html files using the php parser, to do this use the following directive</p>
<pre><code>AddType application/x-httpd-php .html</code></pre>
<h4>6. Use Custom Error Pages</h4>
<p>Use the following directive if you want to display your own 404 page instead of the server default</p>
<pre><code>ErrorDocument 404 /errors/404.html</code></pre>
<h4>7. Redirects</h4>
<p>The following directive carries out a simple 301 redirect</p>
<pre><code>redirect 301 /directory/old_file.html http://www.my_domain.com/new_directory/newfile.html</code></pre>
<h4>8. Stop Hotlinking</h4>
<p>To prevent bandwidth thieves, use the following block of code. This prevents hotlinking of .gif, .jpg and .png files (more can be added)</p>
<pre><code><ifmodule>

RewriteEngine on

RewriteCond %{HTTP_REFERER} !^$

RewriteCond %{HTTP_REFERER} !^http://(www.)?your_domain_name.com/.*$ [NC]

RewriteRule .*.(gif|jpg|png)$ - [F,L]

</ifmodule>

</code></pre>
<p>If you prefer to teach them a lesson, serve some alternate content use</p>
<pre><code><ifmodule>RewriteEngine on

RewriteCond %{HTTP_REFERER} !^$

RewriteCond %{HTTP_REFERER} !^http://(www.)?your_domain_name.com/.*$ [NC]

RewriteRule .*.(gif|jpg|png)$ http://www.your_domain_.com/alternate_image.bmp [R,NC,L]

</ifmodule></code></pre>
<p>Bibliography:<br />
<a href="http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html">Apache mod_rewrite</a><br />
<a href="http://httpd.apache.org/docs/trunk/howto/htaccess.html">htaccess tutorial</a></p>
<p>Cool Software:<br />
<a href="http://cooletips.de/htaccess/">Automatic .htaccess Generator</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kunaal84.com/blog/2007/08/27/tips-and-tricks-with-the-htaccess-file-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
