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

eickhardt's avatar

Routes with .php file extensions

Hi guys,

I'm using 5.1 and homestead. Becuase of some old code, I have to make some routes available that end with ".php". What I have so far is this:

// Route
Route::get('config/{file}{extension?}', [
    'uses' => 'Frontend\ImageDesignerController@test',
    'as' => 'testest'])
->where(['file' => '[a-zA-Z0-9-_]+', 'extension' => '\..+' ]);

// Controller
public function test($file, $extension)
{
    return "$file : $extension";
}

If I go to /config/designer.flip I get the desired result: "designer : .flip". But if I go to /config/designer.php I get "No input file specified.". Is it a nginx setting I'm missing?

Edit: Thanks for the help guys - @jensaronsson 's answer did the trick. I put his code in my /etc/nginx/sites-enabled/{sitename}.

0 likes
2 replies
sid405's avatar

Could really be nginx @eickhardt .

I don't have a nginx install at hand but tried your code on apache and it works as expected...

Hope that helps.

jensaronsson's avatar
Level 2

Its its a nginx setting you are missing. Nginx is sending all .php to fastcgi to be parsed.

You can add another location block to intercept and send "designer.php" the request to index.php and it should then get parsed by laravel and hit the correct route.

    location ~ ^/config\/.*\.php$ {
        try_files $uri $uri/ /index.php?$query_string;
    }

Im not an expert on nginx so please correct mistakes.

EDIT. I just realised that if you put a file like "text.php" in "/public/test.php" that file will be downloaded, so to avoid that change to.

    location ~ /config\/.*\.php$ {
        try_files /index.php?$query_string /dev/null =404;
    }

Now it will try to send it to laravel first, if that would fail it will send it to /dev/null and set a not found 404 status.

Please or to participate in this conversation.