WordPress開啟偽靜態(tài)教程
時間:2023-06-29 14:57:01 | 來源:網站運營
時間:2023-06-29 14:57:01 來源:網站運營
WordPress開啟偽靜態(tài)教程:偽靜態(tài)的好處是利于SEO,容易被搜索引擎收錄
首先打開wp的后臺。找到設置–固定鏈接–選擇自定義結構
在后面填寫,并保存
/%post_id%.html
然后就是編寫偽靜態(tài)規(guī)則了
IIS偽靜態(tài)規(guī)則
IIS 環(huán)境是 Windows 主機常用的服務器環(huán)境,新建一個 txt 文件,將下面的代碼添加到文件中:
[ISAPI_Rewrite]# Defend your computer from some worm attacks#RewriteRule .*(?:global.asa|default/.ida|root/.exe|/./.).* . [F,I,O]# 3600 = 1 hour
CacheClockRate 3600RepeatLimit 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=$1RewriteRule /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.phpRewriteRule ^/$ /index.php [L]RewriteRule /(.*) /index.php/$1 [L]然后另存為 httpd.ini 文件,上傳到WordPress站點的根目錄即可。
Apache偽靜態(tài)規(guī)則
Apache是 Linux 主機下常見的環(huán)境,現(xiàn)在一般的 Linux 虛擬主機都采用這種環(huán)境。新建一個 htaccess.txt 文件,添加下面的代碼:
然后上傳到 WordPress 站點的根目錄,重命名為 .htaccess 即可
Nginx偽靜態(tài)規(guī)則
Nginx環(huán)境一般是Linux 主機 VPS或服務器用戶用的比較多,這些用戶一般都會自己配置Nginx,或者有專門的人幫你配置,打開 nginx.conf 或者某個站點的配置環(huán)境,比如 wpdaxue.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 即可。