nginx & wordpress configure rewrite
nginx & wordpress 配置重写来做伪静态,每个域名单独放到一个server文件中,在nginx.conf中包含进去,这样有利于配置管理.
me@localhost /# cat /webserver/nginx/vhost/lastme.conf
1.在需要配置伪静态的server配置文件中,配置如下,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
server { listen 80; server_name www.lastme.com; #your domain charset utf-8; #access_log logs/host.access.log main; location / { root /webserver/wwwroot/; #webroot index index.html index.php; if (-f $request_filename/index.html){ rewrite (.*) $1/index.html break; } if (-f $request_filename/index.php){ rewrite (.*) $1/index.php; } if (!-f $request_filename){ rewrite (.*) /index.php; } } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /webserver/wwwroot/$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; } } server { server_name lastme.com; #301 Redirect rewrite ^/(.*) http://www.lastme.com/$1 permanent; } |
3.配置说明,来自wordpress官网
首先我们看看wordpress官方列出的部分可以使用的固定链接基本参数:
%year% 基于文章发布年份,比如2009;
%monthnum% 基于文章发布月份,比如12;
%day% 基于文章发布当日,比如28;
%hour% 基于文章发布小时数,比如15;
%minute% 基于文章发布分钟数,比如43;
%second% 基于文章发布秒数,比如33;
%postname% 基于文章的postname,其值为撰写时指定的缩略名,不指定缩略名时是文章标题;
%post_id% 基于文章post_id,比如888;
%category% 基于文章分类,子分类会处理成”分类/子分类”这种形式;
%author% 基于文章作者名,如libertyspy.
将上述参数进行组合,即可得到wordpress的固定链接形式。常见的几种:
1./%year%/%monthnum%/%day%/%postname%/
2./%year%/%monthnum%/%postname%/
3./%year%/%monthnum%/%day%/%postname%.html
4./%year%/%monthnum%/%postname%.html
5./%category%/%postname%.html
6./%post_id%.html
No Comments