Skip to content

Commit

Permalink
* Smarter handling of PHPSESSID variables for search engines. First o…
Browse files Browse the repository at this point in the history
…f all, moved the code to the template handler, then skipped it entirely if there's already a canonical URL. If there isn't, added a test for noindex (no need to remove the var if the engine can't index the page in the first place), and did a shorter and smarter replacement of the var. (index.php, Subs-Template.php)
  • Loading branch information
Nao committed Mar 21, 2014
1 parent 033c80b commit 406792e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
5 changes: 5 additions & 0 deletions core/app/Subs-Template.php
Expand Up @@ -60,6 +60,11 @@ function obExit($start = null, $do_finish = null, $from_index = false, $from_fat
if (empty($context['page_title_html_safe']))
$context['page_title_html_safe'] = empty($context['page_title']) ? '' : westr::htmlspecialchars(un_htmlspecialchars(strip_tags($context['page_title'])), ENT_COMPAT, false, false);

// Try to get rid of ?PHPSESSID for robots.
if (empty($context['canonical_url']) && we::$user['possibly_robot'] && empty($context['robot_no_index']) && strpos(we::$user['url'], ($sn = session_name()) . '=') !== false)
if (we::$user['url'] != ($correcturl = preg_replace('~(?:\?' . $sn . '=[^&;]*$|\b' . $sn . '=[^&;]*[&;])~', '', we::$user['url'])))
$context['canonical_url'] = $correcturl;

// Start up the session URL fixer. Don't do it in SSI, as it did it already.
if (!defined('WEDGE') || WEDGE != 'SSI')
ob_start('ob_sessrewrite');
Expand Down
17 changes: 0 additions & 17 deletions index.php
Expand Up @@ -98,23 +98,6 @@
// Load the user's cookie (or set as guest) and load their settings.
we::getInstance();

// Get rid of ?PHPSESSID for robots.
// !! Probably useless, thanks to canonical URLs.
if (we::$user['possibly_robot'] && strpos(we::$user['url'], 'PHPSESSID=') !== false)
{
$correcturl = preg_replace('~([?&]PHPSESSID=[^&]*)~', '', we::$user['url']);
$correcturl = str_replace(array('index.php&', 'index.php??'), 'index.php?', $correcturl);
$correcturl = str_replace(array('/&?', '/??', '/&'), '/?', $correcturl);
$correcturl = preg_replace('~&$|\?$~', '', $correcturl);

if ($correcturl != we::$user['url'])
{
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $correcturl);
exit;
}
}

// Check the request for anything hinky.
checkUserBehavior();

Expand Down

0 comments on commit 406792e

Please sign in to comment.