Tommy 碎碎念

Tommy Wu's blog

« 上一篇 | 下一篇 »

Lifetype 在 nginx 的 rewrite 處理
post by tommy @ 03 十二月, 2011 11:56

Lifetype 同樣只提供 Apache 的 rewrite 處理, 所以... 我們一樣需要轉換為 nginx 的方式.

底下是我用的方式 (我是用自訂的格式, 並不是 Lifetype 預設的那種簡短網址, 所以... 如果你要用, 還是要改一下才有作用):

# Lifetype rewrtie rule
#
# sitemap
# /sitemap1.tgz
rewrite ^/sitemap([0-9]+)\.gz$ /tmp/sitemap/$1/sitemap.gz last;
 
# post
# /1/post/3
rewrite ^/([0-9]+)/post/([0-9]+)$ /index.php?op=ViewArticle&blogId=$1&articleId=$2 last;
rewrite ^/([0-9]+)/post/([0-9]+)/page/([1-9][0-9]*)$ /index.php?op=ViewArticle&blogId=$1&articleId=$2&page=$3 last;
# /1/aechive/3
rewrite ^/([0-9]+)/archive/([0-9]+)$ /index.php?op=ViewArticle&blogId=$1&articleId=$2 last;
rewrite ^/([0-9]+)/archive/([0-9]+)/page/([1-9][0-9]*)$ /index.php?op=ViewArticle&blogId=$1&articleId=$2&page=$3 last;
# /post/1/3
rewrite ^/post/([0-9]+)/([0-9]+)$ /index.php?op=ViewArticle&blogId=$1&articleId=$2 last;
rewrite ^/post/([0-9]+)/([0-9]+)/page/([1-9][0-9]*)$ /index.php?op=ViewArticle&blogId=$1&articleId=$2&page=$3 last;
# /aechive/1/3
rewrite ^/archive/([0-9]+)/([0-9]+)$ /index.php?op=ViewArticle&blogId=$1&articleId=$2 last;
rewrite ^/archive/([0-9]+)/([0-9]+)/page/([1-9][0-9]*)$ /index.php?op=ViewArticle&blogId=$1&articleId=$2&page=$3 last;
 
# Monthly/Daily archive
# /1/archives/200401
rewrite "^/([0-9]+)/archives/([0-9]{6})$" /index.php?op=Default&blogId=$1&Date=$2 last;
rewrite "^/([0-9]+)/archives/([0-9]{6})/page/([1-9][0-9]*)$" /index.php?op=Default&blogId=$1&Date=$2&page=$3 last;
# /1/archives/20040101
rewrite "^/([0-9]+)/archives/([0-9]{8})$" /index.php?op=Default&blogId=$1&Date=$2 last;
rewrite "^/([0-9]+)/archives/([0-9]{8})/page/([1-9][0-9]*)$" /index.php?op=Default&blogId=$1&Date=$2&page=$3 last;
# /archives/1/200401
rewrite "^/archives/([0-9]+)/([0-9]{6})$" /index.php?op=Default&blogId=$1&Date=$2 last;
rewrite "^/archives/([0-9]+)/([0-9]{6})/page/([1-9][0-9]*)$" /index.php?op=Default&blogId=$1&Date=$2&page=$3 last;
# /archives/1/20040101
rewrite "^/archives/([0-9]+)/([0-9]{8})$" /index.php?op=Default&blogId=$1&Date=$2 last;
rewrite "^/archives/([0-9]+)/([0-9]{8})/page/([1-9][0-9]*)$" /index.php?op=Default&blogId=$1&Date=$2&page=$3 last;
 
# Album
# /88/album/34
rewrite ^/([0-9]+)/album/([0-9]+)$ /index.php?op=ViewAlbum&blogId=$1&albumId=$2 last;
rewrite ^/([0-9]+)/album/([0-9]+)/page/([1-9][0-9]*)$ /index.php?op=ViewAlbum&blogId=$1&albumId=$2&page=$3 last;
# /album/88/34
rewrite ^/album/([0-9]+)/([0-9]+)$ /index.php?op=ViewAlbum&blogId=$1&albumId=$2 last;
rewrite ^/album/([0-9]+)/([0-9]+)/page/([1-9][0-9]*)$ /index.php?op=ViewAlbum&blogId=$1&albumId=$2&page=$3 last;
 
# Albums
# /88/album/
rewrite ^/([0-9]+)/album/$ /index.php?op=ViewAlbum&blogId=$1&albumId=0 last;
# /album/88/
rewrite ^/album/([0-9]+)/$ /index.php?op=ViewAlbum&blogId=$1&albumId=0 last;
 
# Category view
# /88/categories/4
rewrite ^/([0-9]+)/categories/([0-9]+)$ /index.php?blogId=$1&postCategoryId=$2 last;
rewrite ^/([0-9]+)/categories/([0-9]+)/page/([1-9][0-9]*)$ /index.php?blogId=$1&postCategoryId=$2&page=$3 last;
# /88/category/4
rewrite ^/([0-9]+)/category/([0-9]+)$ /index.php?blogId=$1&postCategoryId=$2 last;
rewrite ^/([0-9]+)/category/([0-9]+)/page/([1-9][0-9]*)$ /index.php?blogId=$1&postCategoryId=$2&page=$3 last;
# /categories/88/4
rewrite ^/categories/([0-9]+)/([0-9]+)$ /index.php?blogId=$1&postCategoryId=$2 last;
rewrite ^/categories/([0-9]+)/([0-9]+)/page/([1-9][0-9]*)$ /index.php?blogId=$1&postCategoryId=$2&page=$3 last;
# /category/88/4
rewrite ^/category/([0-9]+)/([0-9]+)$ /index.php?blogId=$1&postCategoryId=$2 last;
rewrite ^/category/([0-9]+)/([0-9]+)/page/([1-9][0-9]*)$ /index.php?blogId=$1&postCategoryId=$2&page=$3 last;
 
# Category-Feeds
# /3/feeds/categories/2/atom
rewrite ^/([0-9]+)/feeds/categories/([0-9]+)/(.+)$ /rss.php?blogId=$1&categoryId=$2&profile=$3 last;
# /feeds/3/categories/2/atom
rewrite ^/feeds/([0-9]+)/categories/([0-9]+)/(.+)$ /rss.php?blogId=$1&categoryId=$2&profile=$3 last;
# /feeds/categories/3/2/atom
rewrite ^/feeds/categories/([0-9]+)/([0-9]+)/(.+)$ /rss.php?blogId=$1&categoryId=$2&profile=$3 last;
# /3/rss/categories/2/atom
rewrite ^/([0-9]+)/rss/categories/([0-9]+)/(.+)$ /rss.php?blogId=$1&categoryId=$2&profile=$3 last;
# /rss/3/categories/2/atom
rewrite ^/rss/([0-9]+)/categories/([0-9]+)/(.+)$ /rss.php?blogId=$1&categoryId=$2&profile=$3 last;
# /rss/categories/3/2/atom
rewrite ^/rss/categories/([0-9]+)/([0-9]+)/(.+)$ /rss.php?blogId=$1&categoryId=$2&profile=$3 last;
 
# Feeds
# /3/feeds/atom
rewrite ^/([0-9]+)/feeds/(.+)$ /rss.php?blogId=$1&profile=$2 last;
# /feeds/3/atom
rewrite ^/feeds/([0-9]+)/(.+)$ /rss.php?blogId=$1&profile=$2 last;
# /feeds/atom/3
rewrite ^/feeds/(.+)/([0-9]+)$ /rss.php?blogId=$2&profile=$1 last;
# /3/rss/atom
rewrite ^/([0-9]+)/rss/(.+)$ /rss.php?blogId=$1&profile=$2 last;
# /rss/3/atom
rewrite ^/rss/([0-9]+)/(.+)$ /rss.php?blogId=$1&profile=$2 last;
# /rss/atom/3
rewrite ^/rss/(.+)/([0-9]+)$ /rss.php?blogId=$2&profile=$1 last;
 
# Trackbacks
# /3/trackbacks/34
rewrite ^/([0-9]+)/trackbacks/([0-9]+)$ /index.php?op=Trackbacks&blogId=$1&articleId=$2 last;
# /trackbacks/3/34
rewrite ^/trackbacks/([0-9]+)/([0-9]+)$ /index.php?op=Trackbacks&blogId=$1&articleId=$2 last;
 
# Comment form
# /88/comment/34
rewrite ^/([0-9]+)/comment/([0-9]+)$ /index.php?op=Comment&blogId=$1&articleId=$2 last;
# /comment/88/34
rewrite ^/comment/([0-9]+)/([0-9]+)$ /index.php?op=Comment&blogId=$1&articleId=$2 last;
 
# Resources
# /88/resource/1/2
rewrite ^/([0-9]+)/resource/([0-9]+)/([0-9]+)$ /index.php?op=ViewResource&blogId=$1&albumId=$2&resId=$3 last;
# /resource/88/1/2
rewrite ^/resource/([0-9]+)/([0-9]+)/([0-9]+)$ /index.php?op=ViewResource&blogId=$1&albumId=$2&resId=$3 last;
# Download a resource
# /88/gallery/this-is-a-resource-name.pdf
#rewrite ^/([0-9]+)/gallery/(.+)$ /resserver.php?blogId=$1&resource=$2 last;
# /get/88/this-is-a-resource-name.pdf
#rewrite ^/gallery/([0-9]+)/(.+)$ /resserver.php?blogId=$1&resource=$2 last;
 
# A non-default blog
# /88
rewrite ^/([0-9]+)$ /index.php?blogId=$1 last;
rewrite ^/([0-9]+)/index\.php$ /index.php?blogId=$1 last;
rewrite ^/([0-9]+)/page/([1-9][0-9]*)$ /index.php?blogId=$1&page=$2 last;
 
# default blog
# /
rewrite ^/$ /index.php?blogId=1 last;
 
# Static Pages
# /3/demosites
#rewrite ^/([0-9]+)/(.+)$ /index.php?op=Template&blogId=$1&show=$2 last;

除了上面這些外, 因為有裝 Gallery 的 plugins, 所以也要處理 Gallery 的部份:

# Galley begin
# Gallery
# for index.php?op=gallery
rewrite ^/([0-9]+)/index(.+)$ /index$2 last;
 
#
# from gallery's .htaccess
# 1. insert /([0-9]+)/ to /xxx
# 2. change !/main\.php$ to !index\.php$
# 3. change /main.php? to index.php?op=gallery&
# 4. shift parameter, add 1 to them
rewrite ^/([0-9]+)/sitemap$ /index.php?op=gallery&g2_view=sitemap.Sitemap last;
rewrite ^/([0-9]+)/updates$ /index.php?op=gallery&g2_view=dynamicalbum.UpdatesAlbum last;
rewrite ^/([0-9]+)/popular$ /index.php?op=gallery&g2_view=dynamicalbum.PopularAlbum last;
rewrite ^/([0-9]+)/admin/$ /index.php?op=gallery&g2_view=core.SiteAdmin last;
rewrite ^/([0-9]+)/radom([^\?]+)$ /index.php?op=gallery&g2_view=dynamicalbum.RandomAlbum last;
rewrite ^/([0-9]+)/v/([^\?]+)/slideshowapplet\.html$ /index.php?op=gallery&g2_view=slideshowapplet.SlideshowApplet&g2_path=$2 last;
rewrite ^/([0-9]+)/d/([0-9]+)-([0-9]+)/([^\?]+)$ /index.php?op=gallery&g2_view=core.DownloadItem&g2_itemId=$2&g2_serialNumber=$3&g2_fileName=$4 last;
rewrite ^/([0-9]+)/v/([^\?]+)/slideshow\.html$ /index.php?op=gallery&g2_view=slideshowapplet.Slideshow&g2_path=$2 last;
rewrite ^/([0-9]+)/rating/([^?/]+)$ /index.php?op=gallery&g2_view=rating.RatingAlbum&g2_limit=$2 last;
rewrite ^/([0-9]+)/rss/([^\/\?]+)$ /index.php?op=gallery&g2_view=rss.Render&g2_name=$2 last;
rewrite ^/([0-9]+)/srss/([0-9]+)$ /index.php?op=gallery&g2_view=rss.SimpleRender&g2_name=$2 last;
rewrite ^/([0-9]+)/key/([^?/]+)$ /index.php?op=gallery&g2_view=keyalbum.KeywordAlbum&g2_keyword=$2 last;
rewrite ^/([0-9]+)/f/([^\?]+)$ /index.php?op=gallery&g2_controller=permalinks.Redirect&g2_filename=$2 last;
rewrite ^/([0-9]+)/v/([^\?]+)$ /index.php?op=gallery&g2_path=$2 last;
#rewrite ^/([0-9]+)/([^\?]+)$ /index.php?op=gallery&g2_view=rewrite.FileNotFound last;
#rewrite ^/([0-9]+)/([^\?]+)$ /index.php?op=gallery&g2_controller=migrate.Redirect&g2_path=$2;

最後, 與 nginx 沒什麼關係, 不過與 php 有點關係. 新版本的 php 有可能會有個 intl 的模組, 如果包含這個 php5-intl 的話, 裡頭會有 Locale 這個 Class 存在. 因為 LifeType 也有一個同樣名稱的 class, 所以... 就會無法執行了. 解決方法就是不要用 php5-intl 或把 LifeType 更新到 1.1.12 (還沒推出, 所以只能抓 snapshot 或 svn 裡頭的版本).



2011/12/10:
修正一下 static page 的 rewrite, 這會影響後頭 gallery 的 rewrite, 如果要用, 記得把這個放到最後頭. (gallery 的 rewrite 也有一個類似的設定, 同樣記得取消)
Del.icio.us Furl HEMiDEMi Technorati MyShare
迴響
暱稱:
標題:
個人網頁:
電子郵件:
authimage

迴響

  

Bad Behavior 已經阻擋了 139 個過去 7 天試圖闖關的垃圾迴響與引用。
Power by LifeType. Template design by JamesHuang. Valid XHTML and CSS