*奇想西卡*

« [美食] 丼久的家 | Main | [MySql] 備份與還原 »

05 三月, 2006

[lifetype] 自定網址、rewrite

blog二三四 — 作者 segaa @ 00:02

今天為了簡潔網址跟lifetype奮鬥好久,終於釐清了一些事情 :D

1. Apache ModReWrite 是透過 apache 的 mod_rewrite 模組來作 url 轉換,所以 http://www.abc.com/index.php?blogId=1 會被轉換成 http://www.abc.com/your-blog 。這跟再使用一般網址時沒有兩樣。因為 Apache 幫你作了所有的轉換工作。

2. 簡潔網址與自訂網址是透過 apache 的 ErrorDocument 的設定,來把『錯誤』的網址轉到特定的 pLog 程式來作處理。為什麼叫做錯誤?因為
http://www.abc.com/your-blog 其實是個不存在的URL,當 apache 接收到後,就把 http://www.abc.com/your-blog 傳到 error.php,error.php 再把網址轉譯成相對應的 變數如 blogId, articleId 等,再把這個 request 傳到 index.php,再進入 pLog 的正常執行程序。

所以你要是使用自定義網址或簡潔網址,你會發現 apache 的 error.log 有一堆 找不到網址的 error。

1.啟用 rewrite紀錄一下lifetype內建的 .htaccess 內容

<Files .htaccess>
deny from all
</Files>

<Files config.properties.php>
deny from all
</Files>

Options -Indexes
Options +FollowSymLinks

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# Permalink to the blog entry (i.e. /plog/1_userfoo/archive/3_title-foo-bar.html)
RewriteRule ^([0-9]+)_[^/]+/archive/([0-9]+)_[^.]+.html$ index.php?op=ViewArticle&blogId=$1&articleId=$2 [L,NC]

# Monthly archive (i.e. /plog/1_userfoo/archive/200401.html)
RewriteRule ^([0-9]+)_[^/]+/archive/([0-9]{6}).html$ index.php?blogId=$1&Date=$2 [L,NC]

# Daily archive (i.e. /plog/1_blogfoo/archive/20040101.html)
RewriteRule ^([0-9]+)_[^/]+/archive/([0-9]{8}).html$ index.php?blogId=$1&Date=$2 [L,NC]

# Album (i.e. /plog/88_userfoo/albums/34_title-foo-bar.html)
RewriteRule ^([0-9]+)_[^/]+/albums/([0-9]+)_[^.]+.html$ index.php?op=ViewAlbum&blogId=$1&albumId=$2 [L,NC]

# Albums (i.e. /plog/88_userfoo/albums/)
RewriteRule ^([0-9]+)_[^/]+/albums/$ index.php?op=ViewAlbum&blogId=$1&albumId=0 [L,NC]

# Category view (i.e. /plog/88_userfoo/categories/4_cat-foobar.html)
# Category-Feeds (i.e. /plog/3_userfoo/feeds/categories/2_category/atom)
RewriteRule ^([0-9]+)_[^/]+/feeds/categories/([0-9]+)_[^.]+/(.*)$ rss.php?blogId=$1&categoryId=$2&profile=$3 [L,NC]

# Feeds (i.e. /plog/3_userfoo/feeds/atom)
RewriteRule ^([0-9]+)_[^/]+/feeds/(.*)$ rss.php?blogId=$1&profile=$2 [L,NC]

# Trackbacks (i.e. /plog/3_userfoo/trackbacks/34_title-foo-bar.html)
RewriteRule ^([0-9]+)_[^/]+/trackbacks/([0-9]+)_[^.]+.html$ index.php?op=Trackbacks&blogId=$1&articleId=$2 [L,NC]

# Comment form (i.e. /plog/88_userfoo/comment/34_title-foo-bar.html)
RewriteRule ^([0-9]+)_[^/]+/comment/([0-9]+)_[^.]+.html$ index.php?op=Comment&blogId=$1&articleId=$2 [L,NC]

# Resources (i.e. /plog/88_userfoo/resources/this-is-a-resource-name.pdf.html)
RewriteRule ^([0-9]+)_[^/]+/resources/([^.]+).([^.]+).html$ index.php?op=ViewResource&blogId=$1&resource=$2.$3 [L,NC]

# Download a resource (i.e. /plog/88_userfoo/get/this-is-a-resource-name.pdf)
RewriteRule ^([0-9]+)_[^/]+/get/(.+)$ resserver.php?blogId=$1&resource=$2 [L,NC]

# Static Pages (i.e /plog/3_userfoo/demosites)
RewriteRule ^([0-9]+)_[^/]+/(.+)$ index.php?op=Template&blogId=$1&show=$2 [NC]

# A non-default blog (i.e. /plog/88_userfoo)
RewriteRule ^([0-9]+)(_[^/]+)?$ index.php?blogId=$1 [L,NC]

# Daily archive (i.e. /plog/1_userfoo/archive/20040101.html)
RewriteRule ^([0-9]+)_[^/]+/archive/([0-9]{8}).html$ index.php?blogId=$1&Date=$2 [L,NC]

</IfModule>
<Files post>
ForceType application/x-httpd-php
</Files>

<Files archives>
ForceType application/x-httpd-php
</Files>

<Files static>
ForceType application/x-httpd-php
</Files>

<Files rss>
ForceType application/x-httpd-php
</Files>

<Files category>
ForceType application/x-httpd-php
</Files>

<Files trackbacks>
ForceType application/x-httpd-php
</Files>

<Files comment>
ForceType application/x-httpd-php
</Files>

<Files resource>
ForceType application/x-httpd-php
</Files>

<Files get>
ForceType application/x-httpd-php
</Files>

<Files album>
ForceType application/x-httpd-php
</Files>

<Files blog>
ForceType application/x-httpd-php
</Files>

<Files user>
ForceType application/x-httpd-php
</Files>

ErrorDocument 401 /error.php
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php

2.啟用自訂網址

permalink_format
/{blogowner}/post/{catid}/{postid}$

category_link_format
/{blogowner}/catid={catid}$

blog_link_format
/{blogowner}$

archive_link_format
/{blogowner}/archives/{year}{month}{day}$

user_posts_link_format
/{blogowner}/user={username}$

post_trackbacks_link_format
/{blogowner}/trackbacks/{postid}$

template_link_format
/{blogowner}/page/{templatename}$

album_link_format
/{blogowner}/albumid={albumid}$

resource_link_format
/{blogowner}/resource/{albumid}/{resourcename}$

resource_preview_link_format
/{blogowner}/resource/{albumid}/preview/{resourceid}$

resource_medium_size_preview_link_format
/{blogowner}/resource/{albumid}/preview_med/{resourceid}$

resource_download_link_format
/{blogowner}/resource/{albumid}/download/{resourceid}$

3.其實 mod_rewrite跟自訂網址可以並存,先啟動lifetype內建的mod_rewrite 再改為 自訂網址就OK了 。

 

以上是自己紀錄用的文件內容 ... 看不懂的話請參考資料來源 :D

http://ajer001.blog.twntwn.info/post/1/186

http://yao.evisual.com.tw/viewtopic.php?p=348&sid=2a38f71870023b1154cfe11d3beb2bb0


« [美食] 丼久的家 | Main | [MySql] 備份與還原 »

迴響


發表迴響






Powered by LifeType