Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to rewrite all requests to /index.php, except /css/* and /js/*.

This is my original config

location / {
    try_files $uri /index.php$is_args$args;

which works, but lets me access all files directly. I tried this

location / {
    rewrite ^(.+)$ /index.php break;

but couldn't get past weird errors like PHP parsing breaking. After I get /index.php rewrite working I assume I should do something like location /css/ { .. } etc, but I'm not really sure.

Any idea how to solve this? Thanks.

share|improve this question

Actually found an answer right after I posted this question.

location ~ \.php$ {
    fastcgi_index   index.php;
    fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include         fastcgi_params;

location /css/ {}
location / {
    rewrite ^ /index.php last;

The trick seemed to be to put the php location above the other ones.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.