WordPress博客的永久链接Permalink有许多种格式,个人认为最好的格式是/%post_id%,无他,惟短尔。
在WordPress设置中把永久链接更改为/%post_id%后,建议一短到底,以example.com的域名形式作为博客地址,同时把www.example.com通过301重定向永久跳转到example.com,即在.htaccess中加入:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
如果是中途变更永久链接形式为/%post_id%,例如从/archives/%post_id%变更为/%post_id%,还需要将诸如example.com/archives/123这样形式的外链,通过301重定向永久跳转到example.com/123,以保证别人通过外链或搜索引擎访问时不出现404页面,即在.htaccess中加入:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^archives/(.+)$ http://example.com/$1 [R=301,L]
类似地,从example.com/?p=123跳转到example.com/123的.htaccess写法是:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^?p= (.+)$ http://example.com/$1 [R=301,L]
使用example.com作为域名后,如果追求完美,还可以将WordPress数据库wp_posts表中的永久链接字段guid中的www.example.com更新为example.com,即执行SQL语句:
UPDATE wp_posts SET guid = REPLACE ( guid, “www. example.com”, “example.com” )
另外,个人觉得博客没必要使用伪静态地址,在链接后加上.html纯属画蛇添足。
“更改WordPress永久链接设置”上的5条回复
受益良多!又学习了一种新的表达
很好,我是新手,所以不知道怎么设置呀!麻烦老师说下
其实这个在Wordpress后台就有设置的……
这样真更简洁了
最近也在研究网站的优化,头疼的很…