精華 z-blog或者其他CMS在二級(jí)目錄偽靜態(tài)規(guī)則的設(shè)置方法分享
在成功使用Z-Blog搭建網(wǎng)站后,為了優(yōu)化URL結(jié)構(gòu)、提升搜索引擎友好度及用戶體驗(yàn),設(shè)置服務(wù)器的偽靜態(tài)規(guī)則變得尤為重要。幸運(yùn)的是,Z-Blog官方非常貼心地在其偽靜態(tài)設(shè)置頁面中提供了針對(duì)多種常見服務(wù)器環(huán)境的偽靜態(tài)規(guī)則配置示例,包括Apache(通過.htaccess文件)、IIS 7及以上版本(利用URL Rewrite Module)、IIS 6(結(jié)合ISAPI Rewrite 2.X)、Nginx以及Lighttpd。以下是如何根據(jù)你所使用的服務(wù)器環(huán)境來設(shè)置偽靜態(tài)規(guī)則的簡要指南:
Zblog偽靜態(tài)規(guī)則獲取
一、登錄ZBLOG后臺(tái)后,點(diǎn)擊插件管理,找到靜態(tài)管理中心。
如果你沒有靜態(tài)管理中心,就自己去應(yīng)用中心安裝一個(gè)。
zblog偽靜態(tài)規(guī)則
二、在設(shè)置界面選擇偽靜態(tài),然后下面的規(guī)則你可以自己修改或者保持默認(rèn)。
zblog偽靜態(tài)規(guī)則
三、點(diǎn)擊確定后,就會(huì)跳轉(zhuǎn)到ReWrite規(guī)則界面。
zblog偽靜態(tài)規(guī)則
四、把生成的偽靜態(tài)規(guī)則添加到你網(wǎng)站的偽靜態(tài)配置里面即可。
不同程序的Zblog偽靜態(tài)規(guī)則
apache zblog偽靜態(tài)規(guī)則
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /zixun/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /zixun/index.php [L]
</IfModule>
把上面的內(nèi)容保存為.htaccess文件,然后上傳到網(wǎng)站根目錄就可以了。子目錄規(guī)則同理。
IIS7 zblog偽靜態(tài)規(guī)則
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="/zixun/ Z-BlogPHP Imported Rule" stopProcessing="true">
<match url="^.*?" ignoreCase="false" />
<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/{R:0}" />
</rule>
<rule name="/zixun/ Z-BlogPHP Imported Rule index.php" stopProcessing="true">
<match url="^index.php/.*?" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="index.php/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
在網(wǎng)站 “當(dāng)前目錄” 創(chuàng)建web.config文件并把相關(guān)內(nèi)容復(fù)制進(jìn)去,子目錄同理。
IIS6 zblog偽靜態(tài)規(guī)則
[ISAPI_Rewrite]
RewriteRule /zixun/page_([0-9]*)\.html /zixun/index\.php\?page=$1&rewrite=1&full_uri=$0 [I,L]
RewriteRule /zixun/date-([0-9\-]+)(?:_)?([0-9]*)\.html /zixun/index\.php\?date=$1&page=$2&rewrite=1&full_uri=$0 [I,L]
RewriteRule /zixun/author-([0-9]+)(?:_)?([0-9]*)\.html /zixun/index\.php\?auth=$1&page=$2&rewrite=1&full_uri=$0 [I,L]
RewriteRule /zixun/tags-([0-9]+)(?:_)?([0-9]*)\.html /zixun/index\.php\?tags=$1&page=$2&rewrite=1&full_uri=$0 [I,L]
RewriteRule /zixun/category-([0-9]+)(?:_)?([0-9]*)\.html /zixun/index\.php\?cate=$1&page=$2&rewrite=1&full_uri=$0 [I,L]
RewriteRule /zixun/post-([0-9]+)\.html(\?.*)? /zixun/index\.php\?id=$1&rewrite=1&full_uri=$0 [I,L]
RewriteRule /zixun/([0-9]+)\.html(\?.*)? /zixun/index\.php\?id=$1&rewrite=1&full_uri=$0 [I,L]
請(qǐng)?jiān)诰W(wǎng)站根目錄創(chuàng)建httpd.ini文件并把相關(guān)內(nèi)容復(fù)制進(jìn)去,httpd.ini文件必須為ANSI編碼,也可以點(diǎn)擊按鈕生成.
提示:本規(guī)則用戶可以加入自定義規(guī)則,將自己的目錄或是文件排除過于廣泛的重寫之外.
提示:ISAPI Rewrite 3請(qǐng)按Apache規(guī)則生成.
Nginx zblog 根目錄偽靜態(tài)規(guī)則
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 (.*) /zixun/index.php;
}
修改nginx.conf,在 location / { }節(jié)點(diǎn) 或者是 location [安裝目錄名稱] / { }(子目錄安裝)節(jié)點(diǎn)間加入上述規(guī)則.
解釋下就是,如果你zblog安裝在子目錄,那么對(duì)應(yīng)的偽靜態(tài)規(guī)則就是下面這樣:
location /zblog/ {
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 (.*) /zixun/index.php;
}
}
你使用的是LNMP一鍵包的話,可以把上面的子目錄偽靜態(tài)規(guī)則單獨(dú)保存為一個(gè)conf文件。例如zblog2.conf,然后在虛擬主機(jī)的配置文件里面引入就可以了。
include rewrite/zblog2.conf;
寶塔面板的話把子目錄規(guī)則添加到現(xiàn)在的偽靜態(tài)規(guī)則后面。
z-blog偽靜態(tài)樣式自定義
如果你對(duì)默認(rèn)的Z-blog偽靜態(tài)鏈接效果不滿意,可以自己DIY,對(duì)應(yīng)的參數(shù)如下:
1、文章的URL配置
可配置參數(shù):
{%host%} :網(wǎng)站地址,必須
{%id%} :文章ID,文章ID和文章別名必須選擇其中一個(gè)
{%alias%} :文章別名,文章ID和文章別名必須選擇其中一個(gè)
{%year%} :文章年份,可選
{%month%} :文章月份,可選
{%category%} :文章所屬分類別名,可選
2、頁面的URL配置
可配置參數(shù):
{%host%} :網(wǎng)站地址,必須
{%id%} :頁面ID,頁面ID和頁面別名必須選擇其中一個(gè)
{%alias%} :頁面別名,頁面ID和頁面別名必須選擇其中一個(gè)
3、首頁的URL配置
可配置參數(shù):
{%host%} :網(wǎng)站地址,必須
{%page%} :分頁碼,必須
4、分類頁的URL配置
可配置參數(shù):
{%host%} :網(wǎng)站地址,必須
{%id%} :分類ID,分類ID和分類別名至少使用一個(gè)
{%alias%} :分類別名,分類ID和分類別名至少使用一個(gè)
{%page%} :分頁碼,必須
5、標(biāo)簽頁的URL配置
可配置參數(shù):
{%host%} :網(wǎng)站地址,必須
{%id%} :標(biāo)簽ID,標(biāo)簽ID和標(biāo)簽別名至少選擇一個(gè)
{%alias%} :標(biāo)簽別名,標(biāo)簽ID和標(biāo)簽別名至少選擇一個(gè)
{%page%} :分頁碼,必須
6、日期頁的URL配置
可配置參數(shù):
{%host%} :網(wǎng)站地址,必須
{%date%} :日期,必須
{%page%} :分頁碼,必須
7、作者頁的URL配置
可配置參數(shù):
{%host%} :網(wǎng)站地址,必須
{%id%} :作者ID,必須
{%page%} :分頁碼,必須