WordPress 偽靜態(tài)規(guī)則(IIS/Apache/Nginx)
安裝了總是詢問(wèn)WordPress 的客戶總是想知道 WordPress 如何添加偽靜態(tài)規(guī)則,今天我就與大家分享一下 IIS/Apache/Nginx 三種環(huán)境下的偽靜態(tài)規(guī)則,希望對(duì)大家有所幫助。
檢測(cè)主機(jī)是否支持偽靜態(tài)的方法:在WP后臺(tái) > 設(shè)置 > 固定鏈接,設(shè)置為 非默認(rèn)帶?的那種結(jié)構(gòu),然后訪問(wèn)任何一篇文章,如果出現(xiàn) 404 錯(cuò)誤,說(shuō)明你的主機(jī)當(dāng)前不支持 WordPress 偽靜態(tài)。

IIS偽靜態(tài)規(guī)則
IIS 環(huán)境是 Windows 主機(jī)常用的服務(wù)器環(huán)境,新建一個(gè) txt 文件,將下面的代碼添加到文件中:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 | [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] |
然后另存為 httpd.ini 文件,上傳到WordPress站點(diǎn)的根目錄即可。
Apache偽靜態(tài)規(guī)則
Apache是 Linux 主機(jī)下常見(jiàn)的環(huán)境,現(xiàn)在一般的 Linux 虛擬主機(jī)都采用這種環(huán)境。新建一個(gè) htaccess.txt 文件,添加下面的代碼:
1
2
3
4
5
6
7
8 | <IfModule mod_rewrite.c>RewriteEngine On
RewriteBase /RewriteRule ^index.php$ - [L]RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]</IfModule> |
然后上傳到 WordPress 站點(diǎn)的根目錄,重命名為 .htaccess 即可
Nginx偽靜態(tài)規(guī)則
Nginx環(huán)境一般是Linux 主機(jī) VPS或服務(wù)器用戶用的比較多,這些用戶一般都會(huì)自己配置Nginx,或者有專門的人幫你配置,打開(kāi) nginx.conf 或者某個(gè)站點(diǎn)?配置環(huán)境,比如 wpdaxue.com.conf(不同人配置的不一樣),在 server { } 大括號(hào)里面添加下面的代碼:
1
2
3
4
5
6
7
8
9
10
11 | location / {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 即可。
會(huì)員登錄
賬號(hào)登錄還沒(méi)有賬號(hào)?立即注冊(cè)