自从使用WP以来,为了迎合Search Bot的检索,通常都直接将固定链接从默认的“/?p=postid”改为“/%postname%”,也就是直接显示文章的名称。
个人觉得这样挺好,这样的链接形式比较直观。不过不确定之前的版本有没有类似这样的问题,就是当我的文章名为数字时(见上篇博文《2012》),固定链接即为“domain.com/2012”—-点击访问均跳到404页面~其他的文章没有问题,初步排错结论是纯数字的文章标题解析bug~
由于之前很少有全为数字标题的文章,所以也没发现类似的问题。为此再次翻阅官方说明:
%year%
The year of the post, four digits, for example 2004
%monthnum%
Month of the year, for example 05
%day%
Day of the month, for example 28
%hour%
Hour of the day, for example 15
%minute%
Minute of the hour, for example 43
%second%
Second of the minute, for example 33
%postname%
A sanitized version of the title of the post (post slug field on Edit Post/Page panel). So “This Is A Great Post!” becomes this-is-a-great-post in the URI (see Using only %postname%). Starting Permalinks with %postname% is strongly not recommended for performance reasons.. *** Note – this has been changed and is ok to do since ver. 2.0
%post_id%
The unique ID # of the post, for example 423
%category%
A sanitized version of the category name (category slug field on New/Edit Category panel). Nested sub-categories appear as nested directories in the URI. Starting Permalinks with %category% is strongly not recommended for performance reasons.
%tag%
A sanitized version of the tag name (tag slug field on New/Edit Tag panel). Starting Permalinks with %tag% is strongly not recommended for performance reasons.
%author%
A sanitized version of the author name.
可以看到官方其实不推荐单独使用%postname%,大概跟服务器mod-rewrite模块的限制有关,为了稳妥起见,官方还是推荐组合使用。比如:“/%category%/%postname%”
也有很多网友推荐其他的固定链接设定方案,常用的有:
1. /y/m/d/post-name/
写法:/%year%/%monthnum%/%day%/%postname%/
2. /y/m/d/post-name.html
写法:/%year%/%monthnum%/%day%/%postname%.html
3. /post-id.html
写法:/%post_id%.html
4. /post-name/
写法:/%postname%/
5. /post-name.html
写法:/%postname%.html
6. category/post-name.html
写法:/%category%/%postname%.html
7. category/post-id.html
写法:/%category%/%post_id%.html
个人推荐以下两种:
domainname.com/%postname%.html
or
domainname.com/%category%/%postname%.html
加上伪装的.html之后纯数字的文章名称也可以照常访问咯~
以上仅供有需要的朋友参考,如遇问题建议翻阅官方文档,恕本人不负责解答~thx~
Like this:
Be the first to like this post.