Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Citti's avatar
Level 3

getting a .php URL to hit the laravel code base

Hi all, So currently running an API server in laravel Forge. Issue I am running into right now is URLs like http://domain.com/test.php do not actually hit my laravel code. NGINX is trying to find that file specifically instead of hitting my code. Ideally this would fall into the laravel application and 404 triggering a lookup i do in my DB for redirects. It would then find this domain.com/test.php in the DB and redirect to the value in the DB.

I have been stumbling around for a while with this one. Hiding the .php extension in NGINX is not going to do anything as it might be hidden but it will have the same behaivor.

All i am getting at this point is: "No input file specified. "

0 likes
11 replies
Cronix's avatar

What are you trying to do in test.php, or what's your actual goal with this external script? AFAIK, if something doesn't have a route defined laravel, laravel won't pick it up.

Citti's avatar
Level 3

So the application is a redirect tool. So what i want to happen is that when i point the domain.com to the live environment. The URL domain.com/test.php will Laravel 404 (which at that point i have a hook that goes into the DB to check for any urls that might need to be redirect - which this one obviously will have a record)... Buttt I can't even get laravel to pick this up. forget about giving it a specific route. it wont even come into the web.php file...

Cronix's avatar

I think you'd need to create a catch-all type route as your last route to catch anything that isn't "real".

Route::get('{unknown}', function ($unknown) {
    return $unknown;
});

This works in my tests, however it can't have a php extension or you do get the No input specified error.

yourapp.com/foo will echo foo

yourapp.com/blah will echo blah

yourapp.com/foo.php will error

yourapp.com/blah.php will error

I'm not sure you can easily get around the .php issue since everything is being routed through laravels bootstrap index.php file.

Citti's avatar
Level 3

Ok, Lets try this guys. Go to your laravel install. and put in any URL /asdf.php

ex: https://laravel.com/asdf.php

This is the behavior you will get. This never hits the laravel code base! so @Cronix putting a route does nothing. just put a die(); in the top of your web.php and nothing will happen. @Snapey its already pointing to the laravel install - but thanks.

What i want to do is have that or any .php page go through laravel and 404... does that make sense? or maybe I am explaining this incorrectly?

Citti's avatar
Level 3

@Cronix Just read your note about maybe it is not possible ... which maybe it is not... but looking to see if anyone has any ideas on how that would work if it is even possible... not sure...

bashy's avatar
bashy
Best Answer
Level 65

In your nginx php location, you need to direct it to a file if it's 404. Since you probably have;

location ~ \.php {
    //
}

It will read all .php URLs and try to find the file. If you want to direct all .php requests to Laravel (if the actual file doesn't exist), use something like this, not tested;

location ~ \.php {
        try_files $uri /index.php;
}
1 like
Citti's avatar
Level 3

@bashy that might just be what i need! Will test and report back. Thanks for the suggestion. Stay Tuned.

Citti's avatar
Level 3

@bashy you were right on! thanks man. For those using forge I updated my NGINX .php block to the following:

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    try_files $uri /index.php;
}   
2 likes
bashy's avatar

Good stuff! Happy to help :)

Please or to participate in this conversation.