wordpress固定連結

固定連結(Permalink)是部落格日誌、分類及其他部落格內容列表的永久URL。

基本介紹

  • 中文名:wordpress固定連結
  • 使用:固定連結連結到你的文章上
  • 應為:永久性、固定不變的
  • 類型:默認形式(不美觀的)
定義,類型,設定方法,結構,404錯誤,常見問題,解決方案,

定義

其他部落格主人可以使用固定連結連結到你的文章上,你也可以在email中傳送某篇日誌的連結。所有日誌的URL應為永久性、固定不變的-這就是所謂的固定連結。

類型

默認形式(不美觀的)
如:http:// example .com/?p=N 這裡的N是Post ID號。它能夠在所有伺服器環境下使用,但這種形式的URL看起來不是很好看。
mod_rewrite類型(美觀的) 這些固定連結樣式可謂淺顯易懂、賞心悅目。雖然這種連結的格式多種多樣,但最常見的形式還是
category/post-name/或 /year/month/day/post-name。這種類型的 某些用戶移除了日期元素(日,月,年)以使得永久連結格式變得更精簡。
固定連結可在以下環境中工作:
具有mod_rewrite模組的Apache網路伺服器 Microsoft IIS7 + 帶有URL Rewrite 1.1的網路伺服器 + 作為FastCGI運行的模組與PHP5 使用404處理程式或 mod_rewrite 或 mod_magnet 的LighttpdPATHINFO(完美的) PATHINFO 固定連結形式跟mod_rewrite 固定連結形式很相像,只有一點不同:前者插入了 /index.php ,如下:
/index.php/yyyy/mm/dd/post-name/ 除此之外,PATHINFO就跟mod_rewrite 固定連結一樣完美了,其靈活性也很相似。mod_rewrite 固定連結所能達到的效果,PATHINFO 固定連結通過/index.php部分也能做到。

設定方法

進入wp後台->設定裡面的固定連結->自定義結構

結構

這裡有幾個結構可以作為參考
%year% 日誌發表的年份,四位數字
%monthnum% 日誌發表的月份
%day% 日誌發表的日期
%hour% 日誌發表的時間-小時
%minute% 日誌發表的時間-分鐘
%second% 日誌發表的時間-秒
%postname%日誌標題的縮略版本(日誌/頁面編輯界面上的日誌別名)。因此“This Is A Great Post!”在URI中會變成this-is-a-great-post。
%post_id%日誌的唯一ID,如123
%category%分類名稱的縮略版本(添加新分類/編輯界面上的分類別名)。嵌套的子分類會作為嵌套子目錄出現在URI中。出於運行方面的考慮,不推薦以%category%作為固定連結的起始部分。
%tag%標籤名稱的縮略版本(添加新標籤/編輯界面上的標籤別名)。出於運行方面的考慮,不推薦以%tag%作為固定連結的起始部分。
%author%作者名稱的縮略版本.
既然知道了我們就可以對這些開始組合了。
幾種組合方式如下
/?p=%post_id%(默認的)
/%year%/%monthnum%/%day%/%postname%/(年/月/日/日誌名)
/%year%/%monthnum%/%postname%/(年/月/日誌名)
/%monthnum%/%day%/%postname%/(月/日/日誌名)
/%year%/%monthnum%/%day%/%post_id%/(年/月/日/日誌id號)
/%year%/%monthnum%/%post_id%/(年/月/日誌id號)
/%monthnum%/%day%/%post_id%/(月/日/日誌id號)
/archives/%post_id%(/archives/日誌id號)
/archives/%postname%(/archives/日誌名)
/%post_id%(/日誌id號)
/%postname%(/日誌名)
/%category%/%postname%.html (分類/日誌名.html)
/%category%/%postname%.htm(分類/日誌名.htm)
/%postname%.html(/日誌名.html)
/%postname%.htm(/日誌名.htm)
/%post_id%.html(/日誌id號.html)
/%post_id%.htm(/日誌id號.htm)
常用的就是以htm後者html方式結尾的。當然這個可以隨你的喜好自由改變。
win主機IIS 6 WordPress固定連線的設定
一般使用wordpress都會將設定固定連結(偽靜態),這樣更有利於seo,wordpress在LINUX系統的伺服器中可以很好的使用,在Windows主機,為了完美支持偽靜態就需要下點功夫。
空間需要支持rewrite組件,現在幾乎所有WIN主機都支持Rewrite 組件,有個問題就是,部落格連結能偽靜態,可中文標籤的連結打不開,比如我們設定的中文目錄中文tag,就打不開了。解決WordPress部落格偽靜態中文標籤無法打開可以使用下面的規則:
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
RewriteRule /tag/(.*) /index\.php\?tag=$1
# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
# Rules to ensure that normal content gets through
RewriteRule /robots.txt /robots.txt [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]
在使用上有什麼不清楚請查看下面的參考資料,有詳細的設定教程
WIN主機二級目錄裝WordPress固定連結設定
很多朋友主站並不想放部落格,有的朋友喜歡美觀想放一個主頁什麼的,有的是公司的網站,或者有的朋友想做淘寶客,那么這樣只能把WordPress放到二級目錄(子目錄)裡面了,wordpress在二級目錄的偽靜態規則規則:
[ISAPI_Rewrite]
# 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 /blog/sitemap.xml /blog/sitemap.xml [L]
RewriteRule /blog/favicon.ico /blog/favicon.ico [L]
# For tag
RewriteRule /blog/tag/(.*)/page/(\d+)$ /blog/index\.php\?tag=$1&paged=$2
RewriteRule /blog/tag/(.+)$ /blog/index\.php\?tag=$1
# For category
RewriteRule /blog/category/(.*)/page/(\d+)$ /blog/index\.php\?category_name=$1&paged=$2
RewriteRule /blog/category/(.*) /blog/index\.php\?category_name=$1
# For file-based wordpress content (i.e. theme), admin, etc.
RewriteRule /blog/wp-(.*) /blog/wp-$1 [L]
# For normal wordpress content, via index.php
RewriteRule ^/blog/$ /blog/index.php [L]
RewriteRule /blog/(.*) /blog/index.php/$1 [L]
#For page
RewriteRule /blog/page/(.*)/?s=(.*) /blog/index\.php\?s=$2&paged=$1
RewriteRule /blog/page/(.*) /blog/index\.php\?paged=$1
如果在規則使用上有什麼不明白的地方請查看下面的參考資料詳細教程
win主機安裝兩個wordpress固定連結設定
如果根目錄和子目錄同時裝wordpress程式,該怎么實現偽靜態?
固定連結設定規則:
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
# For sub
RewriteRule /wordpress/sitemap.xml /wordpress/sitemap.xml [L]
RewriteRule /wordpress/favicon.ico /wordpress/favicon.ico [L]
RewriteRule /wordpress/tag/(.*)/page/(\d+)$ /wordpress/index\.php\?tag=$1&paged=$2
RewriteRule /wordpress/tag/(.+)$ /wordpress/index\.php\?tag=$1
RewriteRule /wordpress/category/(.*)/page/(\d+)$ /wordpress/index\.php\?category_name=$1&paged=$2
RewriteRule /wordpress/category/(.*) /wordpress/index\.php\?category_name=$1
RewriteRule /wordpress/wp-(.*) /wordpress/wp-$1 [L]
RewriteRule ^/wordpress/$ /wordpress/index.php [L]
RewriteRule /wordpress/(.*) /wordpress/index.php/$1 [L]
RewriteRule /wordpress/page/(.*)/?s=(.*) /wordpress/index\.php\?s=$2&paged=$1
RewriteRule /wordpress/page/(.*) /wordpress/index\.php\?paged=$1
# For root
RewriteRule /tag/(.*) /index\.php\?tag=$1
RewriteRule /robots.txt /robots.txt [L]
RewriteRule /sitemap.xml /sitemap.xml [L]
RewriteRule /favicon.ico /favicon.ico [L]
RewriteRule /wp-(.*) /wp-$1 [L]
RewriteRule /wordpress/(.*) /wordpress/$1 [L]
RewriteRule ^/$ /index.php [L]
RewriteRule /(.*) /index.php/$1 [L]
關於規則使用設定,詳細圖文教程請查看下面的參考資料
win主機IIS 7 WordPress固定連線的設定
“美觀的”固定連結通常會要求使用mod_rewrite,而IIS(常見於Windows伺服器)卻不支持mod_rewrite。(如果你在Windows上使用Apache 2.0.54,mod_rewrite可能會運行,前提是要在apache\conf\httpd.conf.中激活mod_rewrite)。
使用IIS 7並具備伺服器管理許可權時,可以使用Microsoft的URL重寫模組來代替mod_rewrite。雖然IIS 7不完全兼容mod_rewrite,但它支持WordPress的固定連結。Microsoft的URL重寫模組安裝完畢後,在WordPress目錄下打開web.config檔案,將以下規則添加到system.webServer 元素中:
<rewrite>
< rules>
< rule name="Main Rule" stopProcessing="true">
< match url=".*" />
< conditions logicalGrouping="MatchAll">
< add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
< add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
< /conditions>
< action type="Rewrite" url="index.php" />
< /rule>
< /rules>
< /rewrite>
win主機 IIS 7偽靜態規則的具體使用方法可以查看下面參考資料
IIS網站上有一份關於Microsoft的URL重寫模組詳細的安裝指南,該模組可用於 x64 與x86系統。
如果這個方法行不通,還可以試試PATHINFO連結;將index.php/放在自定義連結結構的開始部分前:
/index.php/%year%/%monthnum%/%day%/%postname%/這個方法並不總能成功,尤其是用在運行於ISS 6上的WordPress時。要讓這方法運行在IIS上,需要將以下兩行代碼添加到php.ini檔案並將檔案保存在網路根目錄下。
cgi.fix_pathinfo = 1
cgi.force_redirect = 0
另一種解決方法是利用IIS的自定義404重定向。這要求你的虛擬主機允許你添加自定義404重定向,不過這並不需要你安裝任何第三方mod_rewrite軟體,也不需要你的固定連結結構以/index.php/開頭。
IIS7虛擬主機裝兩個wordpress固定連結設定
安裝兩個wordpress,一個在根目錄,一個在子目錄(二級目錄)偽靜態規則設定方案:
根目錄的偽靜態規則設定可以看下面參考資料
在子目錄(二級目錄)中的安裝wordpress,Web.config配置檔案偽靜態代碼:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules><remove name="wordpress"/>
<rule name="wordpress" patternSyntax="Wildcard">
<match url="*"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php"/>
</rule></rules>
</rewrite>
</system.webServer>
</configuration>
詳細的設定方案,圖文教程可查看下面參考資料

404錯誤

產生中文TAG標籤連結和中文別名分類目錄連結無法打開的原因是WordPress不支持中文的編碼。我們需要編輯WordPress源檔案讓它支持中文的編碼形式,也就是UTF-8和GBK編碼。
打開編輯wp-include/class-wp.php檔案;
<1>
$pathinfo = $_SERVER['PATH_INFO'];
替換為
$pathinfo = mb_convert_encoding($_SERVER['PATH_INFO'], "UTF-8", "GBK");
<2>
$req_uri = $_SERVER['REQUEST_URI'];[/php]
替換為
$req_uri = mb_convert_encoding($_SERVER['REQUEST_URI'], "UTF-8", "GBK");
詳細設定方案,有源檔案提供下載,圖文教程請查看下面參考資料

常見問題

常見的幾個問題
若是以/%category%/%postname%/這種方式來自定義固定連結的時候打開的網址可能會出現亂碼,可能會打不開頁面,那是因為分類目錄和文章名字是中文引起的,這樣我們可以使用英文的別名來解決。
在創建wordpress固定連結的時候會出現別名設定,選擇合適的英文或者拼音
在發布文章的時候在檔案標題下方有一個固定連結,選擇編輯即可。
使用固定連結的必要條件
具有mod_rewrite模組的Apache網路伺服器 在WordPress主目錄下 激活 FollowSymLinks選項 允許FileInfo directives(如 AllowOverride FileInfo 或 AllowOverride All) 一個.htaccess檔案(若該檔案缺失,WordPress會嘗試在用戶激活美觀的固定連結時創建一個新檔案) 如果你希望WordPress自動更新.htaccess檔案,需要為WordPress賦予該檔案的寫入許可權 當你新建或更新了一個“美觀的”固定連結結構後,WordPress會生成重寫規則並嘗試將重寫規則插入適當的.htaccess檔案。如果WordPress無法將重寫規則插入.htaccess檔案,就會顯示You should update your .htaccess now(請立即升級你的.htaccess檔案)這樣的信息,然後輸出重寫規則,讓你複製並貼上到檔案中(將規則置於檔案結尾處)。
在WordPress 2.0以及更高版本中,你可能只需要執行一次以上動作,因為WordPress會在內部運行重寫規則。如果移動了WordPress主目錄的地址(部落格地址),就需要重複以上動作。
WordPress會與已有的.htaccess檔案合作愉快,也不會刪除任何已存在的重寫規則或其他指令。如果你有其它mod_rewrite規則,請將你的規則優先於WordPress生成的mod_rewrite規則。

解決方案

在Linux主機下,Wordpress固定連線後,也有出現404錯誤頁的可能!
最簡單的方法如下:
自建個 TXT 文章 把下面這段代碼複製進去!
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# BEGIN 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>
# END WordPress
然後把TXT檔案更改名字
擴展名一起改的喔 .htaccess?
把這個檔案上傳到 WordPress 根目錄
然後把許可權改成777 這樣就OK了?
實在不清楚的地方
你可以參考下面的資料!

相關詞條

熱門詞條

聯絡我們