New Zenner
- Join Date:
- Feb 2009
- Posts:
- 101
- Plugin Contributions:
- 0
SEMRush user agent in spiders.txt, login returns 302 leading to annoying ranking
Hi! I'm not sure what changed and where, but suddenly SEMRush sent us a notice that every page on our site contained a link that returned a 302 response. It was a bit of a weird thing to complain about, not exactly the end of the world, but the reason is that every page has our 'login' link on it, and when they crawl the site they send every request with a User-Agent string that's listed in our spiders.txt file.
So init_sessions.php goes into the SESSION_BLOCK_SPIDERS == 'True' block, checks the spiders list, and because it finds it, does not start the session. We get $spider_flag=true and $session_started=false.
Then when the link being accessed is the login page, includes/modules/pages/login/header_php.php says that if $session_started==false, then redirect to FILENAME_COOKIE_USAGE. This is what's causing the negative ranking in SEMRush's report, they don't like any kind of 302 redirect.
I can see why the various parties in this engagement do what they do, but all my options seem poor at this point:
- I would not want to remove SEMRush from spiders.txt, because I don't want their crawling to appear in our access stats etc as a user visit (see counter.php).
- I wouldn't want to hack init_sessions.php to 'allow' the SEMRush user agent to start the session, because it's ugly as hell.
- I can manually 'hide' the warnings on SEMRush but that's laborious for our > 160 pages.
I doubt very much that complaining to SEMRush would get anywhere because they pretty much have to pass a user agent that mentions them, so any action on their part doesn't seem warranted to me.
My best bet right now seems to be option 2 of the 3 above, so I've added a very hacky modification to init_sessions.php:
if ($spider_flag == false
/* New bit here */ || strpos(strtolower($user_agent), 'semrush') !== FALSE) {
zen_session_start();
$session_started = true;
}
So the new logic I'm imposing is, although normally any site visit by a spider sets $spider_flag=true and $session_started=false, in the special case of web crawlers who are ranking us on the behaviour of the site that depends on a session existing, actually start a session and allow $spider_flag=true and $session_started=true.
Of course I shouldn't hardcode 'semrush' in the code, this is just a first step in working through this problem.
Any feedback welcome :)