Using robots.txt and sitemap.xml files with Slim


#1

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?


#2

Just place this files into the public folder.


#3

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.


#4

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.


#5

I was having a look at your prisma project.

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


#6

Yes of course! :slight_smile:

You could read this comment or try the complete tutorial.


#7

Thank you very much :slight_smile: