2012-06-07 2 views
0

다음은 내 .htaccess 파일입니다. default_rewrite.php 파일이 있고 내가 만든 데이터베이스에서 내 콘텐츠를 가져옵니다. 당신이 알고있는 깨진 링크 예컨대 http://www.example.com/test/fgdhfuis에 갈 때.htaccess 파일에 오류 페이지를 추가하는 방법

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

는 내 기본 재 작성 페이지로 이동하지만 데이터베이스에 저장된 페이지로 이동하지 않습니다. 예컨대

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

나는 ErrorDocument 404 /404.php 시도했지만이 나를 위해 그것을하지 않습니다.

모든 조언을 크게 듣습니다. PHP를 편집 아래

:

<?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"; 
    } 

을 시도하지만이 모든 페이지가

+0

데이터베이스를 검사하는 코드 스 니펫을 가져올 수 있습니까? 귀하의 재 작성 규칙 이후, 모든 URL을 default-rewrite.php로 다시 작성합니다. 문제는 코드에 있습니다. – ku6pk

+0

그래서 기본 재 작성 페이지로 이동하여 데이터베이스의 페이지를 추가합니다. –

+0

$ colname_Page가 데이터베이스에 있는지 확인하는 코드가 있어야합니다. – ku6pk

답변

1

코드 바라 보았다 데 404 오류로 이동합니다, 당신은 추가 할 수

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

첫 번째 쿼리를 만들고 colname_Page를 404 페이지와 같게 설정하여 데이터베이스에 저장합니다. 또는 헤더 ('HTTP/1.0 404 Not Found')를 사용하여 PHP에서 404 오류를 보낼 수 있습니다. 그러면 Apache는 .htaccess에 지정한 ErroDocument 404 페이지를 사용해야합니다.

+0

404 상태 (즉,'header ('HTTP/1.0 404 Not Found')')를 보내면 404에 대한 ErrorDocument 지시문에 정의 된대로 오류 문서를 마술처럼 보내지 않습니다 오류. PHP에서 404 문서를 관리하고이를 응답의 일부로 보내야합니다. – MrWhite

관련 문제