「WordPress」- 美化 URL 地址

问题描述

该笔记将记录:在 WordPress 中,与 URL 地址处理有关的设置,及相关问题处理。

解决方案

设置 url 格式

如果需要对 URL 美化,需要在 Settings / Permalinks 中进行配置。

默认的格式是:http://example.com/?p=123

我们使用格式:http://example.com/%category%/%postname%.html

但是这需要进行 URL 重写,否则只会返回 404 页面。因为使用 Nginx 服务:

location / {
	try_files $uri $uri/ /index.php?$args;
}

然后重启 Nginx 服务。

处理 404 页面

我们使用 Redirection 来对 404 页面进行重定向。

也能够使用 URL rewriting 对页面进行重写,但是这需要编程:
1)URL Rewriting: How To Rewrite URLs In WordPress – Regur Technology Solutions
2)Rewriting URLs in WordPress: Tips and Plugins – Hongkiat

参考文献

Using Permalinks
zh-cn:使用固定链接