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