TwiML™ Voice: <Redirect>

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

Verb Attributes

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

Attribute Name Allowed Values Default Value
method GET, POST POST

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.

Use it in a <Redirect> verb like so:

Loading Code Samples...
Language
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
response.redirect({
    method: 'POST'
}, 'http://pigeons.com/twiml.xml');

console.log(response.toString());
using Twilio.TwiML;
using Twilio.Http;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        response.Redirect(new Uri("http://pigeons.com/twiml.xml"), method: HttpMethod.Post);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\Twiml;

$response = new Twiml();
$response->redirect('http://pigeons.com/twiml.xml', ['method' => 'POST']);

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.redirect('http://pigeons.com/twiml.xml', method: 'POST')

puts response
from twilio.twiml.voice_response import Redirect, VoiceResponse

response = VoiceResponse()
response.redirect('http://pigeons.com/twiml.xml', method='POST')

print(response)
import com.twilio.twiml.Redirect;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.TwiMLException;
import com.twilio.twiml.Method;

public class Example {
    public static void main(String[] args) {
        Redirect redirect = new Redirect.Builder().method(Method.POST)
            .url("http://pigeons.com/twiml.xml").build();
        VoiceResponse response = new VoiceResponse.Builder().redirect(redirect)
            .build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Redirect method="POST">http://pigeons.com/twiml.xml</Redirect>
</Response>
Using method attribute in a Redirect verb

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 for <Redirect>:

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

Nesting Rules

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

Examples

Example 1: Absolute URL Redirect

In this example, we have a <Redirect> verb after a <Dial> verb with no URL. When the <Dial> verb finishes, the <Redirect> executes. <Redirect> makes a request to http://www.foo.com/nextInstructions and transfers the call flow to the TwiML received in response to that request.

Loading Code Samples...
Language
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
response.dial('415-123-4567');
response.redirect('http://www.foo.com/nextInstructions');

console.log(response.toString());
using Twilio.TwiML;
using System;

class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        response.Dial("415-123-4567");
        response.Redirect(new Uri("http://www.foo.com/nextInstructions"));

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\Twiml;

$response = new Twiml();
$response->dial('415-123-4567');
$response->redirect('http://www.foo.com/nextInstructions');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial(number: '415-123-4567')
response.redirect('http://www.foo.com/nextInstructions')

puts response
from twilio.twiml.voice_response import Dial, Redirect, VoiceResponse

response = VoiceResponse()
response.dial('415-123-4567')
response.redirect('http://www.foo.com/nextInstructions')

print(response)
import com.twilio.twiml.Dial;
import com.twilio.twiml.Number;
import com.twilio.twiml.Redirect;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Number number = new Number.Builder("415-123-4567").build();
        Dial dial = new Dial.Builder().number(number).build();
        Redirect redirect = new Redirect.Builder()
            .url("http://www.foo.com/nextInstructions").build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial)
            .redirect(redirect).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial>415-123-4567</Dial>
    <Redirect>http://www.foo.com/nextInstructions</Redirect>
</Response>
Absolute URL Redirect

Example 2: Relative URL Redirect

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

Loading Code Samples...
Language
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

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

console.log(response.toString());
using Twilio.TwiML;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        response.Redirect(new Uri("../nextInstructions"));

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\Twiml;

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

echo $response;
require 'twilio-ruby'

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

puts response
from twilio.twiml.voice_response import Redirect, VoiceResponse

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

print(response)
import com.twilio.twiml.Redirect;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.TwiMLException;


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

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Redirect>../nextInstructions</Redirect>
</Response>
Relative URL Redirect

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.

1 / 1
Loading Code Samples...
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
response.redirect({
    method: 'POST'
}, 'http://pigeons.com/twiml.xml');

console.log(response.toString());
using Twilio.TwiML;
using Twilio.Http;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        response.Redirect(new Uri("http://pigeons.com/twiml.xml"), method: HttpMethod.Post);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\Twiml;

$response = new Twiml();
$response->redirect('http://pigeons.com/twiml.xml', ['method' => 'POST']);

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.redirect('http://pigeons.com/twiml.xml', method: 'POST')

puts response
from twilio.twiml.voice_response import Redirect, VoiceResponse

response = VoiceResponse()
response.redirect('http://pigeons.com/twiml.xml', method='POST')

print(response)
import com.twilio.twiml.Redirect;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.TwiMLException;
import com.twilio.twiml.Method;

public class Example {
    public static void main(String[] args) {
        Redirect redirect = new Redirect.Builder().method(Method.POST)
            .url("http://pigeons.com/twiml.xml").build();
        VoiceResponse response = new VoiceResponse.Builder().redirect(redirect)
            .build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Redirect method="POST">http://pigeons.com/twiml.xml</Redirect>
</Response>
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
response.dial('415-123-4567');
response.redirect('http://www.foo.com/nextInstructions');

console.log(response.toString());
using Twilio.TwiML;
using System;

class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        response.Dial("415-123-4567");
        response.Redirect(new Uri("http://www.foo.com/nextInstructions"));

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\Twiml;

$response = new Twiml();
$response->dial('415-123-4567');
$response->redirect('http://www.foo.com/nextInstructions');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.dial(number: '415-123-4567')
response.redirect('http://www.foo.com/nextInstructions')

puts response
from twilio.twiml.voice_response import Dial, Redirect, VoiceResponse

response = VoiceResponse()
response.dial('415-123-4567')
response.redirect('http://www.foo.com/nextInstructions')

print(response)
import com.twilio.twiml.Dial;
import com.twilio.twiml.Number;
import com.twilio.twiml.Redirect;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Number number = new Number.Builder("415-123-4567").build();
        Dial dial = new Dial.Builder().number(number).build();
        Redirect redirect = new Redirect.Builder()
            .url("http://www.foo.com/nextInstructions").build();
        VoiceResponse response = new VoiceResponse.Builder().dial(dial)
            .redirect(redirect).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial>415-123-4567</Dial>
    <Redirect>http://www.foo.com/nextInstructions</Redirect>
</Response>
SDK Version:
  • 5.x
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

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

console.log(response.toString());
using Twilio.TwiML;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        response.Redirect(new Uri("../nextInstructions"));

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\Twiml;

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

echo $response;
require 'twilio-ruby'

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

puts response
from twilio.twiml.voice_response import Redirect, VoiceResponse

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

print(response)
import com.twilio.twiml.Redirect;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.TwiMLException;


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

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Redirect>../nextInstructions</Redirect>
</Response>