<?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/"
		xmlns:xhtml="http://www.w3.org/1999/xhtml"
>

<channel>
	<title>べたろぐ。 &#187; .htaccess</title>
	<atom:link href="http://szdy.info/wp/tag/htaccess/feed/" rel="self" type="application/rss+xml" />
	<link>http://szdy.info/wp</link>
	<description></description>
	<lastBuildDate>Tue, 28 Sep 2010 10:42:57 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://szdy.info/wp/tag/htaccess/feed/" />
		<item>
		<title>404 not found &#8211; error.cgi</title>
		<link>http://szdy.info/wp/2009/04/20/6/</link>
		<comments>http://szdy.info/wp/2009/04/20/6/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 10:36:54 +0000</pubDate>
		<dc:creator>beta</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[SAKURA Internet]]></category>
		<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://szdy.info/wp/?p=6</guid>
		<description><![CDATA[とりあえずエラーページを用意してみました。いわゆる 404 Not Found とかいうアレです。 なぜって？ディレクトリ内の丸見えを防ぎたかったんです 使っているサーバはさくらインターネットのレンタルサーバ スタンダー [...]]]></description>
			<content:encoded><![CDATA[				<p>とりあえずエラーページを用意してみました。いわゆる <code>404 Not Found</code> とかいうアレです。</p>
				<h3>なぜって？ディレクトリ内の丸見えを防ぎたかったんです</h3>
				<p>使っているサーバは<a href="http://www.sakura.ne.jp/rentalserver/standard/index.html" title="XOOPSやMovable Type（MT）の本格活用にさくらのレンタルサーバ スタンダード｜さくらインターネット">さくらインターネットのレンタルサーバ スタンダードプラン</a>で、さくらは .htaccess で設定をいぢることはできるんですが、<code>Options</code> が使えない。なのでインデックスファイルが存在しないディレクトリを開いた時に中身が丸見えになるのを防ぐには、<code>Options</code> を使わずに違うアプローチが必要になる。公式サポートの<a href="http://support.sakura.ad.jp/support/manual/rs/tech_htaccess.shtml#ht05" title="SAKURA Internet : サポート/お問合せ　:　オンラインマニュアル - ひみつのフォルダにあるファイルの一覧を見られないようにしたい">ひみつのフォルダにあるファイルの一覧を見られないようにしたい</a>というページでは <code>DirectoryIndex</code> を使ってインデックスファイルの設定の最後にエラーページを指定して、インデックスファイルが存在しない場合はエラーページに飛ばす方法が書かれていました。まあ、この方法を使うことにしたわけですが、ただエラーページを用意しただけじゃつまらないので色々と細工をしてみました。</p>
				<h3>めんどくさいことは Perl に投げちゃお</h3>
				<p>細工と言っても単純で、エラーコード <code>404</code> だけでなく <code>403</code> や <code>500</code> にも対応できるように、エラーページを Perl スクリプトにして動的に出力してやることにしました。</p>
				<h3>ステータスコードは検索ロボットたちに優しいんです</h3>
				<p>Perl スクリプトにすることでステータスコードをきちんと返すことができるようになる。きちんとステータスコードを出力することによって、エラーを、人にだけでなく Google や Yahoo などの検索ロボットにも伝えることができるので、結果的に検索から訪れる人に対してのエラーを減らすことができる。</p>
				<h3>真っすぐな視線には弱いんです</h3>
				<p>なお、当初の目的である、インデックスファイルがない時に error.cgi へ飛ばした場合ですが、error.cgi へ直接アクセスされることになります。なので、直接 error.cgi へアクセスがあった時はエラー <code>404</code> を返し、ファイルは存在しませんよと偽装することにしました。</p>
				<dl>
				<dt>error.cgi の大まかなサンプルコード</dt>
				<dd>
				<pre><code>my $error_code = $ENV{REDIRECT_STATUS};
<!--pre-->
<!--pre--># エラー 500 (Internal server error) の場合
<!--pre-->if ( $error_code eq "500" ){
<!--pre-->
<!--pre--># エラー 404 (File not found) の場合
<!--pre-->} elsif ( $error_code eq "404" ){
<!--pre-->
<!--pre--># エラー 403 (Permission denied) の場合
<!--pre-->} elsif ( $error_code eq "403" ){
<!--pre-->
<!--pre--># error.cgi への直接リンクの場合
<!--pre-->} else {
<!--pre-->    # 404 を偽装しステータスコードも 404 を返す
<!--pre-->    <strong>print "Status: 404 Not Found\n";</strong>
<!--pre-->
<!--pre-->}</code></pre>
				</dd>
				</dl>
				<dl>
				<dt>.htaccess の中の関連する項目</dt>
				<dd>
				<pre><code>#-----------------------------------------------
<!--pre--># インデックスファイル
<!--pre-->
<!--pre-->DirectoryIndex index.cgi index.php index.xhtml index.shtml index.html <strong>/error/error.cgi</strong>
<!--pre-->
<!--pre-->#--------------------------------------------------
<!--pre--># エラー400 (Bad Syntax) リクエストの方法が違います
<!--pre--># エラー401 (Authorization Required) 認証に失敗しました
<!--pre--># エラー403 (Permission denied) アクセス権限がありません
<!--pre--># エラー404 (File not found) 該当するページが見つかりません
<!--pre--># エラー500 (Internal server error) 内部サーバーエラー（主にCGIなどの誤り）
<!--pre-->
<!--pre-->#ErrorDocument 400 /error/400.php
<!--pre-->#ErrorDocument 401 /error/401.php
<!--pre-->ErrorDocument 403 <strong>/error/error.cgi</strong>
<!--pre-->ErrorDocument 404 <strong>/error/error.cgi</strong>
<!--pre-->ErrorDocument 500 <strong>/error/error.cgi</strong></code></pre>
				</dd>
				</dl>
				<dl>
				<dt>error.cgi の実行結果例</dt>
				<dd>
				<ul>
				<li><a href="/error/sample.dat" title="403 Permission deniedの例">403 Permission denied</a></li>
				<li><a href="/error/sample.html" title="404 not found">404 not found</a></li>
				<li><a href="/error/sample.cgi" title="500 Internal server errorの例">500 Internal server error</a></li>
				<li><a href="/error/error.cgi">直接 error.cgi へアクセスした場合</a> (404 Not Found)</li>
				</ul>
				</dd>
				</dl>
				<p>エラーページ作成にあたって <a href="http://x68000.q-e-d.net/~68user/" title="68user's page">68user&#8217;s page</a> 内の <a href="http://x68000.q-e-d.net/~68user/cgi-bin/cvsweb.cgi/public_html/cgi-bin/error.cgi?rev=HEAD&amp;content-type=text/x-cvsweb-markup" title="public_html/cgi-bin/error.cgi - view - 1.13">error.cgi</a> を参考にしました。</p>
]]></content:encoded>
			<wfw:commentRss>http://szdy.info/wp/2009/04/20/6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://szdy.info/wp/2009/04/20/6/" />
	</item>
	</channel>
</rss>

