> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# CreateRedirect

# Package: redirects

# Namespace: RedirectsService

# Method link: https://dev.wix.com/docs/api-reference/business-management/seo/redirects/redirect-v1/create-redirect.md

## Permission Scopes:
Manage SEO Settings: SCOPE.PROMOTE.MANAGE-SEO

## Introduction

Creates a redirect.

The `from` path can't be the site root, and can't already belong to another redirect unless
`options.forceReplace` is `true`. With `options.forceReplace`, the redirect that holds the path
is deleted and the new one is created in its place.

If the redirect would close a loop, meaning an existing redirect starts at the path this one
points to, the redirect that closes the loop is deleted and the create proceeds. Both a
conflicting redirect replaced this way and a loop-closing redirect are gone for good, so
retrieve them first if you need to restore them.

Creating a redirect that already exists with the same `from`, `to`, and `options.groupRedirect`
changes nothing and returns the redirect from the request, without an `id` or a `createdDate`.

To create multiple redirects in a single API call, call [Bulk Create Redirects](https://dev.wix.com/docs/api-reference/business-management/seo/redirects/redirect-v1/bulk-create-redirects.md). Note the
difference in how the two handle problems: this method resolves loops and, with
`options.forceReplace`, conflicts, while [Bulk Create Redirects](https://dev.wix.com/docs/api-reference/business-management/seo/redirects/redirect-v1/bulk-create-redirects.md) fails the individual redirect
instead.

---

## REST API

### Schema

```
 Method: createRedirect
 Description: Creates a redirect.  The `from` path can't be the site root, and can't already belong to another redirect unless `options.forceReplace` is `true`. With `options.forceReplace`, the redirect that holds the path is deleted and the new one is created in its place.  If the redirect would close a loop, meaning an existing redirect starts at the path this one points to, the redirect that closes the loop is deleted and the create proceeds. Both a conflicting redirect replaced this way and a loop-closing redirect are gone for good, so retrieve them first if you need to restore them.  Creating a redirect that already exists with the same `from`, `to`, and `options.groupRedirect` changes nothing and returns the redirect from the request, without an `id` or a `createdDate`.  To create multiple redirects in a single API call, call [Bulk Create Redirects](https://dev.wix.com/docs/api-reference/business-management/seo/redirects/redirect-v1/bulk-create-redirects.md). Note the difference in how the two handle problems: this method resolves loops and, with `options.forceReplace`, conflicts, while [Bulk Create Redirects](https://dev.wix.com/docs/api-reference/business-management/seo/redirects/redirect-v1/bulk-create-redirects.md) fails the individual redirect instead.
 URL: https://www.wixapis.com/seo-redirects-service/v1/create-redirect
 Method: POST
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  redirect
 Method parameters: 
   param name: options | type: CreateRedirectOptions | description: Extra options for creating a redirect.  
        - name: forceReplace | type: boolean | description: Whether to delete the redirect that already starts from the same `from` path and create the new one in its place. When `false`, a taken `from` path fails the call with `FROM_URL_EXISTS`.  The replaced redirect is deleted for good, so retrieve it first if you might need to restore it.  Default: `false`  
   param name: redirect | type: Redirect | description: A redirect sends a visitor who requests one path on a site to another path or URL.  Redirects keep old links working after a page is renamed or removed, consolidate duplicate URLs, and point a whole section of a site somewhere else. A redirect returns a 301 permanent redirect, takes effect on the live site immediately with no site publish, and takes precedence over a page that exists at the same path.  A redirect either matches its `from` path exactly, or matches everything under it when `options.groupRedirect` is `true`. A redirect scoped to a `language` applies to that language version of a multilingual site, and one with no `language` applies to every language. | required: true 
        - name: from | type: string | description: Path on the site that the redirect starts from, URL-encoded. For example, `/old-page`.  Can't be the site root. A path that differs from another redirect's `from` path only by a trailing slash counts as the same path.  For a redirect scoped to a `language`, specify the path with or without the language prefix: the prefix is stripped, so a `fr` redirect from `/fr/about` is stored and returned as `/about`.  | validation: maxLength 950
        - name: to | type: string | description: Where the redirect sends the visitor, URL-encoded. Either a path on the site, such as `/new-page`, or a full URL, such as `https://example.com/page`.  | validation: maxLength 4096
        - name: options | type: RedirectOptions | description: How the redirect matches the paths a visitor requests.  
           - name: groupRedirect | type: boolean | description: Whether the redirect matches every path under its `from` path, carrying the rest of the URL over to the target. For example, a group redirect from `/forum/questions/` to `/forum/faqs/` sends `/forum/questions/my-post` to `/forum/faqs/my-post`. When `false`, only the exact `from` path matches.  A group redirect and an exact redirect that share a `from` path are two different redirects.  Default: `false`  
        - name: language | type: string | description: Language version of a multilingual site that the redirect applies to, as a 2-letter language code or a language tag. For example, `fr` or `en-US`.  When omitted, the redirect applies to every language on the site. A redirect scoped to a language conflicts only with redirects in the same language and with redirects that apply to every language.  Deleting a redirect scoped to a language stops it taking effect, but it can still appear in [List Redirects](https://dev.wix.com/docs/api-reference/business-management/seo/redirects/redirect-v1/list-redirects.md).  | validation: minLength 2, maxLength 5
        - name: id | type: string | description: Redirect GUID.  You can specify your own GUID when creating a redirect. When omitted, an GUID is generated.  | validation: format GUID
 Return type: CreateRedirectResponse
  - name: redirect | type: Redirect | description: Created redirect.  `createdDate` isn't returned. When the site already has an identical redirect, the redirect from the request is returned as is, without an `id`.  
     - name: from | type: string | description: Path on the site that the redirect starts from, URL-encoded. For example, `/old-page`.  Can't be the site root. A path that differs from another redirect's `from` path only by a trailing slash counts as the same path.  For a redirect scoped to a `language`, specify the path with or without the language prefix: the prefix is stripped, so a `fr` redirect from `/fr/about` is stored and returned as `/about`.  | validation: maxLength 950
     - name: to | type: string | description: Where the redirect sends the visitor, URL-encoded. Either a path on the site, such as `/new-page`, or a full URL, such as `https://example.com/page`.  | validation: maxLength 4096
     - name: options | type: RedirectOptions | description: How the redirect matches the paths a visitor requests.  
        - name: groupRedirect | type: boolean | description: Whether the redirect matches every path under its `from` path, carrying the rest of the URL over to the target. For example, a group redirect from `/forum/questions/` to `/forum/faqs/` sends `/forum/questions/my-post` to `/forum/faqs/my-post`. When `false`, only the exact `from` path matches.  A group redirect and an exact redirect that share a `from` path are two different redirects.  Default: `false`  
     - name: language | type: string | description: Language version of a multilingual site that the redirect applies to, as a 2-letter language code or a language tag. For example, `fr` or `en-US`.  When omitted, the redirect applies to every language on the site. A redirect scoped to a language conflicts only with redirects in the same language and with redirects that apply to every language.  Deleting a redirect scoped to a language stops it taking effect, but it can still appear in [List Redirects](https://dev.wix.com/docs/api-reference/business-management/seo/redirects/redirect-v1/list-redirects.md).  | validation: minLength 2, maxLength 5
     - name: id | type: string | description: Redirect GUID.  You can specify your own GUID when creating a redirect. When omitted, an GUID is generated.  | validation: format GUID
     - name: createdDate | type: string | description: Date and time the redirect was created.  Not returned by [Create Redirect](https://dev.wix.com/docs/api-reference/business-management/seo/redirects/redirect-v1/create-redirect.md). Call [Get Redirect](https://dev.wix.com/docs/api-reference/business-management/seo/redirects/redirect-v1/get-redirect.md) or [List Redirects](https://dev.wix.com/docs/api-reference/business-management/seo/redirects/redirect-v1/list-redirects.md) to retrieve it.  | read-only: true | validation: format date-time

 Possible Errors:
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code:  | Description: The `redirect` is missing, or one of its fields is invalid. The `from` path can't be the site root. Details are in `fieldViolations`.
   HTTP Code: 409 | Status Code: ALREADY_EXISTS | Application Code: FROM_URL_EXISTS | Description: There's already a redirect from this `from` path. Nothing is written. The existing redirect's `from`, `to`, and `options` are returned in the error's `data`. To replace it, set `options.forceReplace` to `true`.


```

### Examples

### Create a group redirect for a whole section of a site
A group redirect carries the rest of the URL over to the target, so `/forum/questions/my-post` resolves to `/forum/faqs/my-post`. A trailing slash is dropped from the stored `from` path, and `createdDate` isn't returned. Call Get Redirect to retrieve it.

```curl
curl -X POST \
'https://www.wixapis.com/seo-redirects-service/v1/create-redirect' \
-H 'Authorization: <AUTH>' \
-H 'Content-Type: application/json' \
-d '{
  "redirect": {
    "from": "/forum/questions/",
    "to": "/forum/faqs/",
    "options": { "groupRedirect": true }
  }
}'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.seo.redirects.createRedirect(redirect, options)
 Description: Creates a redirect.  The `from` path can't be the site root, and can't already belong to another redirect unless `options.forceReplace` is `true`. With `options.forceReplace`, the redirect that holds the path is deleted and the new one is created in its place.  If the redirect would close a loop, meaning an existing redirect starts at the path this one points to, the redirect that closes the loop is deleted and the create proceeds. Both a conflicting redirect replaced this way and a loop-closing redirect are gone for good, so retrieve them first if you need to restore them.  Creating a redirect that already exists with the same `from`, `to`, and `options.groupRedirect` changes nothing and returns the redirect from the request, without an `id` or a `createdDate`.  To create multiple redirects in a single API call, call [Bulk Create Redirects](https://dev.wix.com/docs/api-reference/business-management/seo/redirects/redirect-v1/bulk-create-redirects.md). Note the difference in how the two handle problems: this method resolves loops and, with `options.forceReplace`, conflicts, while [Bulk Create Redirects](https://dev.wix.com/docs/api-reference/business-management/seo/redirects/redirect-v1/bulk-create-redirects.md) fails the individual redirect instead.
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  redirect
 Method parameters: 
   param name: options | type: CreateRedirectOptions  none  
        - name: options | type: CreateRedirectOptions | description: Extra options for creating the redirect.  
           - name: forceReplace | type: boolean | description: Whether to delete the redirect that already starts from the same `from` path and create the new one in its place. When `false`, a taken `from` path fails the call with `FROM_URL_EXISTS`.  The replaced redirect is deleted for good, so retrieve it first if you might need to restore it.  Default: `false`  
   param name: redirect | type: Redirect | description: A redirect sends a visitor who requests one path on a site to another path or URL.  Redirects keep old links working after a page is renamed or removed, consolidate duplicate URLs, and point a whole section of a site somewhere else. A redirect returns a 301 permanent redirect, takes effect on the live site immediately with no site publish, and takes precedence over a page that exists at the same path.  A redirect either matches its `from` path exactly, or matches everything under it when `options.groupRedirect` is `true`. A redirect scoped to a `language` applies to that language version of a multilingual site, and one with no `language` applies to every language. | required: true 
        - name: from | type: string | description: Path on the site that the redirect starts from, URL-encoded. For example, `/old-page`.  Can't be the site root. A path that differs from another redirect's `from` path only by a trailing slash counts as the same path.  For a redirect scoped to a `language`, specify the path with or without the language prefix: the prefix is stripped, so a `fr` redirect from `/fr/about` is stored and returned as `/about`.  | validation: maxLength 950
        - name: to | type: string | description: Where the redirect sends the visitor, URL-encoded. Either a path on the site, such as `/new-page`, or a full URL, such as `https://example.com/page`.  | validation: maxLength 4096
        - name: options | type: RedirectOptions | description: How the redirect matches the paths a visitor requests.  
           - name: groupRedirect | type: boolean | description: Whether the redirect matches every path under its `from` path, carrying the rest of the URL over to the target. For example, a group redirect from `/forum/questions/` to `/forum/faqs/` sends `/forum/questions/my-post` to `/forum/faqs/my-post`. When `false`, only the exact `from` path matches.  A group redirect and an exact redirect that share a `from` path are two different redirects.  Default: `false`  
        - name: language | type: string | description: Language version of a multilingual site that the redirect applies to, as a 2-letter language code or a language tag. For example, `fr` or `en-US`.  When omitted, the redirect applies to every language on the site. A redirect scoped to a language conflicts only with redirects in the same language and with redirects that apply to every language.  Deleting a redirect scoped to a language stops it taking effect, but it can still appear in [List Redirects](https://dev.wix.com/docs/api-reference/business-management/seo/redirects/redirect-v1/list-redirects.md).  | validation: minLength 2, maxLength 5
        - name: _id | type: string | description: Redirect GUID.  You can specify your own GUID when creating a redirect. When omitted, an GUID is generated.  | validation: format GUID
 Return type: PROMISE<Redirect>
  - name: from | type: string | description: Path on the site that the redirect starts from, URL-encoded. For example, `/old-page`.  Can't be the site root. A path that differs from another redirect's `from` path only by a trailing slash counts as the same path.  For a redirect scoped to a `language`, specify the path with or without the language prefix: the prefix is stripped, so a `fr` redirect from `/fr/about` is stored and returned as `/about`.  | validation: maxLength 950
  - name: to | type: string | description: Where the redirect sends the visitor, URL-encoded. Either a path on the site, such as `/new-page`, or a full URL, such as `https://example.com/page`.  | validation: maxLength 4096
  - name: options | type: RedirectOptions | description: How the redirect matches the paths a visitor requests.  
     - name: groupRedirect | type: boolean | description: Whether the redirect matches every path under its `from` path, carrying the rest of the URL over to the target. For example, a group redirect from `/forum/questions/` to `/forum/faqs/` sends `/forum/questions/my-post` to `/forum/faqs/my-post`. When `false`, only the exact `from` path matches.  A group redirect and an exact redirect that share a `from` path are two different redirects.  Default: `false`  
  - name: language | type: string | description: Language version of a multilingual site that the redirect applies to, as a 2-letter language code or a language tag. For example, `fr` or `en-US`.  When omitted, the redirect applies to every language on the site. A redirect scoped to a language conflicts only with redirects in the same language and with redirects that apply to every language.  Deleting a redirect scoped to a language stops it taking effect, but it can still appear in [List Redirects](https://dev.wix.com/docs/api-reference/business-management/seo/redirects/redirect-v1/list-redirects.md).  | validation: minLength 2, maxLength 5
  - name: _id | type: string | description: Redirect GUID.  You can specify your own GUID when creating a redirect. When omitted, an GUID is generated.  | validation: format GUID
  - name: _createdDate | type: Date | description: Date and time the redirect was created.  Not returned by [Create Redirect](https://dev.wix.com/docs/api-reference/business-management/seo/redirects/redirect-v1/create-redirect.md). Call [Get Redirect](https://dev.wix.com/docs/api-reference/business-management/seo/redirects/redirect-v1/get-redirect.md) or [List Redirects](https://dev.wix.com/docs/api-reference/business-management/seo/redirects/redirect-v1/list-redirects.md) to retrieve it.  | read-only: true 

 Possible Errors:
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code:  | Description: The `redirect` is missing, or one of its fields is invalid. The `from` path can't be the site root. Details are in `fieldViolations`.
   HTTP Code: 409 | Status Code: ALREADY_EXISTS | Application Code: FROM_URL_EXISTS | Description: There's already a redirect from this `from` path. Nothing is written. The existing redirect's `from`, `to`, and `options` are returned in the error's `data`. To replace it, set `options.forceReplace` to `true`.


```

### Examples

### Create a group redirect for a whole section of a site
A group redirect carries the rest of the URL over to the target, so `/forum/questions/my-post` resolves to `/forum/faqs/my-post`. A trailing slash is dropped from the stored `from` path.

```javascript
import { redirects } from "@wix/seo";

async function createRedirect() {
  const response = await redirects.createRedirect({
    from: "/forum/questions/",
    to: "/forum/faqs/",
    options: { groupRedirect: true },
  });
}

```

### createRedirect (self-hosted)
Self-hosted SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { redirects } from '@wix/seo';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { redirects },
  // Include the auth strategy and host as relevant
});


async function createRedirect(redirect,options) {
  const response = await myWixClient.redirects.createRedirect(redirect,options);
};
```

---