Path: API › 网站管理

`POST /site`

为指定网站创建重定向规则，支持域名重定向和路径重定向。

## Request body

_Required._

- `action237.request_time` (string, required) — Unix 时间戳。
- `action237.request_token` (string, required) — 按 API 概览生成的签名。
- `action237.action` (string, required) — 具体操作名称。
  - one of `"CreateRedirect"`
- `action237.sitename` (string, required) — 网站域名（注意小写）
- `action237.redirectname` (string, required) — 重定向名称（唯一标识）
- `action237.tourl` (string, required) — 目标 URL
- `action237.redirectdomain` (string, required) — JSON 数组，来源域名列表 `["old.example.com"]`
- `action237.redirectpath` (string, required) — 来源路径，如 `/` 或 `/old-path`
- `action237.redirecttype` (string, required) — 重定向类型：`"path"` / `"domain"`
- `action237.type` (string, required) — `"0"` 启用 / `"1"` 301 永久
- `action237.domainorpath` (string, required) — `"path"` 路径重定向 / `"domain"` 域名重定向
- `action237.holdpath` (string, required) — `"1"` 保留路径 / `"0"` 不保留

## Example request

```text
{
  "request_time": "string",
  "request_token": "string",
  "action": "CreateRedirect",
  "sitename": "string",
  "redirectname": "string",
  "tourl": "string",
  "redirectdomain": "string",
  "redirectpath": "string",
  "redirecttype": "string",
  "type": "string",
  "domainorpath": "string",
  "holdpath": "string"
}
```

## Code samples

### cURL（填写面板地址与签名）

```curl
curl --request POST \
  --url "https://your-panel.example.com:8888/site" \
  --header "Content-Type: application/x-www-form-urlencoded" \
  --data-urlencode "request_time=<Unix时间戳>" \
  --data-urlencode "request_token=<按 API 概览生成的签名>" \
  --data-urlencode "action=CreateRedirect" \
  --data-urlencode "sitename=<sitename>" \
  --data-urlencode "redirectname=<redirectname>" \
  --data-urlencode "tourl=<tourl>" \
  --data-urlencode "redirectdomain=<redirectdomain>" \
  --data-urlencode "redirectpath=<redirectpath>" \
  --data-urlencode "redirecttype=<redirecttype>" \
  --data-urlencode "type=<type>" \
  --data-urlencode "domainorpath=<domainorpath>" \
  --data-urlencode "holdpath=<holdpath>"
```

## Responses

### default

接口响应，业务状态见下方详细说明。

#### Example

```json
{
  "status": true,
  "msg": "创建成功"
}
```

- `action237.response.default.status` (boolean, optional) — `true` 创建成功


## CreateRedirect

为指定网站创建重定向规则，支持域名重定向和路径重定向。

- **路由**：`POST /site`
- **action**：`CreateRedirect`

## 输入参数

| 参数名称 | 必选 | 类型 | 描述 |
|----------|------|------|------|
| action | 是 | String | 固定值 `CreateRedirect` |
| sitename | 是 | String | 网站域名（注意小写） |
| redirectname | 是 | String | 重定向名称（唯一标识） |
| tourl | 是 | String | 目标 URL |
| redirectdomain | 是 | String | JSON 数组，来源域名列表 `["old.example.com"]` |
| redirectpath | 是 | String | 来源路径，如 `/` 或 `/old-path` |
| redirecttype | 是 | String | 重定向类型：`"path"` / `"domain"` |
| type | 是 | String | `"0"` 启用 / `"1"` 301 永久 |
| domainorpath | 是 | String | `"path"` 路径重定向 / `"domain"` 域名重定向 |
| holdpath | 是 | String | `"1"` 保留路径 / `"0"` 不保留 |

## 输出参数

| 参数名称 | 类型 | 描述 |
|----------|------|------|
| status | Boolean | `true` 创建成功 |

## 示例

### 请求

```
POST /site HTTP/1.1
Host: 192.168.168.213:8888
Content-Type: application/x-www-form-urlencoded

action=CreateRedirect&sitename=testapi.bt.local&redirectname=old_site&tourl=http://example.com&redirectdomain=["old.example.com"]&redirectpath=/&redirecttype=path&type=0&domainorpath=path&holdpath=0
```

### 响应

```json
{"status": true, "msg": "创建成功"}
```

## 相关接口

- [GetRedirectList](/api/site/getredirectlist) — 查询重定向列表
- [ModifyRedirect](/api/site/modifyredirect) — 修改重定向
- [DeleteRedirect](/api/site/deleteredirect) — 删除重定向

