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

ingro's avatar

Nginx on Homestead error while visiting urls that end with php extension

I'm rebuilding an old website with Laravel 4.2 on Homestead but I have a funny problem with Nginx.

For SEO reasons the urls have to remain the same, so I have things like: http://www.sample.app/user/me.php

Problem is that with the default Nginx configuration on Homestead I get the infamous "No input file specified." error when I try to visit that url, while it works as the usual on url that didn't end with the php extension.

So how can I configure Nginx to pass "user/me.php" as querystring for laravel's index.php, as it's done for normal routes?

Thank you!

0 likes
13 replies
bashy's avatar

Redirect all old links to new ones! It'll be better in the long run...

If you don't want to, just add .php in the route name (I did it for some links that were still included so couldn't change them yet)

Router::get('user/me.php' 'blahController@index');
ingro's avatar

Thanks for the suggestion but for the SEO guy the "redirect all" strategy it's not viable...

The solution to add .php in the route name doesn't work because Nginx doesn't forward it to Laravel main script, so I'm in the same situation! :(

What i want to achieve is something similar to this written in Apache, but I'm a total noob with Nginx:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
bashy's avatar
bashy
Best Answer
Level 65

I work with an SEO company and for a new site using Laravel, I wouldn't use .php. Do a 301 redirect list from old URLs to new ones. If he thinks that's bad, he's not a very good "SEO guy".

As for the routing, I used Apache for that one site and not done it with Nginx.

Here is the conversion of that Apache rewrite

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}

// In the php part (would be extra stuff here)
location ~ \.php$ {
    try_files $uri /index.php =404;
}
2 likes
ingro's avatar

Thank you, that was what I looking for :) Even though I don't think the 404 part is needed in my case. I will also talk to the SEO guy about the redirects, in the meantime I can keep working.

Thanks to all!

bashy's avatar

Cool :)

For your notes, if you need this for SEO

Your Nginx config

include /etc/nginx/redirects; // or whatever you want to call it

In that file, you can do this for all links that you want to redirect

rewrite /some/url.php /some/url permanent;
rewrite /some/url2.php /some/url2 permanent;
rewrite /some/url3.php /some/url3 permanent;
1 like
ingro's avatar

Well there are like hundreds of that, the site is pretty big, so I think I should find a way to do it in a more generic way :P

bashy's avatar

Well for the most part you can do ones with regex, or even everything via one rewrite (since you just want to remove .php)

This should work for removing .php from all URLs (they will be the same, just without .php)

location / {
    try_files $uri $uri/ @extensionless-php;
}

location @extensionless-php {
    rewrite ^(.*)$ $1.php permanent last;
}
1 like
ingro's avatar

Thank you sir, I will sure try that when I'll need it! :)

1 like
timgavin's avatar

@bashy I'm also trying to remove the .php from my URLs, and everything I've tried so far has failed.

Where would I put this in my nginx config? Every time I try it the browser downloads a file.

location / {
    try_files $uri $uri/ @extensionless-php;
}

location @extensionless-php {
    rewrite ^(.*)$ $1.php permanent last;
}
bashy's avatar

@timgavin You just put it where your original location block was (as long as you're actually using nginx). If it's downloading a file, that means PHP is probably not working?

timgavin's avatar

@bashy Sorry about the delay, I didn't see the notification!

I'm doing this on a new Forge server, and PHP is definitely working as it's serving the files no problem. Just not when I try to remove the extension. Strange...

bashy's avatar

@timgavin Can't really tell without additional config examples. Probably not related to the part you pasted.

Please or to participate in this conversation.