I have following server configuration:
server {
listen 80;
server_name mysite.proj;
location / {
root /path/to/mysite.proj/www;
index index.php index.html index.htm;
}
access_log /path/to/mysite.proj/data/logs/access.log;
error_log /path/to/mysite.proj/data/logs/error.log;
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php last;
}
location ~ \.php$ {
root /path/to/mysite.proj/www;
fastcgi_pass 127.0.0.1:8081;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /path/to/mysite.proj/www$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 80;
server_name www.mysite.proj;
rewrite ^/(.*) http://mysite.proj/$1 permanent;
}
It works fine, every url is rewritten to index.php. But in same time every stylesheet url, every javascript url, every image url is rewriten as well. How to write rewrite rule to not rewrite urls for css, js, images files?
try_files $uri $uri/ /index.php;As a side note, I believe nginx uses -f instead of -e for checking the existence of a file. – cyberx86 Oct 19 '11 at 19:01if (!-e $request_filename) { rewrite ^(.+)[^(css|js|gif|...)]$ /index.php last; }Not exactly elegant enough for me to submit it as an answer, though (through some combination of location and try_files, you should be able to do that without the if) – cyberx86 Oct 19 '11 at 20:56