文档中心

iCMS文档

基本用法

文章/栏目/标签等应用rewrite配置

栏目/文章/标签等应用 Rewrite规则说明

很多人在问iCMS 伪静态(rewrite)怎么设置

iCMS的URL规则都是可以自定义的,自由度非常高.

可以组成各种各样的URL

就看您喜欢什么样的

下面简单介绍下常用的设置

开启 伪静态(rewrite)

iCMS的应用rewrite需要在栏目设置中开启

没开启前以动态链接显示

应用 链接 分页链接
栏目/分类 /category.php?cid=1 /category.php?cid=1&page=1
文章 /article.php?id=1 /article.php?id=1&p=1
标签 /tag.php?id=1 /tag.php?id=1&page=1

选择栏目设置 ->URL规则设置->访问模式

然后设置URL规则

静态目录

一般为栏目名自动生成的拼音,可以自定义

栏目URL规则

举个栗子

  • 栏目目录
规则 生成链接
{CDIR}/index{EXT} http://www.ooxx.com/test/index.html
/{CDIR}/ http://www.ooxx.com/test/
/{CDIR} http://www.ooxx.com/test
/ooxx/{CDIR} http://www.ooxx.com/ooxx/test
  • 栏目ID
规则 生成链接
/{CID}/ http://www.ooxx.com/1/
/{CID} http://www.ooxx.com/1
/ooxx/{CID}/ http://www.ooxx.com/ooxx/1/

栏目规则有{CID}的 rewrite

/{CID}/

  • nginx

    rewrite "^/(\d+)(/|/index\.html)$"          /category.php?cid=$1 last;
    rewrite "^/(\d+)/index_(\d+).html$"         /category.php?cid=$1&page=$2 last; #这个是分页
  • apache

    RewriteRule ^(\d+)(/|/index\.html)$             category.php?cid=$1 [L]
    RewriteRule ^(\d+)/index_(\d+).html$            category.php?cid=$1&page=$2 [L]

/ooxx/{CID}/

  • nginx

    rewrite "^/ooxx/(\d+)(/|/index\.html)$"         /category.php?cid=$1 last;
    rewrite "^/ooxx/(\d+)/index_(\d+).html$"        /category.php?cid=$1&page=$2 last; #这个是分页
  • apache

    RewriteRule ^ooxx/(\d+)(/|/index\.html)$        category.php?cid=$1 [L]
    RewriteRule ^ooxx/(\d+)/index_(\d+).html$       category.php?cid=$1&page=$2 [L]

/list-{CID}-{P}.html

  • nginx

    rewrite "^/list-(\d+)-(\d+).html$"          /category.php?cid=$1&page=$2 last;
  • apache

    RewriteRule ^list-(\d+)-(\d+).html$        category.php?cid=$1&page=$2 [L]

栏目规则有{CDIR}的 rewrite

/{CDIR}/

  • nginx

    rewrite "^/(\w+)(/|/index\.html)$"     /category.php?dir=$1 last;
    rewrite "^/(\w+)/index_(\d+).html$"    /category.php?dir=$1&page=$2 last; #这个是分页
  • apache

    RewriteRule ^(\w+)/$                        category.php?dir=$1 [L]
    RewriteRule ^(\w+)/index.html$              category.php?dir=$1 [L]
    RewriteRule ^(\w+)/index_(\d+).html$       category.php?dir=$1&page=$2 [L]

/ooxx/{CDIR}/

  • nginx

    rewrite "^/ooxx/(\w+)(/|/index\.html)$"        /category.php?dir=$1 last;
    rewrite "^/ooxx/(\w+)/index_(\d+).html$"   /category.php?dir=$1&page=$2 last;
  • apache

    RewriteRule ^ooxx/(\w+)/$                        category.php?dir=$1 [L]
    RewriteRule ^ooxx/(\w+)/index.html$              category.php?dir=$1 [L]
    RewriteRule ^ooxx/(\w+)/index_(\d+).html$       category.php?dir=$1&page=$2 [L]

栏目的分页规则跟栏目的首页规则是一样的

但是{P}要对应&page=


内容规则

就是文章的URL

举个栗子

规则 链接
{CDIR}/{YYYY}/{MM}{DD}/{ID}{EXT} http://www.ooxx.com/test/2015/0115/1.html
{CDIR}/{ID}.html http://www.ooxx.com/test/1.html
/ooxx/{ID}.html http://www.ooxx.com/ooxx/1.html
/a/{ID}.html http://www.ooxx.com/a/1.html
/a/{0xID}.html http://www.ooxx.com/a/0000001.html
/{CDIR}/{LINK}{EXT} http://www.ooxx.com/test/自定义链接.html

一般要包含{ID}或者{0xID}或者{LINK}

文章rewrite

{CDIR}/{YYYY}/{MM}{DD}/{ID}{EXT}

  • nginx

    rewrite "^/\w+/\d+/\d+/(\d+).html$"             /article.php?id=$1 last;
    rewrite "^/\w+/\d+/\d+/(\d+)_(\d+).html$"       /article.php?id=$1&p=$2 last;
  • apache

    RewriteRule ^\w+/\d+/\d+/(\d+).html$              article.php?id=$1 [L]
    RewriteRule ^\w+/\d+/\d+/(\d+)_(\d+).html$        article.php?id=$1&p=$2 [L]

{CDIR}/{ID}.html

  • nginx

    rewrite "^/\w+/(\d+).html$"             /article.php?id=$1 last;
    rewrite "^/\w+/(\d+)_(\d+).html$"       /article.php?id=$1&p=$2 last;
  • apache

    RewriteRule ^\w+/(\d+).html$              article.php?id=$1 [L]
    RewriteRule ^\w+/(\d+)_(\d+).html$        article.php?id=$1&p=$2 [L]

    /a/{0xID}.html

  • nginx

    rewrite "^/a/(\d+).html$"               /article.php?id=$1 last;
    rewrite "^/a/(\d+)_(\d+).html$"         /article.php?id=$1&p=$2 last;
  • apache

    RewriteRule ^a/(\d+).html$              article.php?id=$1 [L]
    RewriteRule ^a/(\d+)_(\d+).html$        article.php?id=$1&p=$2 [L]

    其它的以此类推

标签的rewrite

标签URL规则

规则 链接
{PHP} /tag.php?id=1
{ID} http://www.ooxx.com/tag/1
{TKEY} http://www.ooxx.com/tag/test
{ZH_CN} http://www.ooxx.com/tag/中文

{ID}

  • nginx

    rewrite "^/tag/(\d+)(/|/index\.html)$"          /tag.php?id=$1 last;
    rewrite "^/tag/(\d+)/index_(\d+).html$"         /tag.php?id=$1&page=$2 last;
  • apache

    RewriteRule ^tag/(\d+)$                         tag.php?id=$1 [L]
    RewriteRule ^tag/(\d+)/index.html$              tag.php?id=$1 [L]
    RewriteRule ^tag/(\d+)/index_(\d+).html$        tag.php?id=$1&page=$2 [L]

{TKEY}

  • nginx

    rewrite "^/tag/(\w+)(/|/index\.html)$"          /tag.php?tkey=$1 last;
    rewrite "^/tag/(\w+)/index_(\d+).html$"         /tag.php?tkey=$1&page=$2 last;
  • apache

    RewriteRule ^tag/(\w+)$                         tag.php?tkey=$1 [L]
    RewriteRule ^tag/(\w+)/index.html$              tag.php?tkey=$1 [L]
    RewriteRule ^tag/(\w+)/index_(\d+).html$        tag.php?tkey=$1&page=$2 [L]

{ZH_CN}或者 {NAME}

  • nginx

    rewrite "^/tag/(.+)(/|/index\.html)$"           /tag.php?name=$1 last;
    rewrite "^/tag/(.+)/index_(\d+).html$"          /tag.php?name=$1&page=$2 last;
  • apache

    RewriteRule ^tag/(.+)$                         tag.php?name=$1 [L]
    RewriteRule ^tag/(.+)/index.html$              tag.php?name=$1 [L]
    RewriteRule ^tag/(.+)/index_(\d+).html$        tag.php?name=$1&page=$2 [L]

IIS的rewrite 自己根据上面的规则修改下

在此就不做介绍

有人想说 我不清楚rewrite是什么...

那就自己google 百度一下 先自己搞清楚了

评论

暂无评论...
验证码 换一张
取 消