問題緣由
因為 WordPress 默認的鏈接樣式不好看,且不美觀,沒有一個完好的目錄結構展示
解決思路
我們可以通過 WordPress 後台的設置-固定連接來進行設置,例圖:

除了默認外的其他設置均可以改變 WordPress 默認的鏈接結構,但是設置這一塊是需要我們的主機支持的;檢測主機是否支持的最好辦法就是,選擇一個除默認外的其他樣式,保存,然後隨便點擊一個文章看是否出現 404,如果出現,那麼很抱歉了,您的主機現在還不支持 WordPress 偽靜態!
到了這一步,我們就需要了解我們所使用的主機是什麼環境的了,這個問題,我們可以問空間服務商得到答案,通常是 IIS/Apache/Nginx 這三種環境,而下面將分別給出這三個環境的偽靜態規則!
IIS 偽靜態規則
IIS 環境是 Windows 主機常用的服務器環境,新建一個 txt 文件,將下面的代碼添加到文件中:
- [ISAPI_Rewrite]
- CacheClockRate 3600
- RepeatLimit 32
- 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]
- RewriteRule /wp-(.*) /wp-$1 [L]
- RewriteRule ^/$ /index.php [L]
- RewriteRule /(.*) /index.php/$1 [L]
然後另存為 httpd.ini 文件,上傳到 WordPress 站點的根目錄即可。
Apache 偽靜態規則
Apache 是 Linux 主機下常見的環境,現在一般的 Linux 虛擬主機都採用這種環境。新建一個 htaccess.txt 文件,添加下面的代碼:
- <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 站點的根目錄,重命名為 .htaccess 即可
Nginx 偽靜態規則
Nginx 環境一般是 Linux 主機 VPS 或服務器用户用的比較多,這些用户一般都會自己配置 Nginx,或者有專門的人幫你配置,打開 nginx.conf 或者某個站點的配置環境,比如 2zzt.com.conf(不同人配置的不一樣),在 server { } 大括號裏面添加下面的代碼:
- 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 即可。
當然,小 2 建議大家使用 WordPress 來搭建網站的時候還是選擇 linux 的空間比較好,因為 linux 下的 Apache 和 Nginx 環境還比 win 下的 IIS 運行 php 程序的效率要高的多!