iamvishnusankar / next-sitemap

Sitemap generator for next.js. Generate sitemap(s) and robots.txt for all static/pre-rendered/dynamic/server-side pages.
https://next-sitemap.iamvishnusankar.com
MIT License
3.27k stars 126 forks source link

siteUrl overwritten by non-trailing slash when trailingSlashes=false #833

Open thomcrielaard opened 3 months ago

thomcrielaard commented 3 months ago

Describe the bug When trailingSlashes is set to false, but siteUrl is set to "yourdomain.com/", next-sitemap will automatically remove the trailing slash (see additional context on why I'm doing this).

To Reproduce Steps to reproduce the behavior:

  1. Go to 'next.config.js' and set trailingSlashes to false (or leave it out for the default setting, which is false)
  2. Go to 'next-sitemap.config.js' and set siteUrl to yourdomain.com/ (with a trailing slash)
  3. Run the next-sitemap command
  4. Check sitemap-0.xml. It now has removed the trailing slash from the domain you provided

Expected behavior I would expect the siteUrl property to be dominant here, since this is manually added. All other URLs should still be generated without a trailing slash.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Admittedly, a bit of a weird configuration, but I don't see any alternatives to keep SEO tools satisfied. All relative URLs to the homepage go to "/", meaning they direct to your domain with a trailing slash. SEO tools don't really like it when there are no incoming URLs to your canonical page, thus if you make the canonical page "yourdomain.com" and direct all homepage links to "/" (and thus yourdomain.com/), the SEO tools will throw an error. To solve this, you can make the homepage canonical version "yourdomain.com/", even though the page will still be redirected to "yourdomain.com", which does keep the tools satisfied. All other pages can just be non trailing. I don't know if this is "the way to go", so if anyone has any suggestions please drop them down below :)

github-actions[bot] commented 1 month ago

Closing this issue due to inactivity.

comlaterra commented 3 weeks ago

Is this repo abandoned?

thomcrielaard commented 3 weeks ago

It seems like it... I've tried to fix the issue myself, but don't have a lot of time and couldn't figure it out unfortunately