Mario Fridrichovsky Mario Fridrichovsky - 1 year ago 71
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
work fine without writing
, but folders like
won't work, I still reveive
File not found
, normaly it should take the
from the folder, how can I provide both functions? add
to files and use
from folder?

Answer Source

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;