Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

1 Answer 1

Actually found an answer right after I posted this question.

location ~ \.php$ {
    fastcgi_pass    127.0.0.1:9000;
    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
add comment

Your Answer

 
discard

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.