2

I am making a sitemap for a site made with Laravel and do not know if I am going the right way. I read an article from Google (https://developers.google.com/search/docs/advanced/sitemaps/build-sitemap#general-guidelines, second item) saying that a sitemap will affect all the child directories from where the file containing the sitemap is located. But the problem is that I do not have a file per se, I have a controller that outputs an .xml when my route site.com/sitemap is called, so it's not an .xml, but rather a .php outputting an xml.

Google Search Console seems to have accepted this but I do not know if this is correct.

Thanks in advance for all the help. And sorry if this is more of a programming question.

3
  • 1
    You only need to generate a loop that outputs a posts list, showing the URL. Finally, check the sitemaps syntax and add the necessary tags to make a standard sitemap.
    – Unix
    Oct 8 at 14:44
  • Ok, got it. Thank you a lot. Oct 8 at 16:05
  • 1
    It's more accurate to say that a sitemap will affect all the child directories from where the sitemap's path is located. In other words, the URL that the (in this case generated) xml resource can be accessed at. Oct 8 at 16:33
4

saying that a sitemap will affect all the child directories from where the file containing the sitemap is located.

I'm not a fan of that wording. It's basically saying that a sitemap can only contain URLs that are at the same level or lower in the URL-path structure from where the sitemap is served from. Most sites serve their sitemap from the root directory so can contain URLs that cover the entire domain. However, a sitemap returned from example.com/foo/sitemap can contain example.com/foo/bar and example.com/foo/bar/baz, but not example.com/bar - which is outside of the URL-path tree.

Don't get hung up on the word "file". As far as the user-agent (eg. Googlebot) is concerned that makes the request, it does not know from the response whether the request mapped directly to a physical file or not.

And "directories" is referring to URL path segments, not physical directories on the underlying filesystem (which the user-agent making the request knows nothing about).

But the problem is that I do not have a file per se, I have a controller that outputs an .xml when my route site.com/sitemap is called, so it's not an .xml, but rather a .php outputting an XML

That's perfectly fine. As mentioned above, the user-agent making the request can not tell the difference, since the HTTP response is likely to be the same.

Aside: The only potential issue might be if you are dynamically generating the sitemap on every request. This could be slow and resource intensive. The response should be cached server-side so it doesn't need to be generated on every request, only when your site has changed. (If the response is cached then you are "kind of" returning a "file", depending on how your caching works.)

1
  • 1
    That's a deeper look I didn't know, so thank you a lot for your knowledge. It was really helpful. Oct 14 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.