上記は機能しませんが、次のようになります。 www.chassis-plans.com/off-the-shelf-industrial-pc.htmlで遊んでください。 URLの大文字と小文字のいずれかを変更すると、コードによって適切な大文字と小文字に変更され、ページが表示されます。存在しないURL(www.chassis-plans.com/x)を入力すると、カスタム404ページが表示されます。
まず、次のものを.htaccessファイルに追加します。ここで/forwarding-site-nocase.htmlはカスタム404ページのURLです。
AddType application/x-httpd-php .html .htm
ErrorDocument 404 /forwarding-site-nocase.html
カスタム404ページの一番上に、1行目から次の行を追加します。最初に空白行があると失敗します。
<?php
$mydir=getdir("/",$_SERVER['REQUEST_URI']);
if($mydir!=false)
{
$thedomain = 'http://' . $_SERVER['SERVER_NAME'];
header("HTTP/1.1 301 Moved Permanently");
header('Location: ' . $thedomain.$mydir);
}
function getdir($loc,$tfile)
{
$startloc=$_SERVER['DOCUMENT_ROOT'];
if (file_exists($startloc.$loc) && $handle = opendir($startloc.$loc))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != ".." && strncasecmp($loc.$file,$tfile,strlen($loc.$file))==0)
{
if(strncasecmp($loc.$file,$tfile,strlen($tfile))==0)
{
return $loc.$file;
}
else
{
return getdir($loc.$file."/",$tfile);
}
}
}
closedir($handle);
}
return false;
}
?>
今、あなたは、次のようなカスタム404ページのためのあなたの標準的なHTMLでこれに従うことができます:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Language" content="en" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="Company information page - Page Not Found Error"/>
<meta name="search" content="Company information page - About Us. Manufacturer of rack mount rugged computer systems and rugged LCD displays for the military and industrial markets" />
などのページの残りの部分。
私は開発とテストの際にIE、おそらくキャッシュに問題がありましたが、今はうまくいくようです。 (グーグルで翻訳)
/var/www/vhosts/domain.com/conf/vhosts.conf [マニュアル](http://httpd.apache.org/docs/current/mod/mod_rewrite.html#を読みます'RewriteMap' ** .htaccessで宣言することはできません - サーバ設定または仮想ホストコンテキストでのみ宣言できます。それ以外の場合 - ルールは正常です。 – LazyOne
HMMM ...本当に理解しないでください。私は共有ホスティングを使用していますが、私はSSH経由でコンソールにアクセスする必要はありません。サーバ設定については言及していません... –
Easy:この行を 'RewriteMap tolower int:tolower'に入れると.htaccess、あなたは500サーバーエラーを取得します。 – LazyOne