About site()->homePage() uri

When I use this:

echo site()->homePage()->url() . "\n";
echo site()->homePage()->uri() . "\n";
echo site()->homePage()->slug() . "\n";

It prints this:

http://localhost/kirby2.2
home
home

The first one, url() is correct. My home page is in the root of the site and has no slug. What about the other two? I expected that at least one of them printed “”, an empty result.

So there is no way to print the uri of that page that reflect the site?

Well, the first one is correct because the home folder is routed to the site url; but you can just as well call the homepage with http://yourdomain.com/home. So “home” as uri and slug are correct as well.

Ahh, I see. Then it’s not a bug.

However, do we like this behaviour? Then every Kirby installation will have possible duplicate content (not optimal for SEO).

What are the benefints of that http://localhost/kirby2.2/home works as well?

No benefits, I don’t think. But this is a common behavior across other CMSs. Drupal comes to mind.

You can combat the potential SEO hit by using a canonical <link> tag in the <head> for the “official” URL of the page. SEs will respect that and not punish for duplicate content.

<link rel="canonical" href="<?= $page->url() ?>">

EDIT: Also, if you never link to /home, then SEs won’t find it. Make sure your RSS feeds use url(); they should be spitting out full URLs anyway.

https://support.google.com/webmasters/answer/139066?hl=en

Yes. I know about canonicals and redirects. The best solution might be to re-route it to 404 and set 404 as status code.

I would prefer if it worked that way out of the box. Maybe add an issue to the repository? Anyone seeing any benefits of keeping it the way it is now?

Generally I agree that it isn’t often needed and does not make that sense.

But there’s one case where it does: If you change the homepage to something else, then the old URL of the new homepage won’t keep working. That’s why it’s useful to keep the route for the homepage.
But maybe it could redirect using HTTP 307, so that could be a new feature.

That’s a rare case I think. I would prefer to add a redirect 301 myself in those rare cases. We change the page location from a page location to a home page location. For me it’s similiar to change the slug. When we change the slug the old page route is not still there. I think it should be the same for the home page (alternative) url.

I added an issue:

Let’s see what Bastian thinks about it. Maybe it’s just closed but then I at least tried.

Maybe it’s just me but I really wouldn’t expect http://localhost/kirby/home to 404. It might be beneficial from an SEO perspective, but certainly not expected or consistent with how Kirby generally works. The easiest SEO fix is to simply not add links to /home in the first place, or am I missing something? I wouldn’t change anything here.

1 Like

+1

I don’t know about the benefits of the current way. But I can see quite a few problems with the proposed new way. And in general with the more complexity it adds to understand Kirby in the first place.

I agree with @diondiondion and @distantnative

I don’t see much of a point of redirecting or throwing a 404 automatically. In most cases, nobody will ever visit the /home URI, including SEs.

And if one is very concerned with it, then a canonical link takes care of it, or it’s easy enough to set up a redirect back to /.