最近需要做一个站,根目录是thinkphp,二级的话是wordpress,wp需要伪静态,找了三中方法解决伪静态的问题。
首先,我当前根目录的伪静态规则是
location / {if (!-e $request_filename) {rewrite ^(.*)$ /index.php?s=$1 last;break;}}
wordpress存放在二级域名helps中,就需要将wordpress的伪静态规则修改后合并到一个规则中。
规则一:
location / {rewrite ^/目录名/wp-admin$ /目录名/wp-admin/ permanent; 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; }}
规则二:
location /目录名/{rewrite ^/wp-admin$ /wp-admin/ permanent; 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; }}
规则三:
location /目录名/ { try_files $uri $uri/ /目录名/index.php?q=$uri&$args; }
将规则中的 目录名改成你的二级域名目录名即可,我的改成helps就可以。
我用的是规则三,比较简便,合并后的规则是这样的
location / {if (!-e $request_filename) {rewrite ^(.*)$ /index.php?s=$1 last;break;}}location /helps/ { try_files $uri $uri/ /helps/index.php?q=$uri&$args; }