Last active
August 29, 2015 14:13
-
-
Save popcorn245/546fdb771d9f8e0de5b8 to your computer and use it in GitHub Desktop.
Seo4Ajax Filter for Laravel 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
|-------------------------------------------------------------------------- | |
| Seo4Ajax Filter | |
|-------------------------------------------------------------------------- | |
| | |
| The following filter is used to load html from SEO4AJAX.com and | |
| serve it specifically to search engine / social networking bots. | |
| EXAMPLE - Route::get('/', array('before' => 'seo4ajax', 'uses' => 'controller@index')); | |
| | |
*/ | |
Route::filter('seo4ajax', function() | |
{ | |
$authKey = 'YOUR SITES AUTH KEY'; | |
$UserAgentsToMatch = '/bot|crawler|spider|archiver|pinterest|facebookexternalhit|flipboardproxy|slurp/i'; | |
$UserAgentsNotToMatch = '/google.*bot|bing|msnbot|yandexbot|pinterest.*ios|mail\.ru/i'; | |
if (isset($_SERVER['QUERY_STRING']) && preg_match('/_escaped_fragment_=/i', $_SERVER['QUERY_STRING'])) { | |
return file_get_contents("http://api.seo4ajax.com/".$authKey.$_SERVER['REQUEST_URI']); | |
} | |
if (isset($_SERVER['HTTP_USER_AGENT']) && !preg_match($UserAgentsNotToMatch, $_SERVER['HTTP_USER_AGENT']) && preg_match($UserAgentsToMatch, $_SERVER['HTTP_USER_AGENT'])) { | |
return file_get_contents("http://api.seo4ajax.com/".$authKey.$_SERVER['REQUEST_URI']); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment