簡體   English   中英

機器人可以到達我的網站嗎? Facebook不能! PHP中的自定義URL控制器

[英]Can robots reach my site? Facebook can't! Custom URL controller in PHP

我在讓Facebook喜歡接受我的網站URL方面遇到麻煩。 使用Facebook開發的工具“ URL Linter”,我發現Facebook出現以下錯誤:“無法訪問網站無法訪問http://www.domainname.com/categories/blouses.html的頁面。”

我正在運行一個使用大量重寫規則的網站,這些規則是通過PHP腳本“即時”創建的。 當請求一個.html文檔時,我使用htaccess將請求解析為一個PHP文件。

RewriteRule ^(.*).html$  url_controller.php [L]

url-controller.php包含以下代碼:

require_once $_SERVER['DOCUMENT_ROOT'].'/lib/config.php';

list($url, $ext) = explode('.html', substr(mysql_real_escape_string($_SERVER['REQUEST_URI']), 1));
list($parent, $child) = explode('/', $url);

$get_product = mysql_query("SELECT p.id FROM product_languages AS pl INNER JOIN products AS p ON pl.product_id = p.id INNER JOIN shop_products AS sp ON sp.product_id = p.id && sp.shop_id = ".$GLOBALS['site_id']." WHERE pl.url_key = '{$url}' && pl.locale = '{$_SESSION['language']}' LIMIT 0,1") or die(mysql_error());

if(mysql_num_rows($get_product)) {
    require_once './pages/view_product.php';
    exit;
}

$get_parent = mysql_query("SELECT c.id FROM categories AS c INNER JOIN shop_categories AS sc ON sc.category_id = c.id && sc.shop_id = ".$GLOBALS['site_id']." INNER JOIN category_languages AS cl ON cl.category_id = c.id && cl.url_key = '{$parent}' && cl.locale = '{$_SESSION['language']}' WHERE parent = 1 && active = 1 LIMIT 0,1");
$get_child = mysql_query("SELECT c.id FROM categories AS c INNER JOIN shop_categories AS sc ON sc.category_id = c.id && sc.shop_id = ".$GLOBALS['site_id']." INNER JOIN category_languages AS cl ON cl.category_id = c.id && cl.url_key = '{$child}' && cl.locale = '{$_SESSION['language']}' WHERE parent = 0 && active = 1 LIMIT 0,1");
if(mysql_num_rows($get_parent) && mysql_num_rows($get_child)) {
    require_once './pages/view_catalog.php';
    exit;
}

$get_cms_page= mysql_query("SELECT p.id FROM cms_pages AS p INNER JOIN shop_cms_pages AS s ON p.id = s.page_id INNER JOIN cms_page_languages AS l ON p.id = l.page_id WHERE s.shop_id = '{$GLOBALS['site_id']}' AND l.url_key = '{$url}' AND p.active = 1 AND l.locale = '{$_SESSION['language']}' LIMIT 0,1") or die(mysql_error());
if(mysql_num_rows($get_cms_page)) {
    require_once './pages/cms_page.php';
    exit;
}

$get_rule = mysql_query("SELECT new_url, status FROM url_rewrite WHERE shop_id = ".$GLOBALS['site_id']." && old_url = '".str_replace('Webshop/','',$url)."' && locale = '{$_SESSION['language']}' LIMIT 0,1") or die(mysql_error());
$fetch_rule = mysql_fetch_array($get_rule);

if(mysql_num_rows($get_rule)) {

     if($fetch_rule['status'] == 301) {
        header ("HTTP/1.1 301 Moved Permanently");
        //fix redirect to /
        if($fetch_rule['new_url'] == '/') {
        header ("Location: ".$fetch_rule['new_url']);
    } else {
        header ("Location: /".$fetch_rule['new_url'].".html");
    }
    exit;
}
elseif($fetch_rule['status'] == 302) {
    header ("Location: /".$fetch_rule['new_url'].".html");
    exit;
}
}

//IF WE GET TO THIS POINT; IT'S NOT BEEN POSSIBLE TO FIND THE REQUESTED URL ANYWHERE IN THE CATALOG
header("HTTP/1.0 404 Not Found");
require_once './pages/error_404.php';
exit;

我很難知道自己在做什么,更糟糕的是,我開始考慮Google是否也可能無法訪問我的網站?

我希望有人可以用他們的經驗和知識來幫助我:)

提前致謝

如果您使用Google網站站長工具 ,則可以GoogleBot的身份獲取網頁。 它將告訴您Google是否有問題。 您的代碼看起來不錯,但是我並沒有花太多時間仔細檢查它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM