武汉SEO
时光静好,与君语;细水流年,与君同;繁华落尽,与君老...

ICMS>正文

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

2019-01-29 12:44 gbl

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}&amp;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}&amp;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}&amp;page={R:2}" appendQueryString="false" /> </rule>

本文链接:https://www.0937.biz/post-367.html