WordPress 作为世界上最流行的免费建站系统,在 seo 方面也设计的很合理。 WordPress 默认的链接是动态的形式,虽然这点对于现在的搜索引擎爬虫抓取内容已经不会再构成影响了,但是伪静态的链接更具有层级结构关系,更有利于蜘蛛抓取。下面小编就说说各个 web 系统下 WordPress 的伪静态规则。
apache 环境下的 WordPress 伪静态规则:
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
新建一个.htaccess 文件并将以上代码写入.htaccess 文件中,上传至 WordPress 站点的根目录中。
IIS 环境下的 WordPress 伪静态规则 (方法一):
打开站点根目录下的 web.config 文件并加入以下代码:
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="" />
</rule>
</rules>
</rewrite>
IIS 环境下的 WordPress 伪静态规则 (方法二):
新建一个 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 ^/$ /index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /(.*) /index.php/$1 [L]
上传至 WordPress 站点根目录。
nginx 环境下的 WordPress 伪静态方法:
location / {
index index.html index.php;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
将以上代码加入到 nginx.conf 文件的 Server 段内。以上就是所有 web 环境下的 WordPress 伪静态规则。