# TwiML™ SMS: \<Redirect>

The `<Redirect>` verb transfers control of a Message response to the TwiML at a different URL. All verbs after `<Redirect>` are unreachable and ignored.

## Verb Attributes \[#attributes]

The `<Redirect>` verb supports the following attributes that modify its behavior:

| Attribute Name               | Allowed Values | Default Value |
| :--------------------------- | :------------- | :------------ |
| [method](#attributes-method) | `GET`, `POST`  | `POST`        |

### method \[#attributes-method]

The 'method' attribute takes the value `GET` or `POST`. This tells Twilio whether to request the `<Redirect>` URL via HTTP `GET` or `POST`. `POST` is the default.

## Nouns \[#nouns]

The "noun" of a TwiML verb is the stuff nested within the verb that's not a verb itself; it's the stuff the verb acts upon. These are the [nouns](https://vimeo.com/2335546) for `<Redirect>`:

| Noun       | TwiML Interpretation                                        |
| ---------- | ----------------------------------------------------------- |
| plain text | An absolute or relative URL for a different TwiML document. |

## Nesting Rules \[#nesting-rules]

No verbs can be nested within `<Redirect>` and `<Redirect>` can't be nested in any other verbs.

## Examples \[#examples]

### Example 1: Absolute URL redirect \[#examples-1]

In this example, we have a `<Redirect>` verb. `<Redirect>` makes a request to `http://www.foo.com/nextInstructions` and transfers control to the TwiML returned from that request.

Absolute URL redirect

```js
const MessagingResponse = require('twilio').twiml.MessagingResponse;

const response = new MessagingResponse();
response.redirect('http://www.example.com/nextInstructions');

console.log(response.toString());
```

```py
from twilio.twiml.messaging_response import Redirect, MessagingResponse

response = MessagingResponse()
response.redirect('http://www.example.com/nextInstructions')

print(response)
```

```cs
using System;
using Twilio.TwiML;
using Twilio.TwiML.Messaging;


class Example
{
    static void Main()
    {
        var response = new MessagingResponse();
        response.Redirect(url: new Uri("http://www.example.com/nextInstructions"));

        Console.WriteLine(response.ToString());
    }
}
```

```java
import com.twilio.twiml.messaging.Redirect;
import com.twilio.twiml.MessagingResponse;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Redirect redirect = new Redirect.Builder("http://www.example.com/nextInstructions").build();
        MessagingResponse response = new MessagingResponse.Builder().redirect(redirect).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
```

```go
package main

import (
	"fmt"

	"github.com/twilio/twilio-go/twiml"
)

func main() {
	twiml, _ := twiml.Messages([]twiml.Element{
		&twiml.MessagingRedirect{
			Url: "http://www.example.com/nextInstructions",
		},
	})

	fmt.Print(twiml)
}
```

```php
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML\MessagingResponse;

$response = new MessagingResponse();
$response->redirect('http://www.example.com/nextInstructions');

echo $response;
```

```rb
require 'twilio-ruby'

response = Twilio::TwiML::MessagingResponse.new
response.redirect('http://www.example.com/nextInstructions')

puts response
```

```xml
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Redirect>
        http://www.example.com/nextInstructions
    </Redirect>
</Response>
```

### Example 2: Relative URL redirect \[#examples-2]

Redirects flow control to a TwiML at a URL relative to the current URL.

Relative URL redirect

```js
const MessagingResponse = require('twilio').twiml.MessagingResponse;

const response = new MessagingResponse();
response.redirect('../nextInstructions');

console.log(response.toString());
```

```py
from twilio.twiml.messaging_response import Redirect, MessagingResponse

response = MessagingResponse()
response.redirect('../nextInstructions')

print(response)
```

```cs
using System;
using Twilio.TwiML;
using Twilio.TwiML.Messaging;


class Example
{
    static void Main()
    {
        var response = new MessagingResponse();
        response.Redirect(url: new Uri("../nextInstructions", UriKind.Relative));

        Console.WriteLine(response.ToString());
    }
}
```

```java
import com.twilio.twiml.messaging.Redirect;
import com.twilio.twiml.MessagingResponse;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Redirect redirect = new Redirect.Builder("../nextInstructions").build();
        MessagingResponse response = new MessagingResponse.Builder().redirect(redirect).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
```

```go
package main

import (
	"fmt"

	"github.com/twilio/twilio-go/twiml"
)

func main() {
	twiml, _ := twiml.Messages([]twiml.Element{
		&twiml.MessagingRedirect{
			Url: "../nextInstructions",
		},
	})

	fmt.Print(twiml)
}
```

```php
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML\MessagingResponse;

$response = new MessagingResponse();
$response->redirect('../nextInstructions');

echo $response;
```

```rb
require 'twilio-ruby'

response = Twilio::TwiML::MessagingResponse.new
response.redirect('../nextInstructions')

puts response
```

```xml
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Redirect>
        ../nextInstructions
    </Redirect>
</Response>
```
