我們使用 WordPress 建站時,一般都是在 IIS/Apache/Nginx 這三種環境下搭建的,若你不知道自己 WordPress 所在的環境是什麼,那麼請去詢問客服。
WordPress 偽靜態之一:Nginx 偽靜態規則
在 linux 系統中,Nginx 環境使用的人很多,如今市面上的 linux 主機 VPS 或伺服器使用者都在用這個,這些人一般都會自己配置配置 Nginx,或者有專門的人幫你配置,你只需要開啟 nginx.conf 或者對應站點的配置檔案,如 junzibuqi.com.conf(請根據你自己的來),在 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 就可以使得你 WordPress 偽靜態規則生效了。
WordPress 偽靜態之一:Apache 偽靜態
比起 Nginx 的偽靜態,設定 Apache 的偽靜態規則更簡單,你只需要新建一個 htaccess.txt 檔案,新增下面的程式碼:
- RewriteEngineOn
- RewriteBase/
- RewriteRule^index.php$ -[L]
- RewriteCond%{REQUEST_FILENAME}!-f
- RewriteCond%{REQUEST_FILENAME}!-d
- RewriteRule./index.php [L]
儲存之後,就將 htaccess.txt 檔案上傳到你 WordPress 網站的根目錄,重新命名為 .htaccess 即可生效。
WordPress 偽靜態之一:IIS 偽靜態規則
IIS 環境是 Windows 主機常用的伺服器環境,直接新建一個 txt 檔案,將下面的程式碼新增到檔案中:
- [ISAPI_Rewrite]
- # Defend your computer from some worm attacks
- #RewriteRule .*(?:global.asa|default.ida|root.exe|..).* . [F,I,O]
- # 3600 = 1 hour
- CacheClockRate3600
- RepeatLimit32
- # 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 站點的根目錄即可生效。