Mario Fridrichovsky Mario Fridrichovsky - 7 months ago 28
PHP Question

nginx CSS break after adding rewrite from $ to $.php

If I will add the following line to my nginx configuration it will break my website and will run without CSS:

location / {
try_files $uri $uri/ =404;
rewrite ^/(.+)$ /$1.php last;
}

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}


if I comment the rewrite condition everything will work fine.

What can I do to bring both things to work, the rewrite condition and the css style sheet?

Edit: I got a new problem, now all files like
test.php
work fine without writing
.php
, but folders like
users/
won't work, I still reveive
File not found
, normaly it should take the
index.php
or
index.html
from the folder, how can I provide both functions? add
.php
to files and use
inde.php/html
from folder?

Answer

Add the following block to your configuration to handle static files.

location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
  access_log        off;
  expires           30d;
  root /path/to/public/root;
}