wordpress頁面的默認鏈接形式采用”樸素”方式 (例如: http://域名/?p=123)
這樣的動態URL鏈接不便于搜索引擎的收錄, 為此, 我們需設置為其他幾種常見的固定鏈接形式, 本網站 http://www.sufaith.com 選擇的是 【 自定義結構 】.
設置方式如下:
進入wordpress后臺系統首頁, 點擊菜單 【設置】- 【固定鏈接】
image
選擇【常用設置】 下的 【自定義結構】 , 可選擇單個標簽或多個標簽組合, 可自定義拼接字符串, 本站點使用的是 /%post_id%.html, 填寫完畢后, 點擊 【保存更改】即可生效.
image
保存更改后, 雖然文章或頁面的鏈接變成了固定鏈接, 但是在訪問頁面時, 卻變成了下載操作, 不能正常訪問該URL地址, 這時需要配置nginx的偽靜態(URL Rewrite)規則.
以下為nginx的配置, 需修改為你自己的域名和root路徑.
server {
listen 80;
server_name www.example.com;
root /usr/local/www/wordpress;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
修改完配置后, 重啟nginx即可生效, 恢復正常訪問.
systemctl restart nginx.service