saberland/saber

Do you want to work on this issue?

You can request for a bounty in order to promote it!

Redirect user when trailing slash omitted or included depending on permalink settings #457

limitlessloop posted onGitHub

<!-- Please don't delete this template or we'll close your issue -->

<!-- Before creating an issue please make sure you are using the latest version of Saber. -->

<!-- Issues which contain questions or support requests will be closed. -->

<!-- Please ask questions via following several ways. -->

<!-- https://chat.saber.land/ -->

<!-- https://stackoverflow.com/questions/ask?tags=saberjs -->

Bug report

When customising a permalink Saber should honour the chosen permalink pattern. Currently, a user can visit both themes/ and theme when a permalink is specified as page: /:slug/. Search engines treat these two paths as different pages. Therefore it is in the best interest for SEO reasons to only allow one. A possible solution is to redirect the user when the trailing slash / is omitted and when it is included.

Steps to reproduce

This occurs on a fresh install of Saber and also the main Saber website.

<!-- If you are reporting a bug that can ONLY be reproduced on your repository, PLEASE provide this repo link. That takes guessing work out of the way and saves us time. -->

<!-- You can also use this CodeSandbox starter https://bit.ly/2IlcpNF -->

What is expected?

Redirect the user following the permalink pattern specified in the Saber config.

For example:

// saber.config.yml
permalinks:
  page: /:slug/

User enters:

// browser
saber.land/themes

Website redirects to:

// browser
saber.land/themes/

If page: /:slug is specified it should do the opposite to the above and remove the trailing slash.

What is actually happening?

The user can visit both URLs saber.land/themes and saber.land/themes/ both with trailing slash omitted or included, however the URL does not change. Google treats both URLs as separate pages with same content.

Other relevant information

There is some information regarding trailing slashes on the Google webmaster blog. https://webmasters.googleblog.com/2010/04/to-slash-or-not-to-slash.html?m=1

Here is some more up-to-date information and advice regarding how to fix this using .htaccess. https://www.danielmorell.com/guides/htaccess-seo/redirects/https-www-and-trailing-slash

I'm not familiar with one-page applications, but maybe for now, this can be managed using the above method? I'll give it a go when I get chance.


@issuehunt has funded $40.00 to this issue.


posted by issuehunt-app[bot] over 5 years ago

I'm not sure how this can be solved by Saber, since Saber only outputs static files and it's up to the user to serve them 🤔 For example, on Netlify you can enable "Pretty URLs" - https://www.netlify.com/docs/redirects/#trailing-slash

posted by andreasvirkus over 5 years ago

Saber uses a server for development purposes, so perhaps a way to configure that could help for developing purposes. Also, a change would need to be made to Saber regarding the way links are handled so that the correct preference is used, which would affect the static build.

Regarding live sites, Netlify doesn't allow consistent treatment of URLs because directories get trailing slashes and files don't. So the only way to allow that functionality with Netlify would be if Saber outputted all files as either non-index files (for no trailing slash) or index files (for trailing slash). Or obviously, if Netlify allowed the user to force all URLs to remove trailing slashes or keep them.

posted by limitlessloop over 5 years ago

The Netlify doc I linked states (for the Pretty URL feature):

/.../ In addition to forwarding paths like /about to /about/ (a common practice in static sites and single page apps), it will also rewrite paths like /about.html to /about/.

posted by andreasvirkus over 5 years ago

It was a while since I tried Netfliy. I think when pretty URLs are enabled it will force the trailing slash. But when they are disabled, it will add a trailing slash for index.html files only. I don't think there was a way to enforce removing the trailing slash when I last used Saber with Netlify, but maybe there is a way one could disable outputting an index.html file in Saber to avoid this problem.

posted by limitlessloop over 5 years ago

I've found what happens with Netlify. Their documentation is incorrect. This is what happens with URLs when Pretty URLs is enabled.

<img width="877" alt="Screenshot 2019-09-28 at 15 52 31" src="https://user-images.githubusercontent.com/5551/65818275-000d5400-e208-11e9-8fb3-00f40b87e138.png">

I guess then the only way to allow non-trailing slash URLs with Netlify would be if Saber could output all files as non-index files. I remember seeing a setting that did something like this, but I believe it only did it for certain situations. This looks like it's probably more of a gripe with Netlify as they don't support non-trailing slash URLs.

posted by limitlessloop over 5 years ago

Fund this Issue

$40.00
Funded
Only logged in users can fund an issue

Pull requests

Recent activities

eslamhiko submitted an output to  saberland/ saber# 457
over 5 years ago
issuehunt funded 40.00 for saberland/saber# 457
over 5 years ago