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 偽靜態規則。