Having a very hard to trying to figure this out. I have changed my website from another platform to Joomla and now Nginx is unable to handle old urls.
My Old Urls were like this:
example.com/home.php
example.com/contact-us.php
My New Joomla SEF Urls are like this:
example.com/home
example.com/contact-us
I have the following Nginx config as per Joomla guide:
location / {
try_files $uri $uri/ /index.php?$args;
}
# Process PHP
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
I want Nginx to pass these old urls to Joomla to handle it. Now, what is happening is, Nginx is treating these old urls as php files and then showing me this No input file specified.
error. I then changed the try_files inside the php block to try_files $uri /index.php?$args;
so my Nginx config looks like this:
location / {
try_files $uri $uri/ /index.php?$args;
}
# Process PHP
location ~ \.php$ {
try_files $uri /index.php?$args;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Is this valid? Would this cause an infinite loop issues in some cases? Is this is right way to do this? I didint find any solution similar to this. Can someone guide me please?
location /
is never usedThe problem you have is related to location precedence (emphasis added).
As such, this location block:
Matches this request:
and no other location block is relevant.
As you already realize, this means that nginx will attempt to find and serve
home.php
resulting in a 404.Use a @location for the main index.php file
Normally the only php file of relevance is
index.php
, you can make use of it like so:Use another location block for *.php requests
In addition to a front controller, joomla allows/expects other php files to be directly accessed such as
/administrator/index.php
. To allow access to them without trying to process missing php files:This will allow direct access to other php files (which ordinarily, isn't a good thing...) falling back to use
/index.php
, via the@joomla
location, for any php file requests that don't exist.Note that the above setup is also in the documentation.