0

以下は私の.htaccessファイルです。ファイルがdefault_rewrite.phpあり、作成したデータベースからコンテンツを取得します。

RewriteEngine on
RewriteRule ^/?([a-z0-9-_]*)$ default-rewrite.php?page=$1 [L]

既知の壊れたリンクEGhttp://www.example.com/test/fgdhfuisに移動すると、デフォルトの書き換えページに移動しますが、データベースに保存したページには移動しません。例えば

http://www.example.com/test/home

私は試しErrorDocument 404 /404.phpましたが、これは私にとってはうまくいきません。

アドバイスをいただければ幸いです。

PHP Editの下:

<?php
  if (!function_exists("GetSQLValueString")) {
  function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
  {
  if (PHP_VERSION < 6) {
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
  case "text":
  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  break;    
  case "long":
  case "int":
  $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  break;
  case "double":
  $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  break;
  case "date":
  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  break;
  case "defined":
  $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  break;
  }
  return $theValue;
  }
  }

  $colname_Page = "home";
  if (isset($_GET['page'])) {
  $colname_Page = $_GET['page'];
  if($colname_Page == "")
  $colname_Page = "home";
  }

  mysql_select_db($database_VRMOnline, $VRMOnline);
  $query_Page = sprintf("SELECT * FROM Page WHERE PageName = %s", GetSQLValueString($colname_Page, "text"));
  $Page = mysql_query($query_Page, $VRMOnline) or die(mysql_error());
  $row_Page = mysql_fetch_assoc($Page);
  $totalRows_Page = mysql_num_rows($Page);

  mysql_select_db($database_VRMOnline, $VRMOnline);
  $query_MetaData = "SELECT * FROM MetaData WHERE MetaDataID = 1";
  $MetaData = mysql_query($query_MetaData, $VRMOnline) or die(mysql_error());
  $row_MetaData = mysql_fetch_assoc($MetaData);
  $totalRows_MetaData = mysql_num_rows($MetaData);

  ?>

私は試した

  $colname_Page = "home";
  if (isset($_GET['page'])) {
  $colname_Page = $_GET['page'];
  if($colname_Page == "")
  $colname_Page = "home";
  if ($totalRows_Page == 0)
  {
  $colname_Page = "404-error";
  }

しかし、これによりすべてのページが404エラーになります

4

1 に答える 1

1

コードを見て、次を追加できます。

if ($totalRows_Page == 0)
{
 // 404 Page Logic
}

最初のクエリの後、colname_Page を 404 ページに設定し、作成してデータベースに入れます。または、PHP でheader('HTTP/1.0 404 Not Found');を使用して 404 エラーを送信できます。Apache は、.htaccess で指定した ErroDocument 404 ページを使用する必要があります。

于 2012-06-07T20:02:14.647 に答える