I am trying to rewrite some links with nginx, but php files are downloaded instead of executing, if I run the php file in browser is working, so no fastcgi problem.
I already checked other simillar questions here but nothing helped me.
My nginx.conf file
....
location / {
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
expires max;
}
location ~ [^/]\.php(/|$) {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9002;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
}
location ~* "/\.(htaccess|htpasswd)$" {
deny all;
return 404;
}
location /contact {
rewrite ^/contact/?$ /contact.php last;
}
I need to rewrite contact.php to /contact but is not working.
I also tried :
location /contact {
rewrite ^/contact?$ /contact.php last;
}
location /contact {
rewrite ^/contact$ /contact.php last;
}
location /contact {
rewrite ^/contact?$ /contact.php break;
}
Nothing works. I do not had this problem is the past…
Best Answer
I found the problem, I just replaced:
with