【发布时间】:2014-07-29 00:08:48
【问题描述】:
我有一个在 nginx 上运行的具有以下 url 结构的站点
http://example.com/category.php?page=1&query=latest
现在我的目标是使用 nginx rewrite 将其转换为下面的一个
其中 1 是页码并且是动态的
获得干净 url 的确切规则是什么,
除此之外,我还需要一个规则,以防有人为页面提供负值,它将自动重定向到页码的正值。
现在我现有的配置如下
server {
server_name example.com;
error_log /data1/nginx/aggri.com.error.log;
root /data1/aggri;
index index.php;
rewrite_log on;
location ~ .php$ {
try_files $uri $uri/ /index.php;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
expires 0;
add_header Cache-Control public;
set $skip_cache 0;
if ($request_uri ~* "^(.*/)index\.php$") {
return 301 $1;
} }
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|js|woff|css)$ {
access_log off; log_not_found off; expires max;
}
location = /robots.txt { access_log off; log_not_found off; }
location ~ /\. { deny all; access_log off; log_not_found off; }
}
【问题讨论】: