文档中心

iCMS文档

基本用法

栏目/文章/标签等应用 Rewrite规则示例


系统URL设置如图


文章和栏目设置如图

标签设置
标签设置如图

如果您的配置跟图中有不同之处

下面Rewrite规则请做相应该的修改

你要原封不动复制粘贴,造成访问不了。

那就好自为之吧,我只能帮你到这了。也别到群里问。

到于什么是Rewrite,APACHE/nginx怎么设置Rewrite 请自行google

最后设置完成后,最好看下最终的网址路径是什么样子的

做适应的调整

由于标签URL规则优化级

标签指定URL > 标签分类 > 标签所属栏目 > 默认配置

所以当前规则 使用标签所属栏目规则 /{CDIR}/{TKEY}{EXT}

rewrite 规则

  • 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;

##栏目
rewrite "^/(\w+)/$"                                        /category.php?dir=$1 last;
rewrite "^/(\w+)/index.html$"                        /category.php?dir=$1 last;
rewrite "^/(\w+)/index_(\d+).html$"               /category.php?dir=$1&page=$2 last;

##标签 使用标签所属栏目规则 /{CDIR}/{TKEY}{EXT},
##当前TKEY生成是没有分隔符的 所以用\w+匹配 
##如果有分隔符的话,要把分隔符也在加规则里去
##例如:([\w\-]+) -为分隔符

rewrite "^/.+/([\w\-]+).html$"              /tag.php?tkey=$1 last;
rewrite "^/.+/([\w\-]+)_(\d+).html$"        /tag.php?tkey=$1&page=$2 last;

如果程序安装在网站根目录的话
由于后台编辑器上的链接分别为
/app/admincp/ui/ueditor/dialogs/image/image.html
/app/admincp/ui/ueditor/dialogs/video/video.html
会被上面的标签伪静态规则匹配到,造成显示404或者显示找不到该标签
那么就将标签的伪静态规则改成如下

rewrite "^/(?!app/admincp).+/([\w\-]+).html$" /tag.php?tkey=$1 last;
rewrite "^/(?!app/admincp).+/([\w\-]+)_(\d+).html$" /tag.php?tkey=$1&page=$2 last;
  • apache
RewriteEngine on
RewriteBase /

##文章
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]

##栏目
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]

##标签 使用标签所属栏目规则 /{CDIR}/{TKEY}{EXT},
##当前TKEY生成是没有分隔符的 所以用\w+匹配 
##如果有分隔符的话,要把分隔符也在加规则里去
##例如:([\w\-]+) -为分隔符

RewriteRule ^/.+/([\w\-]+).html$              tag.php?tkey=$1 last;
RewriteRule ^/.+/([\w\-]+)_(\d+).html$        tag.php?tkey=$1&page=$2 last;
  • IIS (未测试正确性,如有问题请自行修改)
<rule name="文章规则1" stopProcessing="true">
<match url="^\w+/\d+/\d+/(\d+).html$" ignoreCase="false" />
<action type="Rewrite" url="article.php?id={R:1}" appendQueryString="false" />
</rule>
<rule name="文章规则2" stopProcessing="true">
<match url="^\w+/\d+/\d+/(\d+)_(\d+).html$" ignoreCase="false" />
<action type="Rewrite" url="article.php?id={R:1}&p={R:2}" appendQueryString="false" />
</rule>

<rule name="栏目1" stopProcessing="true">
<match url="^(\w+)/$" ignoreCase="false" />
<action type="Rewrite" url="category.php?dir={R:1}" appendQueryString="false" />
</rule>
<rule name="栏目2" stopProcessing="true">
<match url="^(\w+)/index.html$" ignoreCase="false" />
<action type="Rewrite" url="category.php?dir={R:1}" appendQueryString="false" />
</rule>
<rule name="栏目3" stopProcessing="true">
<match url="^(\w+)/index_(\d+).html$" ignoreCase="false" />
<action type="Rewrite" url="category.php?dir={R:1}&page={R:2}" appendQueryString="false" />
</rule>

<rule name="标签规则1" stopProcessing="true">
<match url="^.+/([\w\-]+).html$" ignoreCase="false" />
<action type="Rewrite" url="tag.php?tkey={R:1}" appendQueryString="false" />
</rule>
<rule name="标签规则2" stopProcessing="true">
<match url="^.+/([\w\-]+)_(\d+).html$" ignoreCase="false" />
<action type="Rewrite" url="tag.php?tkey={R:1}&page={R:2}" appendQueryString="false" />
</rule>

评论

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