我們都知道WordPress程序很強(qiáng)大,對(duì)搜索引擎優(yōu)化很友好,但是有一點(diǎn)可能有些人還不是很清楚,對(duì)于WordPress這樣一款開源程序來 說,它本身就是在Linux/Apache平臺(tái)中開發(fā),先天上與其結(jié)合得比較緊密,因此,如果可能的話,選擇Linux/Apache平臺(tái)應(yīng)該是第一選 擇。盡管WordPress可以在Windows/iis平臺(tái)中安裝使用,但存大許多不足,其實(shí)中致命的一點(diǎn)便是IIS本身不支持Mod_Rewrite 功能,而這將會(huì)給博客的維護(hù)、管理、SEO優(yōu)化帶來很多麻煩。
由于IIS不支持Mod_Rewrite,因此,Wordpress便無法實(shí)現(xiàn)標(biāo)準(zhǔn)的、簡(jiǎn)潔的Permalinks,而只能采取在Url中包含“index.php“的替代方案(如SEO探索的權(quán)益之計(jì)中所探討的那樣);所以無法實(shí)現(xiàn)真正的偽靜態(tài)功能。
經(jīng)過幾天的努力找答案終于搞定了Wordpress在win/IIS下偽靜態(tài)的功能,雖然網(wǎng)上有利用404.php頁面來實(shí)現(xiàn)的方法,但終歸沒有這種自然的好。今天就給大家分享一下,首先你的主機(jī)要裝Rewrite組件,現(xiàn)在國(guó)內(nèi)很多WINDOWS主機(jī)都有裝這個(gè)了,如果沒有可以聯(lián)系主機(jī)空間商。然后在httpd.ini 中加入如下代碼:
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
#解決中文tag無法訪問的問題
RewriteRule /tag/[^/]+)/([^/]+)/?([0-9]+)?/ /index.php?tag=$1&paged=$3 [L]
# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
# Rules to ensure that normal content gets through
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]
但是修改之后中文tag又不能訪問了,別擔(dān)心,接著看下一步。
修改wp-include中的classes-wp.php,之前版本可能是classes.php。
原代碼:
$pathinfo = $_SERVER['PATH_INFO'];
替換為:
$pathinfo = mb_convert_encoding($_SERVER['PATH_INFO'], "UTF-8", "GBK");
原代碼:
$req_uri = $_SERVER['REQUEST_URI'];
替換為:
$req_uri = mb_convert_encoding($_SERVER['REQUEST_URI'], "UTF-8", "GBK");
修改后,保存下,然后將保存后的文件上傳并覆蓋原文件即可,這里需要注意文件保存格式。
然后在固定鏈接中設(shè)置為自己想要的就可以了。
附:常用WordPress固定鏈接格式
1)/%postname%/
2)/%year%/%monthnum%/%postname%/
3)/post/%post_id%.html
4)/%year%/%monthnum%/%day%/%postname%/
5)/%year%/%monthnum%/%day%/%postname%.html