Welcome! Log In Create A New Profile

Advanced

wordpress - permalinks with .php in url not working

Posted by jpcadillac 
wordpress - permalinks with .php in url not working
June 08, 2015 05:36PM
I'm moving a site from an Apache server to a nginx server. A lot of the pages have a .php extension at the end of the permalink. Trying to view those pages results in a nginx 404 Not Found. However those pages worked fine on Apache. Here is the server block config for the site:

# Vhost Config: example.com

server {

root /var/www/vhosts/sites/www.example.com/web;
index index.php index.html index.htm;

server_name example.com www.example.com;

port_in_redirect off;

location /Denied {
return 403;
}

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

location ~* ^(/sitemap).*(\.xml)$ {
rewrite ^ /index.php;
}

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;

location = /50x.html {
root /usr/share/nginx/html;
}
location = /404.html {
root /usr/share/nginx/html;
}

location ~ ^/.*\.php$ {
try_files $uri = 404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico|xml)(\?ver=[0-9.]+)?$ {
expires 1w;
log_not_found off;
}

location ~ /\. {
deny all;
}

location = /ping.html
{
access_log off;
}

}

I commented out "#try_files $uri = 404;" to see if that would work however that resulted in a "File not found." message.

So the main problem is trying to get WordPress and nginx to see the permalink with a .php extension before it tries to run a .php file which it sees is not a real file.

Is this possible?
Re: wordpress - permalinks with .php in url not working
June 08, 2015 07:52PM
I ended up changing

location ~ ^/.*\.php$ {
try_files $uri = 404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

to

location ~ ^/.*\.php$ {
try_files $uri $uri/ /index.php?$args;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

It now works, but I feel that is a security issue now.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 302
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready