When switching to any other page, the error falls out: Sorry,

Routes:

Route::get('/about', function(){ return view('about'); }); Route::get('/posts', 'PostController@index'); 

In the welcome.blade.php file - the main page

 <div class="title mb-md"> Napotest </div> <div class="links"> <a href="{{ url('/about') }}">О нас</a> <a href="https://laracasts.com">Войти или зарегистрироваться</a> <a href="{{ url('/posts') }}">Список статей</a> <a href="https://forge.laravel.com">Список пользователей</a> </div> 

PostController.php

 public function index() { $posts = $this->model->all(); return view('post.all', compact('posts')); } 

.htaccess

 <IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On # Redirect Trailing Slashes If Not A Folder... RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ /$1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] # Handle Authorization Header RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] </IfModule> 

Virtual Host Settings

 ##<VirtualHost *:80> ##ServerAdmin webmaster@dummy-host.example.com ##DocumentRoot "C:/xampp/htdocs/dummy-host.example.com" ##ServerName dummy-host.example.com ##ServerAlias www.dummy-host.example.com ##ErrorLog "logs/dummy-host.example.com-error.log" ##CustomLog "logs/dummy-host.example.com-access.log" common ##</VirtualHost> ##<VirtualHost *:80> ##ServerAdmin webmaster@dummy-host2.example.com ##DocumentRoot "C:/xampp/htdocs/dummy-host2.example.com" ##ServerName dummy-host2.example.com ##ErrorLog "logs/dummy-host2.example.com-error.log" ##CustomLog "logs/dummy-host2.example.com-access.log" common ##</VirtualHost> 

Routs

enter image description here

Physically, these two pages exist about.blade.php and all.blade.php. Why does an error always appear ??

Interestingly, if the line browser to write: http: //localhost/Projects/mysite/public/index.php/about - the page opens!

  • show settings .htaccess - Anton Kucenko
  • @AntonKucenko, added to the question - dexploizer
  • Are you sure that you have Apache, and not nginx? If not, then .htaccess is not used. - Daniel Protopopov
  • @DanielProtopopov, launched running xampp with apache .. - dexploizer
  • Add a code to configure a virtual host, please. - Daniel Protopopov

3 answers 3

Try to do this: In the Routes

 Route::get('/posts', 'PostController@index')->name('posts') //именной роут 

In welcome.blade.php

 <a href="{{ route('posts') }}">Список статей</a> //вписывается имя именного роута 

And in your case there may be an error in that it’s not a relative path that is taken, but a full one, but I’m not sure

  • Thanks for the answer! But, unfortunately, I have already tried it - the result is the same. And how to check which ways? Or where can this be corrected? - dexploizer
  • Another option to do this (in this method, you can use laravel constants like url () -> full, so that not all the way): <a href = "{{url (' localhost / Projects / mysite / public / index.php / about ')}} "> About us </a> <a href="{ after url ('url()-> full.' / About ')}}"> About </a> Or <a href = "{{url ('./ about')}}"> About us </a> But it's vryatli - Max Moskalenko
  • All the same. For some reason, does not see the view - dexploizer
  • You can also check the correctness of directories, but in general the URL is very strange, it’s strange that a file opens from index.php, and even more strange that index.php is shown at all, I thought that laravel on routing hides it - Max Moskalenko
  • index.php is not shown, you can simply specify it explicitly and see whether it comes at all or not - dexploizer

This is where you made a mistake: you are in the wiew / post / all.blade.php folder (create a file here and see the result)

To get the file from the folder: view / all.blade.php you need to specify in the controller

 return view('all', compact('posts')); 
  • Thanks for the suggested answer, but I have all.blade.php in views/post - dexploizer
  • or even simpler: <IfModule mod_rewrite.c> RewriteEngine On RewriteCond% {REQUEST_URI}! ^ public RewriteRule ^ (. *) $ public / $ 1 [L] </ IfModule> - user-name

Thank you all for the answers! I changed the .htaccess file to something below and it all worked!

 <IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ RewriteRule ^(.*) - [E=BASE:%1] RewriteCond %{ENV:REDIRECT_STATUS} ^$ RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L] RewriteCond %{REQUEST_FILENAME} -f RewriteRule .? - [L] RewriteRule .? %{ENV:BASE}/index.php [L] </IfModule>