Skip to content

Allow configuration of trailing slashes for meta and sitemap #387

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

Open
icemancast opened this issue May 22, 2025 · 7 comments
Open

Allow configuration of trailing slashes for meta and sitemap #387

icemancast opened this issue May 22, 2025 · 7 comments
Labels
feature request New feature or request

Comments

@icemancast
Copy link

A client needs the sitemap urls to have the appended slash in the url. How can I achieve this?

@duncanmcclean duncanmcclean added the question Further information is requested label May 23, 2025
@jesseleite jesseleite changed the title Ending Forward Slash on Sitemap.xml Allow configuration of trailing slashes for meta and sitemap May 23, 2025
@jesseleite
Copy link
Member

This is probably something that should be configurable in Statamic core, so that packages like seo-pro and ssg can opt-into trailing slashes. We've thought about an implementation on the URL facade, maybe something like URL::enforceTrailingSlashes(bool), so that it can be toggled on and off for specific situations without affecting the whole app.

Related statamic/ideas#1293
Related statamic/ssg#65

@jesseleite jesseleite added feature request New feature or request and removed question Further information is requested labels May 23, 2025
@jesseleite
Copy link
Member

@icemancast In the meantime, you can extend the Sitemap class and override the pages() method by following the steps in this PR to rebind your custom sitemap class extension. Something like this will forcibly append trailing slashes to all your sitemap URLs...

class CustomSitemap extends Sitemap
{
    public function pages(): array
    {
        return collect(parent::pages())
            ->map(fn ($page) => array_merge($page, [
                'loc' => $page['loc'].'/',
            ]))
            ->all();
    }
}

@icemancast
Copy link
Author

Awesome thanks @jesseleite , google seems to be adding rules by the minute for everything and marketers seem to keep hitting me with something new I need to help with.

@jesseleite
Copy link
Member

jesseleite commented May 23, 2025

@icemancast For sure!

Fwiw, I'm not convinced trailing slashes matter. I think this is often a misunderstood SEO requirement. For example, looking at Google's guide, which references sitemaps.org, where the protocol only requires trailing slashes if your web server requires them to serve the page...

Image

That said, I still don't think it hurts to make it configurable! ❤️

@icemancast
Copy link
Author

@jesseleite thank you this helps my case too :).

@icemancast
Copy link
Author

@jesseleite I did figure out the issue. So this statamic sites shoots to netlify and it compiles the static files. Netlify by default appends the forward slash which doesn't match the sitemap. So their seo program is complaining about the issue.

@jesseleite
Copy link
Member

@icemancast Ah good to know, that makes sense!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants