Question

I have a singe page website, built with SammyJS as js framework and PHP for the backend, So when I reach the point of SEO I read about google Ajax crawlers, so I did the following: 1.I add the below 2 lines to my htacess file.

#RewriteCond %{QUERY_STRING} ^_escaped_fragment_=(.*)$
#RewriteRule ^$ /seo/index/ [R=301,L] 

2. I create a new controller (seo) which only will display the required data(HTML) to be indexed without any CSS or js.

So if the url contains _escaped_fragment_, the web-server will redirect it to seo controller. This solution works fine when I share using facebook, but not works among gplus, linked-in and twitter. also when I test how google-bot see my site, google-bot sees 301 redirect page!.

From this, I want something to work without redirect, and this require sammyJS to be worked without hash, and I can't make it works.

my question is how to make sammy js works without #! or #, taken in consider push state not supported in all browser.

any ideas guys about this case.

Thanks,

Was it helpful?

Solution

After some research I find this way to handle seo and social media with single page applications,

Since I use Yii framework for the back-end, in the main layout file I got the parameters of the query string, So if the url contains "_escaped_fragment_", I take this variable and its value and got the result direct without including the sammyJS routers file.

so in the top of the layout file:

<?php
if(isset($_GET['_escaped_fragment_'])){
        Return the data you want using PHP only don't relay on js,
        from here you need to provide a full html page with all data.
}else{
       include your sammy js routers file.. normal case 
}
?>

and also you don't need any redirection from the htaccess file.

Thanks,

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top