0
votes

I have a website using Silex.

I have uploaded few files in root folder like robots.txt and few push notifications sdk.

Problem is getting error when I am trying to access that file using url : domain.com/robots.txt is giving error when trying to access from chrome browsers

No route found for GET /robot.txt

Fatal error: Uncaught exception 'Symfony\Component\Routing\Exception\RouteNotFoundException' with message 'Unable to generate a URL for the named route "" as such route does not exist.' in /home/path/domain.com/vendor/symfony/routing/Symfony/Component/Routing/Generator/UrlGenerator.php:134 Stack trace: #0 /home/path/domain.com/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Extension/RoutingExtension.php(45): Symfony\Component\Routing\Generator\UrlGenerator->generate(NULL, NULL, false) #1 /home/path/domain.com/data/twig/fe/bb/cd3e9843c1ef02ee591d59cfb1afd51eb5cd52af42e38573c035f7ef4128.php(146): Symfony\Bridge\Twig\Extension\RoutingExtension->getPath(NULL, NULL) #2 /home/path/domain.com/vendor/twig/twig/lib/Twig/Template.php(276): __TwigTemplate_febbcd3e9843c1ef02ee591d59cfb1afd51eb5cd52af42e38573c035f7ef4128-doDisplay(Array, Array) #3 /home/path/domain.com/vendor/twig/twig/lib/Twig/Template.php(250): Twig_Template->displayWithErrorHandling(Array, Array) #4 /home/path/domain in /home/path/domain.com/vendor/twig/twig/lib/Twig/Template.php on line 291

1
Silex use a controller to associate an url with a view. If you ask for the url /robots.txt but you don't create a controller for robots.txt, you can't access it. If you really want to access it with an URL, just create a controller like $app->get('/robot') ... and the view will just be robots.txt - Mickaƫl Leger

1 Answers

0
votes

When you say root folder, do you mean the public_html folder, or the folder that contains folders like 'templates' and 'src'?

The large php error after "No route found for 'GET /robot.txt'" is actually being thrown when Silex is attempting to process a template document. I'm guessing the error template(s) in your silex install aren't set up correctly.

If your robots.txt file is in your publicly accessible foilder you don't need a Silex controller to serve it, but you do need the webserver to be configured to serve real files before it tries passing the request to index.php.

There are exmaple configs here https://silex.symfony.com/index.php/doc/2.0/web_servers.html

For apache the relevant bit is

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

For nginx the relevant bit is

try_files $uri /index.php$is_args$args;

These are the parts of the config that say 'check if there's actually a file for this url, and use index.php if there isn't'