Answer the question
In order to leave comments, you need to log in
Laravel dynamic robots.txt plus nginx php-fpm not working?
We use dynamic robots.txt, the text of which is stored in the database and configured in the admin panel.
Laravel has a route for this:
Route::get('/robots.txt', function(){
$settings = \App\Block::where('kind', 'robots.txt')->first();
$fileText = $settings->code;
$headers = ['Content-type'=>'text/plain','Content-Length'=>sizeof($fileText)];
return Response::make($fileText, 200, $headers);
});
Answer the question
In order to leave comments, you need to log in
What and how exactly does not work?
Maybe you have a real robots.txt file and nginx gives it in the first place. In this case, you need to remove it.
1. The nginx config for this site should not contain the line location = /robots.txt { access_log off; log_not_found off; }
2. Route with Streamed Downloads
Route::get('/robots.txt',function(){
return response()->streamDownload(function () {
echo \App\Block::where('kind', 'robots.txt')->first()->code;
}, 'robots.txt', ['Content-Type'=>'text/plain'],'inline');
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question