WordPress偽靜態規則設置


偽靜態:即網站本身是動態網頁如.php、.asp、.aspx等格式,而這類網頁還帶“?”加參數來讀取數據庫。開啟偽靜態后,動態網頁即被轉換重寫成靜態網頁類型頁面。

WordPress和其它網站系統不一樣,其它網站系統基本都帶有生成靜態頁面功能。但Wp只能使用偽靜態。

現在的主機基本都會支持偽靜態功能,只需在空間后台偽靜態功能,選擇網站系統,空間就會支持該系統的偽靜態。

如何判讀空間是否支持偽靜態。在網站后台:設置-固定鏈接,選擇第一個除外,看網站其它頁面是否出現404,如果是,則空間不支持偽靜態。

只要空間支持偽靜態重寫URL Rewrite功能,根據服務器主機空間環境,只需加入下列偽靜態規則即可。

Apache偽靜態規則

新建一個 txt 文件,將下面的代碼添加到文件中,然后另存為.htaccess文件,上傳到WordPress站點的根目錄即可。

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

</IfModule>

Nginx規則

在Nginx中的server模塊配置如下內容,打開 nginx.conf 或者某個站點的配置環境,例如 /usr/local/nginx/conf/yzipi.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){

IIS偽靜態規則rewrite (.*) /index.php;

}

}

IIS偽靜態規則

新建一個 txt 文件,將下面的代碼添加到文件中,然后另存為 httpd.ini 文件,上傳到WordPress站點的根目錄即可。

[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]

參考鏈接


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM