Why NGINX rewrite rule is working offline but when i put it online it is not working?

Posted July 18, 2017 2.1k views

server {
listen xxxxxxxxxxxxx;
server_name xxxxxxxx;

if ($timeiso8601 ~ “^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})”) {}
log /home/websites/$year-$month-$day.log;
log /home/websites/;

root /home/websites/;
index index.php index.html index.htm;

location / {
rewrite ^/chi-siamo/?([a-z-]+)?/?$ /chi-siamo.php?chi=$1 last;
rewrite ^/categoria/?([a-z-]+)?/?([a-z0-9-]+)?/?$ /categoria.php?cat=$1&id=$2 last;
rewrite ^/nazione/italia/?([0-9]+)?/?$ /nazione.php?nazione=italia&pg=$1 last;
rewrite ^/nazione/italia/?([a-z0-9-]+)?/?([a-z0-9-]+)?/?$ /nazione.php?nazione=italia&regione=$1&id=$2 last;
rewrite ^/nazione/?([a-z-]+)?/?([0-9-]+)?/?$ /nazione.php?nazione=$1&id=$2 last;
rewrite ^/ricerca/?([a-z0-9-]+)?/?([0-9]+)?/?$ /ricerca.php?search=$1&pg=$2 last;
rewrite ^(.*[^/])$ $1/ permanent;

location ~ .php$ {
root /home/websites/;
index index.php;
fastcgiparam SCRIPTFILENAME $documentroot$fastcgiscriptname;
include fastcgi

here is my configuration, i begging anyone to help me. Have a nice day and God bless you all :)

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi @cabrerarace34

What do you mean with “working offline, but not online” ? It works on your local Nginx, but not when you put it on your droplet?
What is working, what is not working?

Can you post the last 30 lines from the error log:

tail -30 /home/websites/

By the way, if is your domain, then you really need to update both Nginx and PHP, since they are very outdated, which might be the reason why you’re having problems.

PS. Please use the code button </> in the comment editor, when adding code/configurations/logs, so it keeps the formatting.