1

I have the following route: Route::resource('users', 'ProfileController'); When I go to site.com/users/123, it loads the page properly. I can also go to site.com/index.php/users/123 and get the same page (not sure if laravel is by default intended to do that).

If I change the url to site.com/does_not_exist/users/123, laravel returns a 404, as you would expect. However, if I go to site.com/does_not_exist/index.php/users/123, laravel loads the page. I can put any random path, non-existent path between site.com and index.php and it will work.

Why doesn't laravel return a 404 for this? How do I fix it so it does?

Telanor
  • 4,419
  • 6
  • 29
  • 36

1 Answers1

0

Because the index.php is the index.php in public folder that handles the incoming request and its a automatically generated class loader

This might work (similar question on how to fix this)

1-Renaming the server.php to index.php (no modifications)

2-Copy the .htaccess from public (like rimon.ekjon said below)

3-Changing .htaccess it a bit as follows for statics:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]

If there are any other static files needed just add the extension to the previous declared list

Source

Community
  • 1
  • 1
Achraf Khouadja
  • 6,119
  • 4
  • 27
  • 39