Using robots.txt and sitemap.xml files with Slim

I am creating a website using Slim and wanted to do some SEO. The problem is Slim being more of an API based framework does not serve files typically and uses endpoints. How do i serve the robots.txt file and other sitemap.xml files to be indexed by search engines?

Just place this files into the public folder.

Iā€™m new to Slim

My directory structure is like this

  • cache
  • vendor
  • .htaccess
  • index.php

My .htaccess is like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

What changes do i need to perform? Sorry noob here.

With this directory structure you need to copy the files directly into the project root directory.

For security reasons, however, your directory structure is no longer recommended. The reason is that the vendor and cache folder can then be accessed directly via the world wide web.

I was having a look at your prisma project.

It contains two .htaccess files right. Can i use something similar to that?

Yes of course! :slight_smile:

You could read this comment or try the complete tutorial.

Thank you very much :slight_smile:

1 Like