简体   繁体   English

机器人可以到达我的网站吗? Facebook不能! PHP中的自定义URL控制器

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

I'm having trouble with getting Facebook Like to accept my website URL's. 我在让Facebook喜欢接受我的网站URL方面遇到麻烦。 Using the the Facebook developed tool "URL Linter", I have found out that Facebook get's the following error: "Website Inaccessible The page at http://www.domainname.com/categories/blouses.html could not be reached." 使用Facebook开发的工具“ URL Linter”,我发现Facebook出现以下错误:“无法访问网站无法访问http://www.domainname.com/categories/blouses.html的页面。”

I'm running a website that's uses a lot of rewrite rules created "on-the-fly" by a PHP script. 我正在运行一个使用大量重写规则的网站,这些规则是通过PHP脚本“即时”创建的。 When a .html document is requested, I use htaccess to parse the request to a PHP file. 当请求一个.html文档时,我使用htaccess将请求解析为一个PHP文件。

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

The url-controller.php contains the following code: 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;

I'm having a hard time seeing what I'm doing wrong - and even worse, I've started to consider whether Google could also be having trouble reaching my site? 我很难知道自己在做什么,更糟糕的是,我开始考虑Google是否也可能无法访问我的网站?

I hope someone can aid me with their experience and knowledge :) 我希望有人可以用他们的经验和知识来帮助我:)

Thanks in advance 提前致谢

If you go to Google Webmaster Tools you will be able to fetch your page as GoogleBot. 如果您使用Google网站站长工具 ,则可以GoogleBot的身份获取网页。 That will tell you if Google has a problem with it. 它将告诉您Google是否有问题。 Your code seems fine, but I did not take much time to look over it carefully. 您的代码看起来不错,但是我并没有花太多时间仔细检查它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM