Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow formatting of pretty URL with trailing slash #679

Open
Krinkle opened this issue Feb 18, 2023 · 3 comments · May be fixed by #692
Open

Allow formatting of pretty URL with trailing slash #679

Krinkle opened this issue Feb 18, 2023 · 3 comments · May be fixed by #692

Comments

@Krinkle
Copy link

Krinkle commented Feb 18, 2023

When using Apache or Nginx to serve a static site having pretty URLs, the default is to serve directories as directories and thus have a trailing slash (with redirect enforcement in place). This seems to be how many other static generators do it as well, e.g. Jekyll.

The issue I'm running into is that when the site is published, the links generated by getUrl() for anchor links and for <link rel="canonical"> in my theme are effectively redirects. This makes the site slower due to additional redirects, and can also make machine metadata harder to correlate due to URLs that are strictly speaking not identical.

I've tried a number of different things. For example:

slug: "episode-3-paul-irish"
path: "/2009/12/04/{slug}/"

However, the slash seems to be hardcoded and stripped away at the end regardless.

I'm willing to submit a patch if it is a welcomed addition. Let me know roughly what approach you'd like me to take in that case.

Related issues: #170

@ZachS
Copy link

ZachS commented Apr 20, 2023

For anyone encountering this issue, I have used the below nginx config to serve all pages without the trailing slash.

    # Strip trailing slash.
    rewrite ^/(.*)/$ /$1 permanent; 

    location / {
        # Make directories resolve to index.html without trailing slash.
        try_files $uri $uri/index.html $uri/ =404;
    }

Without this, every internal link was causing a redirect from no-slash to slash. Not good for SEO.

@bakerkretzmar
Copy link
Collaborator

Do you specifically need all your pages served with the trailing slash, or can you configure your server to strip it so all your URLs don't have it?

@Krinkle
Copy link
Author

Krinkle commented Jun 30, 2023

I need it served with a trailing slash as the intention is to preserve and match the URL structures of other sites part of the project. This would also avoid infinite redirects or vendor lock-in when e.g. migrating to another engine in the future.

@bakerkretzmar bakerkretzmar linked a pull request Jul 28, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants