有點基礎的人都知道靜態URL有助于SEO,能夠讓搜索引擎更好的收錄,并且現在好多主題的功能都是需要實現偽靜態才能夠使用的,相信大部分的人都是知道偽靜態的重要性,WordPress要想實現偽靜態也是非常簡單的,但我發現還是有很多新人朋友都設置不好,下面小新就給大家講解一下:
固定鏈接其實就是修改 WordPress 目錄、頁面或者帖子的URL鏈接形式。固定鏈接不僅可以優化鏈接、保持鏈接的美觀性使用戶得到更好的體驗,還可以更好的SEO優化,修改后的靜態地址更容易讓搜索引擎接受從而達到更好的排名。要想設置固定鏈接成功的話必須先添加偽靜態規則。
IIS偽靜態規則
新建一個txt文件,然后把下面的代碼復制粘貼進去另存為 httpd.ini 文件,上傳到網站根目錄.
- [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] --Vevb.com
- # For normal wordpress content, via index.php
- RewriteRule ^/$ /index.php [L]
- RewriteRule /(.*) /index.php/$1 [L]
Apache偽靜態規則
新建一個 htaccess.txt 文件,把下面代碼復制粘貼進去保存后上傳到網站根目錄,重命名為 .htaccess.
- RewriteEngine On
- RewriteBase /
- RewriteRule ^index/.php$ - [L]
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteRule . /index.php [L]
Nginx偽靜態規則
打開 nginx.conf 或者某個站點的配置環境,不同人配置的不一樣,在 server { } 大括號里面添加下面的代碼后保存,重啟 Nginx就行了.
- 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;
- }
- }
一般的情況下大多數都是使用IIS+Apache,小新博客就是使用IIS和Apache實現偽靜態的!Now!規則寫好之后就可以固定鏈接了,固定鏈接之前先了解一下官方的一些結構參數:
- %year%:發布文章的年份,比如2010;
- %monthnum%:發布文章的月份,比如01;
- %y%:發布文章當日,比如06;
- %hour%:發布文章小時數,比如23;
- %minute%:發布文章分鐘數,比如43;
- %second%:發布文章秒數,比如33;
- %postname%:文章的postname,文章的別名;
- %post_id%:文章的post_id,比如48;
- %tegory%:文章的分類;
- %author%:文章作者名。
固定鏈接時應該注意什么呢?
1、不要讓日期出現在固定鏈接里面
2、不要讓分類的鏈接出現在固定鏈接里面
3、鏈接不要太深
4、鏈接中不要出現中文
網上常見的鏈接格式:
- /%year%/%monthnum%/%y%/%postname%/
- /%year%/%monthnum%/%postname%/
- /%year%/%monthnum%/%y%/%postname%.html
- /%year%/%monthnum%/%postname%.html
- /%tegory%/%postname%.html
- /%post_id%.html
- /%postname%/
固定鏈接設置:
wordpress后臺<設置<固定鏈接.
小新用的是/%post_id%.html我覺得簡潔美觀,用戶體驗起來效果更好,推薦使用.
新聞熱點
疑難解答
圖片精選