WordPress 是目前最流行的 Blog CMS, 原本每个网址后面会加上 “?p=xxx” 作为识别文章, 而 WordPress 的固定连结功能可以自订网址。Wordpress 内建的 .htaccess 档案已经做好 Rewrite 的设定, 但如果网页服务器是用 Nginx, 就不可以用这个 .htaccess 了, 以下是在 Nginx 设定 WordPress Rewrite 固定连结的方法。
首先开启网站的 .conf 档案, 例如网站是 phpini.com, 设定档是 /etc/nginx/site-enabled/phpini.com.conf:
# vi /etc/nginx/site-enabled/phpini.com.conf
在 “server” 段落下的 “location” 段落, 加入以下一行:
|
1 2 3 |
location / { try_files $uri $uri/ /index.php?$args; } |
如果 WordPress 安装在 sub-directory, 例如 “blog”, 需要改成这样:
|
1 2 3 |
location /blog/ { try_files $uri $uri/ /blog/index.php?$args; } |
储存盘案后离开文字编辑器, 重新启动或重新加载 Nginx:
# systemctl reload nginx