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

Check out our new API beta site!

Child pages
  • UAPI Functions - Mime::add_redirect
Skip to end of metadata
Go to start of metadata

Description

This function adds a redirect to a domain.

Important:

In cPanel & WHM version 76 and later, when you disable the Web Server role, the system disables this function.

Examples 


 cPanel or Webmail Session URL
https://hostname.example.com:2083/cpsess##########/execute/Mime/add_redirect?domain=example.com&src=%2Fspecific-page&redirect=http%3A%2F%2Fexample2.com&redirect_wildcard=1&redirect_www=0&type=permanent


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.
 
//   Add a redirect to the example.com domain
$mime_add_redirect = $cpanel->uapi(
    'Mime', 'add_redirect',
    array(
        'domain'            => 'example.com',
        'src'               => '/specific-page',
        'redirect'          => 'http://example.com/',
        'type'              => 'permanent',
        'redirect_wildcard' => '1',
        'redirect_www'      => '0',
 )
);


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.
 
#   Add a redirect to the example.com domain
my $mime_add_redirect = $cpliveapi->uapi(
    'Mime', 'add_redirect',
    {
        'domain'            => 'example.com',
        'src'               => '/specific-page',
        'redirect'          => 'http://example.com/',
        'type'              => 'permanent',
        'redirect_wildcard' => '1',
        'redirect_www'      => '0',
    }
);


Note:

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

 Command Line
uapi --user=username Mime add_redirect domain=example.com src=/specified-page redirect=http://example.com type=permanent redirect_wildcard=1 redirect_www=0


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)
{  
   "status":1,
   "warnings":null,
   "errors":null,
   "metadata":{  

   },
   "messages":[  
      "Htaccess Installed"
   ],
   "data":null
}


Note:

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

Parameters

ParameterTypeDescriptionPossible valuesExample
domainstring

Required

The domain from which to redirect.

A valid domain on the server.


example.com
src
string

A specific page from which to redirect.

This value defaults to /.

A valid path, relative to the domain.
/specific-page
redirect
string

Required

The URL to which to redirect.

A valid URL.
http://example.com/
type
string

Whether the redirect is temporary.

This value defaults to permanent.

  • permanent
  • temp
permanent
redirect_wildcard
Boolean

Whether to redirect all files within a directory to the same filename within the destination directory.

This value defaults to 0.

  • 1 — Redirect all files within the directory.
  • 0 — Do not redirect all files within the directory.
1
redirect_www
integer

Whether to redirect domains with or without www.

This value defaults to 0.


  • 2 — Redirect with www.
  • 1 — Redirect without www.
  • 0 — Redirect with and without www.
0

Returns

This function only returns metadata.