<?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/"
	>

<channel>
	<title>unitstep.net &#187; htaccess</title>
	<atom:link href="http://unitstep.net/blog/category/htaccess/feed/" rel="self" type="application/rss+xml" />
	<link>http://unitstep.net</link>
	<description>the home of peter chng</description>
	<pubDate>Tue, 30 Dec 2008 19:37:22 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Taking the www out of the web</title>
		<link>http://unitstep.net/blog/2006/12/27/taking-the-www-out-of-the-web/</link>
		<comments>http://unitstep.net/blog/2006/12/27/taking-the-www-out-of-the-web/#comments</comments>
		<pubDate>Wed, 27 Dec 2006 18:47:32 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[fix]]></category>

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

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

		<guid isPermaLink="false">http://unitstep.net/blog/2006/12/27/taking-the-www-out-of-the-web/</guid>
		<description><![CDATA[Despite the phrase &#8220;World-Wide Web&#8221; being as dated and passÃ© as claims of Al Gore &#8220;inventing the Internet&#8221;, the term persists today as the most popular and unnecessary subdomain for websites.  Should it really be necessary to type &#8220;www&#8221; before every domain name?  Furthermore, does it even have any more relevance?
Since the major [...]]]></description>
			<content:encoded><![CDATA[<p>Despite the phrase &#8220;World-Wide Web&#8221; being as dated and <i>passÃ©</i> as claims of Al Gore <a href="http://en.wikipedia.org/wiki/Al_gore#1999_CNN_interview">&#8220;inventing the Internet&#8221;</a>, the term persists today as the most popular and unnecessary subdomain for websites.  Should it really be necessary to type &#8220;www&#8221; before every domain name?  Furthermore, does it even have any more relevance?</p>
<p>Since the major use of Internet is for accessing websites, the &#8220;www&#8221; prefix shouldn&#8217;t be needed anymore.  It is an archaic holdover from a previous era, one where browser wars meant IE vs. Netscape and where Geocities was <em>the</em> place to be.  Thankfully, the folks over at <a href="http://no-www.org/">no-www</a> have been aiming to improve this for some time.</p>
<h3>So what&#8217;s the big deal?</h3>
<p>Well, it&#8217;s not such a big deal, more just a pet peeve of mine.  Most sites out there are thankfully configured well enough so that navigating to &#8220;domain.com&#8221; just redirects you to &#8220;www.domain.com&#8221; with no damage done.  However, some servers are setup so that navigating to &#8220;domain.com&#8221; <em>doesn&#8217;t</em> work, and this forces you to type in the &#8220;www&#8221; subdomain before.  This really doesn&#8217;t make sense in today&#8217;s world.</p>
<p>In my opinion, all websites should be set up with the no-www version as the default.  Using the &#8220;www&#8221; subdomain should redirect you to the no-www version, with no harm done.  This is known as <a href="http://no-www.org/faq.php">Class-B compliance</a>, according to the no-www folks, and it&#8217;s probably going to be the best way to go for some time, since many people still use the &#8220;www&#8221;, after having the phrase drilled into their heads during the late 90&#8217;s. </p>
<h3>So, how to fix it?</h3>
<p>If you&#8217;ve signed up for hosting from a provider, chances are they&#8217;ve already implemented some sort of compliance, but not the optimal type.  For example, most hosting providers will automatically redirect the no-www request to the www one.  So, under this configuration, someone entering &#8220;domain.com&#8221; would be redirected to &#8220;www.domain.com&#8221;.  No big deal, but things could be better.  After all, the no-www version is shorter and thus requires less typing and less space.  Good if you want to save a few cents on your business cards.</p>
<p>Fixing it is a simple effort that takes a minute or so.  All you have to do is edit the <code>.htaccess</code> file in the root of your website, if you&#8217;re using Apache.  Here&#8217;s the following directive I&#8217;m using.</p>
<pre>
<code># BEGIN no-www
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.unitstep\.net$ [NC]
RewriteRule ^(.*)$ http://unitstep.net/$1 [R=301,L]
&lt;/IfModule&gt;
# END no-www</code>
</pre>
<p>The <code>RewriteRule</code> uses a 301 - this is a special <acronym class="uttInitialism" title="HyperText Transfer Protocol">HTTP</acronym> code used to tell of a permanent redirection.  Browsers and search engines crawling your site will interpret this as an instruction that your website has permanently moved to the non-www address.  This is most important for search engines, so that they know that the no-www version is not <a href="http://googlewebmastercentral.blogspot.com/2006/12/deftly-dealing-with-duplicate-content.html">just a duplicate</a> or different website than the previous www version.  The 301 instruction tells them that the old www version doesn&#8217;t exist anymore, and it has been moved to the no-www address. </p>
<p>Taking it a step further, you could also redirect <em>any</em> subdomain to just the root.  For example, I also own the domain &#8220;peterchng.com&#8221;, and wanted to redirect any request to that address, subdomains included, to my main site.  Here&#8217;s the directives I used.</p>
<pre>
<code># BEGIN peterchng.com FORWARD
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(([a-zA-Z0-9]+)\.)*peterchng\.com$ [NC]
RewriteRule ^(.*)$ http://unitstep.net/$1 [R=301,L]
&lt;/IfModule&gt;
# END peterchng.com FORWARD</code>
</pre>
<p>Go ahead, try typing in <a href="http://who.the.heck.is.peterchng.com">&#8220;who.the.heck.is.peterchng.com&#8221;</a> into your browser, and you&#8217;ll see it redirects right back to this site.</p>
<p>You&#8217;ll want to be careful when using these directives - if you actually do have separate websites on different subdomains, they&#8217;ll be inaccessible if you do this!  I&#8217;ve been using it until I find a use for peterchng.com - or a different use for unitstep.net.  </p>
<h3>Why all the trouble then?</h3>
<p>With all the trouble of going of removing the &#8220;www&#8221; you may wonder why it was ever used in the first place.  Well, IIRC, in the early years of the Internet, websites or <acronym class="uttInitialism" title="HyperText Transfer Protocol">HTTP</acronym> wasn&#8217;t the main use.  Other services/protocols such as gopher, FTP and telnet were probably a lot more dominant.  So, it made sense to set up a separate subdomain that would be used to accept <acronym class="uttInitialism" title="HyperText Transfer Protocol">HTTP</acronym> connections.  This would make it easier for users to distinguish between the services offered from a particular domain.  However, since <acronym class="uttInitialism" title="HyperText Transfer Protocol">HTTP</acronym> has grown to eclipse those traditional services, the use of www is almost superfluous nowadays.</p>
<hr/>Copyright &copy; 2009 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2006/12/27/taking-the-www-out-of-the-web/feed/</wfw:commentRss>
		</item>
		<item>
		<title>WordPress and password-protected directories: How to make them work together</title>
		<link>http://unitstep.net/blog/2006/08/15/wordpress-and-password-protected-directories/</link>
		<comments>http://unitstep.net/blog/2006/08/15/wordpress-and-password-protected-directories/#comments</comments>
		<pubDate>Wed, 16 Aug 2006 03:27:06 +0000</pubDate>
		<dc:creator>Peter Chng</dc:creator>
		
		<category><![CDATA[apache]]></category>

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

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

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

		<guid isPermaLink="false">http://unitstep.net/blog/2006/08/15/wordpress-and-password-protected-directories/</guid>
		<description><![CDATA[If you have WordPress installed in the root directory of your website, as many people do, then the entire website is subject to the .htaccess rules defined by WordPress, if you&#8217;re using a permalink structure that uses mod_rewrite. (Again, most people use this option, as it allows for human-readable URIs instead of ones filled with [...]]]></description>
			<content:encoded><![CDATA[<p>If you have WordPress installed in the root directory of your website, as many people do, then the entire website is subject to the <code>.htaccess</code> rules defined by WordPress, if you&#8217;re using a permalink structure that uses <code>mod_rewrite</code>. (Again, most people use this option, as it allows for human-readable URIs instead of ones filled with GET queries)  Because the WordPress <code>.htaccess</code> file resides in the site root folder, it allows WordPress to handle all URIs relating to requests from the site - this is good, as it allows WordPress to handle 404s nicely, and you can define 404 pages from within WordPress rather than having to resort to server directives.</p>
<p>However, this can create problems if you want to create password-protected directories.  Accessing them sometimes doesn&#8217;t work because of WordPress&#8217;s <code>.htaccess</code> file, however this isn&#8217;t a WordPress problem <i style="latin">per se</i>, but rather a problem with how Apache has been set up.  I ran into this problem - I tried accessing a password-protected directory that I knew had been set up properly, but I kept getting a 404 error and was redirected to my WordPress theme&#8217;s 404 page.  After a little bit of searching over at the <a href="http://wordpress.org/support/">WordPress support boards</a>, I found some solutions that were sort of messy, involving editing WordPress files or adding a lot to the <code>.htaccess</code> file. </p>
<p>However, after looking for a bit more, I found <a href="http://www.ju-ju.com/2006/03/17/wordpress-404-error/">this page</a>, where the author outlines his fix; but later on a comment posted to his site provided me with the fix I wanted - <a href="http://textpattern.com/faq/173/password-protected-directories-with-htaccess">something simple</a>.  Though that site deals with <a href="http://textpattern.com/">TextPattern</a>, another blogging platform, apparently it handles requests in a similar manner to WordPress.</p>
<p>The problem lies with improperly set (usually non-specified) <code>ErrorDocument</code> directives.  In this case, the responsible error codes are <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.2">401</a> (Unauthorized) and <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.4">403</a> (Forbidden).  These directives are used to tell Apache what document to send or display to the user when each of these error codes are encountered.  If these are set to point to a non-existant file, WordPress ends up handling the request - which in these cases, it treats just like a 404.  When you try to access a password-protected resource, Apache first sends a 401 (Unauthorized), as a challenge to provide the proper credentials (login/password); if the error directive for this points to non-existant file, then the request is improperly passed on to WordPress and then treated like a 404 here.</p>
<p>To fix it, you need to specify the error directives in your root <code>.htaccess</code> file, which if you have WordPress in the root, is the same file that WordPress uses.  If you open it up, you should find WordPress&#8217; rules in there, which will look something like this</p>
<pre><code># BEGIN WordPress
&lt;ifmodule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
&lt;/ifmodule&gt;
# END WordPress</code></pre>
<p>Add the following lines to the <code>.htaccess</code> file.</p>
<pre><code>ErrorDocument 401 /&lt;PATH_TO_ERROR_DOCS&gt;/401.html
ErrorDocument 403 /&lt;PATH_TO_ERROR_DOCS&gt;/403.html</code></pre>
<p>Where 401.html and 403.html are the pages you want shown when each of those respective errors are encountered.  These should be static pages. (eg. not server-side scripts)  This fix worked like a charm for me.  </p>
<hr/>Copyright &copy; 2009 <strong><a href="http://unitstep.net">unitstep.net</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact <strong><a href="mailto:webmaster@unitstep.net">webmaster@unitstep.net</a></strong> for more information.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://unitstep.net/blog/2006/08/15/wordpress-and-password-protected-directories/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
