You can find our user documentation at docs.cpanel.net.

Check out our new API beta site!

Child pages
  • UAPI Functions - DomainAliases::set_redirect_url
Skip to end of metadata
Go to start of metadata

Description

This function redirects a domain alias (parked domain) to a URL.


Examples 


 cPanel or Webmail Session URL
https://hostname.example.com:2083/cpsess##########/execute/DomainAliases/set_redirect_url?domain=example.com&url=https://www.targetdomain.com


Note:

This example calls the UAPI function via a cPanel session. For more information, read our Guide to UAPI documentation. 

 LiveAPI PHP Class
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
 
// Set redirection for a domain alias
$setredirecton = $cpanel->uapi(
    'DomainAliases', 'set_redirect_url'
    array(
        'domain'           => 'example.com',
        'url'              => 'https://www.targetdomain.com',
    )
);


Note:

For more information, read our Guide to the LiveAPI System.


 LiveAPI Perl Module
my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
 
# Set redirection for a domain alias
my $setredirecton = $cpliveapi->uapi(
    'DomainAliases', 'set_redirect_url',
    {
        'domain'           => 'example.com',
        'url'              => 'https://www.targetdomain.com',
    }
);


Note:

For more information, read our Guide to the LiveAPI System.


 Command Line
uapi --user=username DomainAliases set_redirect_url domain=example.com url=https://www.targetdomain.com


Notes:

  • You must URI-encode values.
  • username represents your account-level username.
  • For more information and additional output options, read our Guide to UAPI documentation or run the uapi --help command. 
  • If you run CloudLinux™, you must use the full path of the uapi command:

    /usr/local/cpanel/bin/uapi


 Output (JSON)
{
    "messages": null,
    "errors": null,
    "status": 1,
    "metadata": {},
    "data": {
       "redirection_enabled": 1
     }
}


Note:

Use cPanel's API Shell interface (cPanel >> Home >> Advanced >> API Shell) to directly test cPanel API calls.

   

Parameters

ParameterTypeDescriptionPossible valuesExample
domainstring

Required

The name of the domain alias.

A valid domain alias that exists on the account.
example.com
urlstring

The target URL to which to redirect the domain alias.

This parameter defaults to null.

  • A valid URL.
  • null — Disables redirection for the domain.
http://www.targetdomain.com

Returns

ParameterTypeDescriptionPossible valuesExample
redirection_enabledBoolean

Whether the domain alias redirects.

  • 1 — The domain alias redirects.
  • 0 — The domain alias does not redirect.
1