Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 谷歌索引的角度应用程序_Angularjs_Apache_.htaccess_Mod Rewrite_Google Index - Fatal编程技术网

Angularjs 谷歌索引的角度应用程序

Angularjs 谷歌索引的角度应用程序,angularjs,apache,.htaccess,mod-rewrite,google-index,Angularjs,Apache,.htaccess,Mod Rewrite,Google Index,我觉得我已经尝试了每一个选项,但都没有成功。首先,让我列出我尝试过的选项: 与Apache一起使用预渲染: 我已尝试使用以下步骤进行此操作: 在角度上: $locationProvider.html5Mode(true); 在HTML中,添加此元标题: <head> <meta name="fragment" content="!"> </head> 这根本不起作用:谷歌无法读取我的子页面 使用节点/Phantomjs呈现页面 var ex

我觉得我已经尝试了每一个选项,但都没有成功。首先,让我列出我尝试过的选项:

与Apache一起使用预渲染:

我已尝试使用以下步骤进行此操作:

在角度上:

$locationProvider.html5Mode(true);
在HTML中,添加此元标题:

<head>
    <meta name="fragment" content="!">
</head>
这根本不起作用:谷歌无法读取我的子页面

使用节点/Phantomjs呈现页面

    var express = require('express');
var app = module.exports = express();
var phantom = require('node-phantom');
app.use('/', function (req, res) {
    if (typeof(req.query._escaped_fragment_) !== "undefined") {
        phantom.create(function (err, ph) {
            return ph.createPage(function (err, page) {
                return page.open("https://system.dk/#!" + req.query._esca$
                    return page.evaluate((function () {
                        return document.getElementsByTagName('html')[0].innerHT$
                    }), function (err, result) {
                        res.send(result);
                        return ph.exit();
                    });
                });
            });
        });
    } else
        res.render('index');
});

app.listen(3500);
console.log('Magic happens on port ' + 3500);
在这里,我创建了这个站点,然后在Apache配置中添加了一个代理,以便所有请求都指向我的域端口
3500

这不起作用,因为它无法呈现索引,当我最终让它发送html页面时,JavaScript不会呈现

遵循自定义快照指南

然后我遵循了这个指南:


然而,这需要我做的一切不是我所寻找的,是恼人的维护自定义快照。另外,制作快照在我的服务器上不起作用。

理论上,你不应该将你的页面预先呈现给google crawler。他们现在解析javascript

谷歌很好地解析了我的angularJS网站

使用$locationProvider.html5Mode(true);以及:


那么,当您在url中插入
?\u转义\u片段\u=
时会发生什么情况?@charlietfl如果我现在这样做,它会重定向到我的索引,并删除要检查的bot条件it@charlietflbot条件(抱歉,我现在很困惑:S)
RewriteCond%{HTTP\u USER\u AGENT}
。。。你的浏览器与这些不匹配
    var express = require('express');
var app = module.exports = express();
var phantom = require('node-phantom');
app.use('/', function (req, res) {
    if (typeof(req.query._escaped_fragment_) !== "undefined") {
        phantom.create(function (err, ph) {
            return ph.createPage(function (err, page) {
                return page.open("https://system.dk/#!" + req.query._esca$
                    return page.evaluate((function () {
                        return document.getElementsByTagName('html')[0].innerHT$
                    }), function (err, result) {
                        res.send(result);
                        return ph.exit();
                    });
                });
            });
        });
    } else
        res.render('index');
});

app.listen(3500);
console.log('Magic happens on port ' + 3500);
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !index
    RewriteRule (.*) index.html [L]