#1 June 9, 2015 2:39pm

tsamant
Member
From: Chicago
Registered: May 14, 2015
Posts: 52

Router behavior for URLs with whitespace

This is arguably a bug: http://www.designcollective.com/%20 and http://www.designcollective.com/ serve the same content.

I picked the above as an example BigTree install. We are on 4.2 and have the same problem.

The real-life consequence is that the moment someone linked us with a trailing space, Google picked it up as "duplicate content". This is now harming our search standing.

An immediate 301 to the real URL with whitespace stripped seems like the solution, but perhaps there are better ways to fix this.

Best,
Tushar

Offline

#2 June 10, 2015 9:05am

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 978

Re: Router behavior for URLs with whitespace

This seems to be the result of how MySQL treats string storage/comparison:
http://stackoverflow.com/questions/7455 … r-does-not

The easiest way to resolve this for SEO purposes is to set canonical URLs in your headers:
https://support.google.com/webmasters/a … 9066?hl=en

I'd generally do something like this as it will ignore the canonical tag for routed templates (since they accept sub-routes you don't necessarily want Google to only list the top level page):

<? if (!$routed) { ?>
<link rel="canonical" href="<?=WWW_ROOT.$bigtree["page"]["path"]?>/" />
<? } ?>

I believe $routed should exist in your header unless that variable is changed inside a template (it's not really an environment variable, just happens to be set in the router). If it was modified in the template you'll need to do something like this to check the routed-ness instead:

$template = $cms->getTemplate($bigtree["page"]["template"]);
if (!$template["routed"]) {

Offline

#3 June 11, 2015 4:47pm

tsamant
Member
From: Chicago
Registered: May 14, 2015
Posts: 52

Re: Router behavior for URLs with whitespace

This fix is inserting the right canonical tag in the home page, thanks!

To document the entire change: in templates/layouts/_header.php, after the title tag, add:

<? if (!$routed) { ?>
<link rel="canonical" href="<?= preg_replace('/\/*$/', '', WWW_ROOT.$bigtree["page"]["path"]) ?>/" />
<? } ?>

Last edited by tsamant (June 11, 2015 4:50pm)

Offline

Board footer

Powered by FluxBB

The Discussion Forum is not available on displays of this size.