文档中心

iCMS文档

基本用法

系统伪静态(rewrite)设置

本文介绍的是系统API的rewrite配置

文章/栏目/标签的rewrite配置是独立配置的与本设置无关,
具体可以查看文章/栏目/标签的REWRITE配置

开启rewrite

位置:系统设置->URL设置 REWRITE 开启

iCMSv7.0.8 或者 开发版升级到 git:2018-03-30 之后可使用下面的规则

git:2018-03-30 新增 rewrite.php 伪静态统一解析程序

以下伪静态规则仅供参考

nginx

location / {
   index  index.html index.htm index.php;
   try_files $uri $uri/ /rewrite.php?$args;
}

apache

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . rewrite.php [L]

iCMSv7.0.7及以前版本 或者 开发版升级到 git:2018-03-30 之前使用旧版本规则

开启后 在下面会显示REWRITE配置.

这个一般不用修改,有做二次开发时可根据需要添加相关链接.

nginx配置

#用户APP
rewrite "^/user$"                       /public/api.php?app=user last;
#用户中心 我的首页
rewrite "^/user/home$"                  /public/api.php?app=user&do=home last;
#用户中心 我的内容
rewrite "^/user/manage/(\w+)$"          /public/api.php?app=user&do=manage&pg=$1 last;
rewrite "^/user/manage$"                /public/api.php?app=user&do=manage last;
#发表文章 
rewrite "^/user/publish$"               /public/api.php?app=user&do=manage&pg=publish last;
#我的文章
rewrite "^/user/article$"               /public/api.php?app=user&do=manage&pg=article last;
#我的分类
rewrite "^/user/category$"              /public/api.php?app=user&do=manage&pg=category last;
#我的评论
rewrite "^/user/comment$"               /public/api.php?app=user&do=manage&pg=comment last;
#我的私信
rewrite "^/user/inbox/(\d+)$"           /public/api.php?app=user&do=manage&pg=inbox&user=$1 last;
rewrite "^/user/inbox$"                 /public/api.php?app=user&do=manage&pg=inbox last;

#用户中心 账号设置
rewrite "^/user/profile/(\w+)$"         /public/api.php?app=user&do=profile&pg=$1 last;
rewrite "^/user/profile$"               /public/api.php?app=user&do=profile last;
#用户第三方登陆
rewrite "^/user/login/(\w+)$"           /public/api.php?app=user&do=login&sign=$1 last;
#用户登陆
rewrite "^/user/login$"                 /public/api.php?app=user&do=login last;
#用户注册
rewrite "^/user/register$"              /public/api.php?app=user&do=register last;
#用户退出
rewrite "^/user/logout$"                /public/api.php?app=user&do=logout last;
#用户找回密码
rewrite "^/user/findpwd$"               /public/api.php?app=user&do=findpwd last;

#用户主页
#这里的前缀 /user/ 要根据 URL设置里的 用户URL 设置
rewrite "^/user/(\d+)/(\w+)/$"          /public/api.php?app=user&do=$2&uid=$1 last;
rewrite "^/user/(\d+)/$"                /public/api.php?app=user&do=home&uid=$1 last;
rewrite "^/user/(\d+)/(\d+)/$"          /public/api.php?app=user&do=home&uid=$1&cid=$2 last;
rewrite "^/user/(\d+)/favorite/(\d+)/$" /public/api.php?app=user&do=favorite&uid=$1&id=$2 last;

#系统API
rewrite "^/api$"                        /public/api.php last;
#评论
rewrite "^/comment$"                    /public/api.php?app=comment last;
#搜索
rewrite "^/search$"                     /public/api.php?app=search last; 
#公共API 验证码之类的
rewrite "^/public/(\w+)$"               /public/api.php?app=public&do=$1 last;

#收藏功能
rewrite "^/favorite$"                   /public/api.php?app=favorite last;
rewrite "^/favorite/(\d+)/$"            /public/api.php?app=favorite&id=$1 last;

#自定义表单
rewrite "^/forms$"                      /public/api.php?app=forms last;
rewrite "^/forms/(\w+)$"                /public/api.php?app=forms&do=$1 last;
rewrite "^/forms/(\d+)/$"               /public/api.php?app=forms&id=$1 last;

apache配置

文档完善中,敬请关注......

IIS配置

文档完善中,敬请关注......


REWRITE配置简单说明

下图为REWRITE配置格式化后

{
    "user": [
        "/user",
        "api.php?app=user"
    ],
    "user:home": [
        "/user/home",
        "api.php?app=user&do=home"
    ],
    "user:publish": [
        "/user/publish",
        "api.php?app=user&do=manage&pg=publish"
    ],
    "user:article": [
        "/user/article",
        "api.php?app=user&do=manage&pg=article"
    ],
    "user:category": [
        "/user/category",
        "api.php?app=user&do=manage&pg=category"
    ],
    "user:comment": [
        "/user/comment",
        "api.php?app=user&do=manage&pg=comment"
    ],
    "user:inbox": [
        "/user/inbox",
        "api.php?app=user&do=manage&pg=inbox"
    ],
    "user:inbox:uid": [
        "/user/inbox/{uid}",
        "api.php?app=user&do=manage&pg=inbox&user={uid}"
    ],
    "user:manage": [
        "/user/manage",
        "api.php?app=user&do=manage"
    ],
    "user:manage:favorite": [
        "/user/manage/favorite",
        "api.php?app=user&do=manage&pg=favorite"
    ],
    "user:manage:fans": [
        "/user/manage/fans",
        "api.php?app=user&do=manage&pg=fans"
    ],
    "user:manage:follow": [
        "/user/manage/follow",
        "api.php?app=user&do=manage&pg=follow"
    ],
    "user:profile": [
        "/user/profile",
        "api.php?app=user&do=profile"
    ],
    "user:profile:base": [
        "/user/profile/base",
        "api.php?app=user&do=profile&pg=base"
    ],
    "user:profile:avatar": [
        "/user/profile/avatar",
        "api.php?app=user&do=profile&pg=avatar"
    ],
    "user:profile:setpassword": [
        "/user/profile/setpassword",
        "api.php?app=user&do=profile&pg=setpassword"
    ],
    "user:profile:bind": [
        "/user/profile/bind",
        "api.php?app=user&do=profile&pg=bind"
    ],
    "user:profile:custom": [
        "/user/profile/custom",
        "api.php?app=user&do=profile&pg=custom"
    ],
    "user:register": [
        "/user/register",
        "api.php?app=user&do=register"
    ],
    "user:logout": [
        "/user/logout",
        "api.php?app=user&do=logout"
    ],
    "user:login": [
        "/user/login",
        "api.php?app=user&do=login"
    ],
    "user:login:qq": [
        "/user/login/qq",
        "api.php?app=user&do=login&sign=qq"
    ],
    "user:login:wb": [
        "/user/login/wb",
        "api.php?app=user&do=login&sign=wb"
    ],
    "user:login:wx": [
        "/user/login/wx",
        "api.php?app=user&do=login&sign=wx"
    ],
    "user:findpwd": [
        "/user/findpwd",
        "api.php?app=user&do=findpwd"
    ],
    "uid:home": [
        "/{uid}/",
        "api.php?app=user&do=home&uid={uid}"
    ],
    "uid:comment": [
        "/{uid}/comment/",
        "api.php?app=user&do=comment&uid={uid}"
    ],
    "uid:share": [
        "/{uid}/share/",
        "api.php?app=user&do=share&uid={uid}"
    ],
    "uid:favorite": [
        "/{uid}/favorite/",
        "api.php?app=user&do=favorite&uid={uid}"
    ],
    "uid:fans": [
        "/{uid}/fans/",
        "api.php?app=user&do=fans&uid={uid}"
    ],
    "uid:follower": [
        "/{uid}/follower/",
        "api.php?app=user&do=follower&uid={uid}"
    ],
    "uid:cid": [
        "/{uid}/{cid}/",
        "api.php?app=user&do=home&uid={uid}&cid={cid}"
    ],
    "uid:favorite:id": [
        "/{uid}/favorite/{id}/",
        "api.php?app=user&do=favorite&uid={uid}&id={id}"
    ],
    "api": [
        "/api",
        "api.php"
    ],
    "comment": [
        "/comment",
        "api.php?app=comment"
    ],
    "search": [
        "/search",
        "api.php?app=search"
    ],
    "public:seccode": [
        "/public/seccode",
        "api.php?app=public&do=seccode"
    ],
    "public:agreement": [
        "/public/agreement",
        "api.php?app=public&do=agreement"
    ],
    "favorite": [
        "/favorite",
        "api.php?app=favorite"
    ],
    "favorite:id": [
        "/favorite/{id}/",
        "api.php?app=favorite&id={id}"
    ],
    "forms": [
        "/forms",
        "api.php?app=forms"
    ],
    "forms:save": [
        "/forms/save",
        "api.php?app=forms&do=save"
    ],
    "forms:id": [
        "/forms/{id}/",
        "api.php?app=forms&id={id}"
    ]
}
  • 配置简单说明
  "唯一标识": [
    "伪静态链接",
    "动态链接" 
  ]

例子

  "user": [
    "/user", //REWRITE开启后使用的链接
    "api.php?app=user" //REWRITE关闭后使用的链接
  ], 
  "user:home": [
    "/user/home", 
    "api.php?app=user&do=home"
  ], 
  • 调用方式
<!--{iCMS:router url='user'}-->
<!--{iCMS:router url='user:home'}-->

评论

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