作者:btsk@163.com | 来源:互联网 | 2024-11-06 13:48
本文探讨了Nginx在处理静态和动态URL时的配置与优化技巧。通过示例展示了如何将复杂的动态URL重写为简洁的静态URL,如将`http://test.dev/televisionSearch?searchword=20&a`转换为`http://test.dev/search_sw_20_p_1.html`。此外,还介绍了如何利用Nginx的重写规则和缓存机制,提高网站性能和用户体验。
静态地址http://test.dev/search_sw_20_p_1.html
动态地址http://test.dev/television/Search?searchword=20&page=1
1、location / {
index index.php;
rewrite ^/search_sw_([^_]*)(_p_)?(\d*).html /index.php?/television/search&searchword=$1&page=$3 last;
}
2、set $real_request_uri $request_uri;
if ($request_uri ~ ^/search_sw_([^_]*)(_p_)?(\d*).html) {
set $real_request_uri /television/search?searchword=$1&page=$3;
}
3、location ~ \.php$ {
fastcgi_param REQUEST_URI $real_request_uri;
include fastcgi_params;
}
4、vi fastcgi_params;
# fastcgi_param REQUEST_URI $request_uri;