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

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.

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. <Redirect> makes a request to http://www.foo.com/nextInstructions and transfers control to the TwiML returned from that request.

Loading Code Samples...
Language
Format:
  • XML
  • TwiML
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("http://www.foo.com/nextInstructions").build();
        VoiceResponse response = new VoiceResponse.Builder().redirect(redirect)
            .build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
from twilio.twiml.voice_response import Redirect, VoiceResponse

response = VoiceResponse()
response.redirect('http://www.foo.com/nextInstructions')

print(response)
const VoiceResponse = require('twilio').twiml.VoiceResponse;

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

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


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

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

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

echo $response;
require 'twilio-ruby'

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

puts response
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Redirect>
        http://www.foo.com/nextInstructions
    </Redirect>
</Response>
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Redirect>
        http://www.foo.com/nextInstructions
    </Redirect>
</Response>
Absolute URL redirect

Example 2: Relative URL redirect

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

Loading Code Samples...
Language
Format:
  • XML
  • TwiML
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();
        }
    }
}
from twilio.twiml.voice_response import Redirect, VoiceResponse

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

print(response)
const VoiceResponse = require('twilio').twiml.VoiceResponse;

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

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


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

        System.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
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Redirect>
        ../nextInstructions
    </Redirect>
</Response>
<?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...
Format:
  • XML
  • TwiML
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("http://www.foo.com/nextInstructions").build();
        VoiceResponse response = new VoiceResponse.Builder().redirect(redirect)
            .build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
from twilio.twiml.voice_response import Redirect, VoiceResponse

response = VoiceResponse()
response.redirect('http://www.foo.com/nextInstructions')

print(response)
const VoiceResponse = require('twilio').twiml.VoiceResponse;

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

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


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

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

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

echo $response;
require 'twilio-ruby'

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

puts response
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Redirect>
        http://www.foo.com/nextInstructions
    </Redirect>
</Response>
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Redirect>
        http://www.foo.com/nextInstructions
    </Redirect>
</Response>
Format:
  • XML
  • TwiML
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();
        }
    }
}
from twilio.twiml.voice_response import Redirect, VoiceResponse

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

print(response)
const VoiceResponse = require('twilio').twiml.VoiceResponse;

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

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


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

        System.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
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Redirect>
        ../nextInstructions
    </Redirect>
</Response>
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Redirect>
        ../nextInstructions
    </Redirect>
</Response>