<?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>CSSKarma &#187; htaccess</title>
	<atom:link href="http://www.csskarma.com/blog/tag/htaccess/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.csskarma.com/blog</link>
	<description>display your &#60;style&#62;</description>
	<lastBuildDate>Sun, 11 Jul 2010 04:57:06 +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>Redirection Options</title>
		<link>http://www.csskarma.com/blog/redirection-options/</link>
		<comments>http://www.csskarma.com/blog/redirection-options/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 15:40:58 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[meta]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.csskarma.com/blog/?p=736</guid>
		<description><![CDATA[Lately, I&#8217;ve been having to work with a lot of redirects and I was going through different redirection options with a client. So I thought I would do a quick write up about the different types of redirection. I also haven&#8217;t seen a collection of these in one place, so I thought I would put [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.csskarma.com/blog/wp-content/uploads/banner_redirection.png" alt="article banner"></p>
<p>Lately, I&#8217;ve been having to work with a lot of redirects and I was going through different redirection options with a client. So I thought I would do a quick write up about the <strong>different types of redirection</strong>.</p>
<p>I also haven&#8217;t seen a collection of these in one place, so I thought I would put this together.</p>
<p>There are a few different types that are commonly use when redirecting users:</p>
<ul>
<li>.htaccess / apache</li>
<li>php header</li>
<li>javascript</li>
<li>meta refresh</li>
</ul>
<p>The top two are the one&#8217;s you&#8217;ll be using most often, I don&#8217;t really recommend the last two. But they <em>are</em> available, so I think they&#8217;re worth noting. So here they are in the order I would recommend: </p>
<h3>.htaccess / apache redirects</h3>
<pre><code>Redirect /old_directory http://example.com/newdirectory</code></pre>
<p>This redirection is most efficient at the apache level, but if you&#8217;re like me and are on shared hosting, getting into the apache installation probably isn&#8217;t an option. In that case you can put this in an <a href="http://www.csskarma.com/blog/creating-an-htaccess-template/">.htaccess file</a> in the root directory of your site.</p>
<p>Using an .htaccess redirection is great for moving entire sites because you can not only redirect a page, but you can redirect entire sites and subdirectories with one line of code.</p>
<h3>PHP header redirects</h3>
<pre><code>&lt;?php header('Location: http://example.com/newdirectory/'); ?&gt;</code></pre>
<p>PHP header redirects are good for single page redirects and if you&#8217;re not comfortable working with the .htaccess file. This code goes at the very top of the page you&#8217;re trying to redirect. If it&#8217;s not there you may get a &#8220;headers already sent&#8221; error.</p>
<p>If you&#8217;re publishing out static HTML files, you can still use this by adding this code into your .htaccess file:</p>
<pre><code>AddType application/x-httpd-php .php .html .htm</code></pre>
<p>This will let you <strong>execute PHP in an HTML file</strong>.</p>
<h3>JavaScript redirects</h3>
<pre><code>&lt;script type="text/javascript"&gt;
&lt;!--
window.location = "http://example.com/newdirectory"
//--&gt;
&lt;/script&gt;</code></pre>
<p>JavaScript redirects are generally not used unless you&#8217;ve exhausted the other two options. If you don&#8217;t have access to the .htaccess file AND you can&#8217;t run server-side script on your page, this is an OK fallback option, but you have to make sure to provide a link to the forwarding page incase a user is browsing without JavaScript.</p>
<h3>Meta redirects</h3>
<pre><code>&lt;meta http-equiv="refresh" content="0;URL=http://example.com/newdirectory"&gt;</code></pre>
<p>As your last option, I don&#8217;t see this in the wild anymore, but it&#8217;s worth mentioning that it does exist and does technically work (I&#8217;m not sure about it&#8217;s validity in HTML 5). You would place this in the document HEAD with the rest of the meta elements.</p>
<p>content=0 is a second timer for the redirect, I have this one set to 0 so it will redirect immediately.</p>
<p><strong>Those are the options I&#8217;ve used in the past; did I miss anything? Maybe an ASP redirect? Let me know!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.csskarma.com/blog/redirection-options/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Using .htaccess to Prevent Bandwidth Theft</title>
		<link>http://www.csskarma.com/blog/preventing-bandwidth-theft/</link>
		<comments>http://www.csskarma.com/blog/preventing-bandwidth-theft/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 15:29:26 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[HTTP]]></category>

		<guid isPermaLink="false">http://www.csskarma.com/blog/?p=447</guid>
		<description><![CDATA[Every once in a while Google Analytics will turn up a peculiar behavior where you can tell someone is linking directly to an image hosted on your Web server. Sometimes it can be for good reasons like giving you credit for a project, or make sure files are synced up (cross-domain projects); but it&#8217;s usually [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.csskarma.com/images/articles/bandwidth-theft.jpg" alt="article banner"/></p>
<p>Every once in a while Google Analytics will turn up a peculiar behavior where you can tell someone is linking directly to an image hosted on your Web server. Sometimes it can be for good reasons like giving you credit for a project, or make sure files are synced up (cross-domain projects); but it&#8217;s usually just out of ignorance or laziness (or myspace).</p>
<p>Either way, hotlinking images like that steals your bandwidth and can effect the performance of your server. So you want to stop it.</p>
<p>There are a few ways you can do this; some people output a special image to a bandwidth thief that says something like &#8220;Stop stealing my images&#8221;. I don&#8217;t like that mainly because you&#8217;re intentionally degrading your bandwidth to teach someone a lesson about hotlinking? Bleh.</p>
<p>I prefer using a 403 error, it works just as well in my opinion, and gets the point accross.</p>
<h5>.htaccess code</h5>
<pre><code>RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?csskarma\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ - [F]</</code></pre>
<p>Put that in your .htaccess file (in your root directory). If you don't have an .htaccess file, just create an empty file in the root and name it ".htaccess". Then put this code in there and you'll be good to go.</p>
<p>Don't forget to change out "csskarma" for your web site. You'll definitely notice if you forget that bit.</p>
<h4>What's going on</h4>
<p>Turn on the rewrite condition:</p>
<pre><code>RewriteEngine On</code></pre>
<p>Match any request for csskarma.com (NC means "no case" it will match upper or lower case requests):</p>
<pre><code>RewriteCond %{HTTP_REFERER} !^http://(.+\.)?csskarma\.com/ [NC]</code></pre>
<p>Allow empty requests, these are harmless and often 404 errors anyway</p>
<pre><code>RewriteCond %{HTTP_REFERER} !^$</code></pre>
<p>Replace the stolen image with a 403 "forbidden" error</p>
<pre><code>RewriteRule .*\.(jpe?g|gif|bmp|png)$ - [F]</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.csskarma.com/blog/preventing-bandwidth-theft/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>This Week in Links 9/24</title>
		<link>http://www.csskarma.com/blog/this-week-in-links-4/</link>
		<comments>http://www.csskarma.com/blog/this-week-in-links-4/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 17:20:15 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Web Standards]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[desktop]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[lunch]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[opera]]></category>
		<category><![CDATA[training]]></category>
		<category><![CDATA[zine]]></category>

		<guid isPermaLink="false">http://www.csskarma.com/blog/?p=107</guid>
		<description><![CDATA[Opera Web Standards Curriculum Ever since Opera accepted that no one uses their browser for general browsing they&#8217;ve been huge activists for the semantic web, and this yet another example of what they&#8217;re doing to help the web evolve and educate the masses. Kudos to Opera. This should be required reading for all new developer/designers [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.csskarma.com/images/articles/this-week-in-links.jpg" alt="article banner"/></p>
<h5><a href="http://www.opera.com/wsc/" rel="external">Opera Web Standards Curriculum</a></h5>
<p>Ever since Opera accepted that no one uses their browser for general browsing they&#8217;ve been huge activists for the semantic web, and this yet another example of what they&#8217;re doing to help the web evolve and educate the masses. Kudos to Opera. This should be required reading for all new developer/designers and even clients.</p>
<h5><a href="http://jquery.open2space.com/" rel="external">jQuery How To&#8217;s</a></h5>
<p>This is a great list of specific things and how to do them with jQuery.</p>
<h5><a href="http://fluidapp.com/" rel="external">Fluid</a></h5>
<p>Fluid app is something I&#8217;ve been looking into for a little while now. I normally wouldn&#8217;t put this up here, because it&#8217;s a mac&ndash;only application; but it seems really neat. It creates desktop apps from web sites, like a bunch of little stand alone browsers in your doc. It does a similar thing to Google Chrome, by modularizing your web apps so if one crashes everything doesn&#8217;t fail.</p>
<h5><a href="http://www.digital-web.com/" rel="external">Digital Web Magazine</a></h5>
<p>I don&#8217;t know exactly how this site evaded my RSS reader for so long, but it&#8217;s a very informative &#8216;zine about the web. When I first saw it I read through a few articles and really liked what I saw.</p>
<h5><a href="http://hngry.com/" rel="external">Hngry</a></h5>
<p>Hngry is the lunch time app we all wanted, but are <a href="http://projects.csskarma.com/lunch/">too lazy</a> to build. It&#8217;s very nice, but it needs a lot more data.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.csskarma.com/blog/this-week-in-links-4/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Securing your Development Space</title>
		<link>http://www.csskarma.com/blog/securing-your-development-space/</link>
		<comments>http://www.csskarma.com/blog/securing-your-development-space/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 17:16:47 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[htpasswd]]></category>

		<guid isPermaLink="false">http://www.csskarma.com/blog/?p=90</guid>
		<description><![CDATA[You can hide your development space from the public many ways, a weird URL no one will find, use a local testing server (localhost), or set up a development server. Up until my last redesign I was just using a directory called dev under csskarma.com. And that was fine, but my file paths would all [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.csskarma.com/images/articles/securing-your-development-space.jpg" alt="article banner"/></p>
<p>You can hide your development space from the public many ways, a weird URL no one will find, use a local testing server (localhost), or set up a development server. Up until my last redesign I was just using a directory called <strong>dev</strong> under csskarma.com. And that was fine, but my file paths would all have to be adjusted when I went live (not a huge deal, but annoying none-the-less).</p>
<p>If you&#8217;re a frequent reader, you might remember that in my last post I mentioned that I was coming out of laziness and cleaning up some stuff on my server. So I finally set up my dev server. It&#8217;s just a sub-domain, but seems to work well so far.</p>
<p>Not that I have anything on it. but I felt like I should use some best practice stuff and password protect it. In password protecting a directory, you use an .htaccess file coupled with an .htpasswd file (to store the usernames and passwords)</p>
<p>The first thing you need is a list of users you want to grant access to. Let&#8217;s say I want to set up a general account for people to access my directories. We&#8217;ll make the username <strong>guest</strong> and the password <strong>dontstaylong</strong>.</p>
<p>Next, we have to go to a site that will encrypt the password for us, I use <a href="http://www.htaccesstools.com/htpasswd-generator/" rel="external">htpasswd generator</a>. After plugging in the username and password, you&#8217;ll come out with something like this:</p>
<h5>Your full .htpasswd file</h5>
<pre><code>guest:ZGu8x2pjH62Pk</code></pre>
<p>Take that code and place it in a file called .htpasswd (you&#8217;ll need to create this). You can put that file anywhere on your server, but it&#8217;s best to make sure it&#8217;s not web accessible (so no one can steal your password). So, if you have a public_html directory or a www, put the file one level higher than that.</p>
<p>Now that we have our .htpasswd file on our server, we can start cutting off access to various parts of our site using an .htaccess file. You can also add multiple users by following the same process as the first one, but put one user per line in the .htpasswd file.</p>
<p>Let&#8217;s say I have a directory at <a href="http://www.csskarma.com/articles/htpasswd/">http://www.csskarma.com/articles/htpasswd/</a> that I want to password protect. To do that I would put an .htaccess file in that directory with this code in it:</p>
<h5>Your full .htaccess file</h5>
<pre><code>AuthType basic
AuthName "This directory is protected"
AuthUserFile /full_server_path_to_file/.htpasswd
Require valid-user</code></pre>
<p>Important: the AuthUserFile must be an absolute server path to the file, relative will not work (at least it didn&#8217;t for me).</p>
<p>Lastly, you visit your new <a href="http://www.csskarma.com/articles/htpasswd/">password protected directory</a> (username: guest &#8211; password: dontstaylong) and marvel at your greatness. This password should apply to all sub directories as well.</p>
<p>In my experience, this is the easiest way to secure an area of your site. However, if you&#8217;re passing sensitive information through, you may want something a little more secure than this. Yahoo! provides a good <a href="http://developer.yahoo.com/security/" rel="external">best practices security</a> write-up you can use as a reference.</p>
<p>Anyone have any thoughts/suggestions for beefing up the .htpasswd file?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.csskarma.com/blog/securing-your-development-space/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Creating an .htaccess template</title>
		<link>http://www.csskarma.com/blog/creating-an-htaccess-template/</link>
		<comments>http://www.csskarma.com/blog/creating-an-htaccess-template/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 16:27:54 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[errorDocument]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[starter files]]></category>

		<guid isPermaLink="false">http://www.csskarma.com/blog/?p=73</guid>
		<description><![CDATA[Recently I decided to finally sit down and organize some things on my site/server. I created dev server, and did some other things that I had been wanting to do for a while. While I was putting together my usual .htaccess file I thought that maybe I could build it a little better and create [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I decided to finally sit down and organize some things on my site/server. I created dev server, and did some other things that I had been wanting to do for a while.</p>
<p>While I was putting together my usual .htaccess file I thought that maybe I could build it a little better and create a file template that I can use in the future when I&#8217;m doing something like this again (since, I know this will come up again). So I did a little research about things I knew I wanted to add in like the 404 error page rewrite rule (which many tutorials seem to omit) and denying a directory listing.</p>
<h5><strong>This is the file template I came up with:</strong></h5>
<p>For those who don&#8217;t know, you create a file called .htaccess with the below code in it, and stick it in the root directory of your site. It does all sorts of neat stuff. It can also be used to password protecting directories, but that&#8217;s for another day</p>
<pre><code>DirectoryIndex index.php index.html index.htm

&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
ErrorDocument 404 /errors/404.php
ErrorDocument 403 /errors/403.php
ErrorDocument 500 /errors/500.php
&lt;/IfModule&gt;

Options -Indexes
Options +FollowSymlinks

&lt;Files .htaccess&gt;
deny from all
&lt;/Files&gt;</code></pre>
<h4>Breaking it down</h4>
<p>This .htaccess file is in 4 basic parts: the directory index, the error documents, directory listing options and denying access to the .htaccess file itself.</p>
<h5>DirectoryIndex</h5>
<pre><code>DirectoryIndex index.php index.html index.htm</code></pre>
<p>DirectoryIndex is the first thing I learned in my .htaccess explorations, it&#8217;s very simple. It tells the server which pages to display by default and in what order. In my example, if I have index.html in a directory along with index.php, the index.php file will be displayed by default, so you have <a href="http://www.csskarma.com/">www.csskarma.com</a> pointing to index.php and if you want to get to index.html you&#8217;d have to type it in like <a href="http://www.csskarma.com/index.html">www.csskarma.com/index.html</a>. Many servers get this right without the DirectoryIndex, but it&#8217;s like doing <code>body{background-color:#fff;}</code>, I put it in just in case.</p>
<h5>ErrorDocument</h5>
<pre><code>&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
ErrorDocument 404 /errors/404.php
ErrorDocument 403 /errors/403.php
ErrorDocument 500 /errors/500.php
&lt;/IfModule&gt;</code></pre>
<p>This is the stuff that I dig. It gets the most press out of all the .htaccess elements; so I guess it&#8217;s the rock star of the .htaccess file. <a href="http://alistapart.com/articles/perfect404/" rel="external">A List Apart</a> did an article on it in 2004, and it was a big usability issue building a good 404 error page. Now we all have our fancy 404 pages.</p>
<p>The mod_rewrite module (as to my understanding of it) deals with rewriting the URL. In this cae, it&#8217;s the thing that lets you have a 404 error without exposing the URL of the actual <a href="http://www.csskarma.com/errors/404.php">error page</a>. 403 Error is a permission denied error and 500 is an internal server error. You can check out <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html" rel="external">all the error codes</a> if you&#8217;d like, but you shouldn&#8217;t bog down your .htaccess file too much, so I keep it to these 3.</p>
<h5>Index Options</h5>
<pre><code>Options -Indexes
Options +FollowSymlinks</code></pre>
<p><code>Options -Indexes</code> is what you use to deny a directory listing; inversely, you could use <code>Options Indexes</code> (no dash) to allow a directory listing. I use this for things like my images directory.</p>
<p><code>Options +FollowSymlinks</code> tells the server to follow Symlinks (no kidding huh?). Some apache servers require this for mod_rewrite to work. So if your mod_rewrite is working fine, you may not need this, I include it just in case. In my experience Symlinks are generally abused and overused but it&#8217;s still good to know how to <a href="http://kb.iu.edu/data/abbe.html" rel="external">create them from the command line</a>.</p>
<h5>.htaccess Access</h5>
<pre><code>&lt;Files .htaccess&gt;
deny from all
&lt;/Files&gt;</code></pre>
<p>This is very simple and (I think) very necessary. It prevents people from viewing your .htaccess file. There&#8217;s really not any sensitive information in <em>my</em> .htaccess file, but it&#8217;s good practice to protect this file in case you do put things in it that you don&#8217;t want exposed.</p>
<p>Fin</p>
<p>So, that&#8217;s my .htaccess file starter template. I&#8217;d be interested to hear what others use in their files and if I missed anything in mine, I&#8217;m certainly no Apache expert.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.csskarma.com/blog/creating-an-htaccess-template/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
