2015-09-23 23 views
10

Mi sento come se avessi tentato ogni singola opzione là fuori e nulla è riuscito. Prima di tutto lasciatemi elencare le opzioni che ho provato:Applicazione angolare indicizzata da Google

Utilizzando PreRender con Apache:

ho cercato questo utilizzando le seguenti operazioni:

In angolare:

$locationProvider.html5Mode(true); 

In HTML , aggiungi questo meta header:

<head> 
    <meta name="fragment" content="!"> 
</head> 

Configurare Apache:

RewriteEngine On 
# If requested resource exists as a file or directory 
    # (REQUEST_FILENAME is only relative in virtualhost context, so not usable) 
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR] 
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d 
    # Go to it as is 
    RewriteRule^- [L] 

    # If non existent 
    # If path ends with/and is not just a single /, redirect to without the trailing/
     RewriteCond %{REQUEST_URI} ^.*/$ 
     RewriteCond %{REQUEST_URI} !^/$ 
     RewriteRule ^(.*)/$ $1 [R,QSA,L]  

    # Handle Prerender.io 
    RequestHeader set X-Prerender-Token "YOUR_TOKEN" 

    RewriteCond %{HTTP_USER_AGENT} baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest [NC,OR] 
    RewriteCond %{QUERY_STRING} _escaped_fragment_ 

    # Proxy the request 
    RewriteRule ^(.*)$ http://service.prerender.io/http://%{HTTP_HOST}$1 [P,L] 

    # If non existent 
    # Accept everything on index.html 
    RewriteRule^/index.html 

Questo non ha funzionato affatto: Google è stato in grado di leggere le mie pagine secondarie.

Utilizzando Nodo/Phantomjs per visualizzare le pagine

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); 

Qui ho creato questo sito poi aggiunto un proxy nella mia configurazione di Apache in modo che tutte le richieste puntato sulla mia porta di dominio 3500.

Questo non ha funzionato dal momento che non è stato possibile eseguire il rendering dell'indice e quando finalmente l'ho ricevuto per inviare la pagina html che JavaScript non avrebbe eseguito il rendering.

seguente guida snapshot personalizzato

Poi ho seguito questa guida:

http://www.yearofmoo.com/2012/11/angularjs-and-seo.html

Tuttavia, questo mi ha richiesto di rendere istantanee personalizzate di tutto ciò che non è quello che la mia ricerca ed è fastidioso mantenere. Inoltre, la make-snapshot non funzionava sul mio server.

+0

quindi cosa succede quando si inserisce '? _escaped_fragment_ =' in url? – charlietfl

+0

@charlietfl adesso se faccio http://www.learningbank.dk/?_escaped_fragment_= reindirizza al mio indice –

+0

prova a rimuovere le condizioni del bot per controllarlo – charlietfl

risposta

2

In teoria non è necessario eseguire il prerender della tua pagina su google crawler. Al momento sono in grado di analizzare javascript. http://googlewebmastercentral.blogspot.ca/2014/05/understanding-web-pages-better.html

Google analizza correttamente il mio sito angularJS. https://www.google.nl/search?q=site%3Atest.coachgezocht.nu

Utilizzo $ locationProvider.html5Mode (true); e:

RewriteEngine On 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_URI} !index 
    RewriteRule (.*) index.html [L]