1. 程式人生 > >建站初學者必知的wordpress在Nginx/Apache/IIS中的偽靜態規則

建站初學者必知的wordpress在Nginx/Apache/IIS中的偽靜態規則

.html SM max-width ext 定義 ima UC rule margin

在搭建好wordpress博客以後,我都是先讓大家配置好文章的url格式為/%postname%.html這樣的自定義結構的。比如是阿裏雲的虛擬主機這樣配置以後,文章頁面還是可以打開的,但是有的服務器或者是虛擬主機就打不開了,這就需要大家配置好偽靜態的規則。

現在,我就把怎麽配置wordpress的偽靜態規則發出來給大家一起來學習。

技術分享圖片

wordpress的Nginx/Apache/IIS偽靜態規則

NGINX偽靜態規則

Nginx環境是Linux服務器裏面常見的網站配置環境,完整網站環境是Linux+Nginx+Mysql+PHP簡稱LNMP環境,他的WordPress偽靜態規則是:

  1. location / {

  2. try_files $uri

    $uri/ /index.php?$args;

  3. }


  4. # Add trailing slash to */wp-admin requests.

  5. rewrite /wp-admin$ $scheme://$host$uri/ permanent;

把上面的文件放置在當前網站的配置裏面,打開 nginx.conf 或者某個獨立站點的配置環境,比如 yangzeye.net.conf(不同人配置的不一樣),而我現在的是寶塔管理面板,只要在網站設置裏面的偽靜態裏面復制上面代碼保存即可。

Apache偽靜態規則

Apache環境也是Linux服務器裏面常見的網站配置環境,完整網站環境是Linux+Apache+Mysql+PHP簡稱LAMP環境,他的WordPress偽靜態規則是:

  1. <IfModule mod_rewrite.c>

  2. RewriteEngine On

  3. RewriteBase /

  4. RewriteRule ^index\.php$ - [L]

  5. RewriteCond %{REQUEST_FILENAME} !-f

  6. RewriteCond %{REQUEST_FILENAME} !-d

  7. RewriteRule . /index.php [L]

  8. </IfModule>

打開網站根目錄下面的.htaccess文件,把上面的代碼復制進去,加入沒有這個文件的話,新建一個txt文本文檔,重命名為.htaccess即可。

IIS的偽靜態規則

IIS服務器是Windows系統自帶的網站服務環境,打開網站根目錄的httpd.ini把代碼配置進去即可,沒有這個文件的新建這個文件。

  1. [ISAPI_Rewrite]

  2. # Defend your computer from some worm attacks

  3. #RewriteRule .*(?:global.asa|default\.ida|root\.exe|\.\.).* . [F,I,O]

  4. # 3600 = 1 hour


  5. CacheClockRate 3600

  6. RepeatLimit 32


  7. # Protect httpd.ini and httpd.parse.errors files

  8. # from accessing through HTTP

  9. # Rules to ensure that normal content gets through


  10. RewriteRule /tag/(.*) /index\.php\?tag=$1

  11. RewriteRule /software-files/(.*) /software-files/$1 [L]

  12. RewriteRule /images/(.*) /images/$1 [L]

  13. RewriteRule /sitemap.xml /sitemap.xml [L]

  14. RewriteRule /favicon.ico /favicon.ico [L]

  15. # For file-based wordpress content (i.e. theme), admin, etc.

  16. RewriteRule /wp-(.*) /wp-$1 [L]

  17. # For normal wordpress content, via index.php

  18. RewriteRule ^/$ /index.php [L]

  19. RewriteRule /(.*) /index.php/$1 [L]

好了,今天的wordpress的Nginx/Apache/IIS偽靜態規則就講完了,如果還有疑問的可以在下面留言哦!

歡迎大家關註楊澤業的澤業建站網,一起來學習實用的建站知識,讓我們的網站能夠更好的幫助我們服務這個世界。

來源:澤業建站網

本文由楊澤業原創,發布於51CTO博客


建站初學者必知的wordpress在Nginx/Apache/IIS中的偽靜態規則