Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

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

attributes page anchor

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

Attribute NameAllowed ValuesDefault Value
methodGET, POSTPOST

method

attributes-method page anchor

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:

Using method attribute in a Redirect verb

using-method-attribute-in-a-redirect-verb page anchor
Node.js
Python
C#
Java
PHP
Ruby

_10
const VoiceResponse = require('twilio').twiml.VoiceResponse;
_10
_10
_10
const response = new VoiceResponse();
_10
response.redirect({
_10
method: 'POST'
_10
}, 'http://pigeons.com/twiml.xml');
_10
_10
console.log(response.toString());

Output

_10
<?xml version="1.0" encoding="UTF-8"?>
_10
<Response>
_10
<Redirect method="POST">http://pigeons.com/twiml.xml</Redirect>
_10
</Response>


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(link takes you to an external page) for <Redirect>:

NounTwiML Interpretation
plain textAn absolute or relative URL for a different TwiML document.

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


Example 1: Absolute URL Redirect

examples-1 page anchor

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(link takes you to an external page) and transfers the call flow to the TwiML received in response to that request.

Node.js
Python
C#
Java
PHP
Ruby

_10
const VoiceResponse = require('twilio').twiml.VoiceResponse;
_10
_10
_10
const response = new VoiceResponse();
_10
response.dial('415-123-4567');
_10
response.redirect('http://www.foo.com/nextInstructions');
_10
_10
console.log(response.toString());

Output

_10
<?xml version="1.0" encoding="UTF-8"?>
_10
<Response>
_10
<Dial>415-123-4567</Dial>
_10
<Redirect>http://www.foo.com/nextInstructions</Redirect>
_10
</Response>

Example 2: Relative URL Redirect

examples-2 page anchor

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

Node.js
Python
C#
Java
PHP
Ruby

_10
const VoiceResponse = require('twilio').twiml.VoiceResponse;
_10
_10
_10
const response = new VoiceResponse();
_10
response.redirect('../nextInstructions');
_10
_10
console.log(response.toString());

Output

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


Rate this page: