栏目/文章/标签 Rewrite规则说明
很人在问iCMS 伪静态(rewrite)怎么设置
iCMS的URL规则都是可以自定义的
可以组成各种各样的URL
就看您喜欢什么样的
下面简单介绍下常用的设置
开启 伪静态(rewrite)
iCMS的rewrite需要在栏目设置中开启
没开启的 都以动态链接显示
/category.php?cid=1
/article.php?id=1
/tag.php?id=1
栏目设置 ->访问模式 选择
然后设置URL规则
静态目录:一般为栏目名的拼音 可以自定义
栏目规则
就是栏目的URL规则
举个栗子
截图中的
{CDIR}/index{EXT}
生成的栏目URL为:http://www.ooxx.com/test/index.html
如果想生成不带index.html
/{CDIR}/
生成的栏目URL为:http://www.ooxx.com/test/
如果想生成最后不带 /
/{CDIR}
生成的栏目URL为:http://www.ooxx.com/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]
内容规则
就是文章的URL
还是举个栗子
截图中的
{CDIR}/{YYYY}/{MM}{DD}/{ID}{EXT}
生成的文章URL为:http://www.ooxx.com/test/2015/0115/1.html
太长了 没关系
咱设置成
{CDIR}/{ID}.html
生成的文章URL为:http://www.ooxx.com/test/1.html
太没个性了 没关系
/ooxx/{ID}.html
生成的文章URL为:http://www.ooxx.com/ooxx/1.html
太黄了
/a/{ID}.html
生成的文章URL为:http://www.ooxx.com/a/1.html
还是没个性
/a/{0xID}.html
生成的文章URL为:http://www.ooxx.com/a/0000001.html
一般要包含{ID}或{0xID}
文章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
标签rewrite设置在系统设置里 标签设置
标签URL:就是标签的URL
例:
标签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]
PS:IIS的rewrite跟apache 差不多
在此就不做介绍
有人想说 我不清楚rewrite是什么...
那就自己google 百度一下 先自己搞清楚了