建站代码网

热门标签

WordPress固定链接伪静态化设置

在默认情况下,刚安装的WordPress的所有网页,都带“问号”的动态链接,这就有必要修改固定链接伪静态化,伪静态化后更容易被各大搜索引擎收录、增加权重,另外,拼音或英文的后缀还能增强网站访问体验。

自从Google淡出中国市场,百度成为一家独大,无数的网站基本都是靠百度吃饭的。国内的各大搜索引擎都声明可以正常收录动态链接,但是由于互联网最原始的网页设计都是html、htm,切搜索引擎本身的站点都是静态页面,所以种种原因使得众多站长把网站静态化。

WordPress由于是PHP系统,所以不能完美静态化,只可以实现伪静态化,并且只针对文章,其它页面、存档、日期的页面不可以伪静态化。

修改步骤:登录网站后台→设置→固定链接→自定义结构,输入各种展示代码,可以显示不同的链接。

固定链接

WordPress链接的展现方式

一、链接形式参数

先了解固定链接形式的组成,这些代码可以单独使用,也可以结合使用,直接复制小括号前的代码到自定义固定链接中保存即可。

%year% (年份,四位数字)
%monthnum% (月份)
%day% (当日)
%hour% (小时)
%minute% (分钟)
%second% (秒)
%postname% (页面别名)
%post_id% (序列数字)
%category% (分类别名)
%author% (作者名)

二、html与htm链接形式

相对来说,百度更喜欢html、htm后缀的页面。现在IP过万的WordPress博客都使用了htm后缀的伪静态化,百度、Google权重都到了7,可见修改固定链接是很有必要的。

/%category%/%postname%.html (分类/日志名.html)
/%category%/%postname%.htm(分类/日志名.htm)
/%postname%.html(/日志名.html)
/%postname%.htm(/日志名.htm)
/%post_id%.html(/日志id号.html)
/%post_id%.htm(/日志id号.htm)

三、文件名链接形式

Google喜欢/%postname%/的页面,外汇站就是使用的/%postname%/固定链接,/%postname%/在英文博客中非常多见,如果你建设的是一个英文博客,或含有英文文章的博客,这种固定链接方式是最利于优化和外国人访问的,别名要用英文单词来诠释,像加拿大华人johnchow(周嘉良)的英文博客月收入超过10万美金。

/%year%/%monthnum%/%day%/%postname%/(年/月/日/日志名)
/%year%/%monthnum%/%postname%/(年/月/日志名)
/%monthnum%/%day%/%postname%/(月/日/日志名)
/%year%/%monthnum%/%day%/%post_id%/(年/月/日/日志id号)
/%year%/%monthnum%/%post_id%/(年/月/日志id号)
/%monthnum%/%day%/%post_id%/(月/日/日志id号)
/archives/%post_id%(/archives/日志id号)
/archives/%postname%(/archives/日志名)
/%post_id%(日志id号)
/%postname%(日志名)

WordPress伪静态文件添加方法

一、Linux主机

请确保你的根目录开启了777权限,已开启的话,在修改自定义固定链接后的瞬间,会在主机根目录自动生成一个.htaccess的文件。

如果不会或无法修改主机权限,那就需要手动创建一个文件,.htaccess,粘贴保存以下代码,把.htaccess文件上传到网站根目录就行了,

二、Windows主机伪静态

你使用的windows主机必须安装了装Rewrite 组件才能支持伪静态,咨询下你的主机商所使用的主机是否支持伪静态,支持的话请继续往下看。

1、先设置404.php,

<?php
$qs = $_SERVER['QUERY_STRING'];
$_SERVER['REQUEST_URI'] = substr($qs, strpos($qs, ':80')+3);
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'];
include('index.php');
?>

2、上传httpd.ini规则至根目录,有两种伪静态规则,请挨个尝试哪个管用。

httpd.ini

[ISAPI_Rewrite]
# Defend your computer from some worm attacks
#RewriteRule .*(?:global.asa|default.ida|root.exe|..).* . [F,I,O]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
# Rules to ensure that normal content gets through
RewriteRule /tag/(.*) /index.php?tag=$1
RewriteRule /software-files/(.*) /software-files/$1 [L]
RewriteRule /images/(.*) /images/$1 [L]
RewriteRule /sitemap.xml /sitemap.xml [L]
RewriteRule /favicon.ico /favicon.ico [L]
# For file-based wordpress content (i.e. theme), admin, etc.
RewriteRule /wp-(.*) /wp-$1 [L]
# For normal wordpress content, via index.php
RewriteRule ^/$ /index.php [L]
RewriteRule /(.*) /index.php/$1 [L]

3

[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
# wordpress 伪静态规则
# For tag(中文标签以及标签翻页的规则)
RewriteRule /tag/(.*)/page/(d+)$ /index.php?tag=$1&paged=$2
RewriteRule /tag/(.+)$ /index.php?tag=$1
# For category(中文分类以及分类翻页的规则)
RewriteRule /category/(.*)/page/(d+)$ /index.php?category_name=$1&paged=$2
RewriteRule /category/(.*) /index.php?category_name=$1
# For sitemapxml
RewriteRule /sitemap.xml /sitemap.xml [L]
RewriteRule /sitemap.html /sitemap.html [L]
RewriteRule /sitemap_baidu.xml /sitemap_baidu.xml [L]
RewriteRule /favicon.ico /favicon.ico [L]
# For file-based wordpress content (i.e. theme), admin, etc.
RewriteRule /wp-(.*) /wp-$1 [L]
# For normal wordpress content, via index.php
RewriteRule ^/$ /index.php [L]
RewriteRule /(.*) /index.php/$1 [L]

3、VPS主机

PS:如果你不知道所使用的主机是什么系统,请咨询主机商。

X