buy
Add Redirect

Description

This API allows the end user to Create a Domain Redirect (Forwarder) for a domain hosted under their account.

You can specify the domain, path, redirect type, and destination URL where the request should be redirected.

Parameters

Sample Code

curl --insecure -u "username:password" -X POST "https://hostname:2003/index.php?api=json&act=redirects" -d "add=1" -d "selectdomain=example.com" -d "path=" -d "type=temporary" -d "address=https://example2.com"
<?php

$user = 'username';
$pass = 'password';
$ip   = 'hostname';

// API URL
$url = 'https://'.rawurlencode($user).':'.rawurlencode($pass).'@'.$ip.':2003/index.php?api=json&act=redirects';

// POST parameters
$post = array(
    'add' => '1',
    'selectdomain' => 'example.com',
    'path' => '',
    'type' => 'temporary',
    'address' => 'https://example.com'
);

// Initialize cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Send POST request
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));

// Execute request
$resp = curl_exec($ch);

if(curl_errno($ch)){
    echo 'Curl error: '.curl_error($ch);
}

curl_close($ch);

// Decode JSON response
$res = json_decode($resp, true);

// Done ?
if(!empty($res['done'])){
    print_r($res['done']);
}else{
    print_r($res['error']);
}

?>

Output

"done": {
    "msg": "Redirect added"
  }
    Was this page helpful?
    Newsletter Subscription
    Subscribing you to the mailing list