alexferreira / seojs

96 stars 5 forks source link

Support HTML5 pushstate URLs #1

Open nilsga opened 11 years ago

nilsga commented 11 years ago

AngularJS can be configured to use HTML5 mode URLs, which means that there is no "hashbang". The seo-server-phantom.js script cannot handle this case, as far as I can see.

alexferreira commented 11 years ago

If you use hashbang URLs then all you need to do is instruct AngularJS to use them instead of regular hash values:

angular.module('HashBangURLs', []).config(['$locationProvider', function($location) {
  $location.hashPrefix('!');
}]);
//then add this module as a dependency within your primary module(s).

Google will now recognize the URL and then do what it has to do to fetch the HTML version.

If you wish not to use hashbang URLs but still inform Google that your website contains AJAX content then include this meta tag within the head tag of the file being accessed at the given URL.

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

Then configure AngularJS to use HTML5 URLs when handling URLs and routes:

//get the module from creating an angular module
angular.module('HTML5ModeURLs', []).config(['$routeProvider', function($route) {
  $route.html5Mode(true);
}]);

Then whichever method you choose can be installed via module:

//get the module from creating an angular module
var App = angular.module('App', ['HashBangURLs']);
//or
var App = angular.module('App', ['HTML5ModeURLs']);

My suggestion is to stick to using hashbang URLs since you can mix both non-AJAX pages (like basic forms and so on) to work with non-hashbang HTTP URLs (like registration pages, forms, etc...).

Any reason not to use hashbang?

nilsga commented 11 years ago

I'm already using HTML5 urls. But the phantom-js script seems to enforce hashbang-urls? I'm using HTML5 urls because they're a lot nicer to look at :)

alexferreira commented 11 years ago

I understand, I did this project based on what is reported by google.

why not develop for HTML5 url, I'll look into it and do some tests.

Take a look at https://developers.google.com/webmasters/ajax-crawling/docs/getting-started url so you can better understand.

WEBIMMO commented 10 years ago

Hello nilsga, Am facing the same issue any tips ?

honkskillet commented 10 years ago
Google will now recognize the URL and then do what it has to do to fetch the HTML version.

Does that mean you don't have server separate HTML, as previously with '#!' ?