nginx下wordpress的rewrite
国庆前买了 linode 的VPS,算是edong撤走了,不用再去照相了,照相这种备案方式和以前BBS专项备案一样,没有什么操作性,迟早也要取消的。以前用edong vps,跑的是nginx+apache,这次直接换成nginx+spawn-fcgi。
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress |
上面是推荐的rewrite规则,但是这样规则会将不存在的图片,css等文件也都转发到index.php,这些文件应该报个404的。
#现在nginx上使用的rewrite server { server_name yuehei.37net.com; access_log /var/log/nginx/yuehei_37net_com_access.log main; error_log /var/log/nginx/yuehei_37net_com_error.log info; root /data/html/37net.com/yuehei; index index.html index.htm index.php; error_page 403 =200 /403.html; location = /403.html { root /data/html; } error_page 404 =200 /404.html; location = /404.html { root /data/html; } location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php last; break; } } location ~ \.(gif|jpg|jpeg|png|css|js)$ { expires 365d; } location ~ \.php$ { include /etc/nginx/fastcgi_params; } } |
测试一下: http://yuehei.37net.com/test_test.png 报的是404了