Child pages
  • cPanel API 1 Functions - Mime::add_redirect
Skip to end of metadata
Go to start of metadata

Description

This function adds a redirect to your .htaccess file.

Warning:

cPanel API 1 is deprecated. Do not use this function. Instead, we strongly recommend that you use the following newer functions:

Important:

In cPanel & WHM version 76 and later, when you disable the WebServer role, the system disables this function. For more information, read our How to Use Server Profiles documentation.

Examples 


 LiveAPI PHP Class
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
$add_redirect = $cpanel->api1('Mime', 'add_redirect', array('http://www.example.com/redirect-me','permanent','http://www.example.com/go-here-instead','example.com','0','0') ); // Call the function.


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.
my $add_redirect = $cpliveapi->api1('Mime', 'add_redirect', ['http://www.example.com/redirect-me','permanent','http://www.example.com/go-here-instead','example.com','0','0'] ); # Call the function.


Note:

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

 cPanel Tag System (deprecated)


Warning:

In cPanel & WHM version 11.30 and later, cPanel tags are deprecated. We provide this example to help developers move from the old cPanel tag system to our LiveAPI system. We strongly recommend that you only use the LiveAPI system to call the cPanel APIs.

<cpanel Module="Mime::add_redirect( $FORM('src','type','url','domain',wildcard',rdwww') )">
 Command Line
cpapi1 --user=username Mime add_redirect http://www.example.com/redirect-me permanent http://www.example.com/go-here-instead example.com 0 0


Notes:

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

    /usr/local/cpanel/bin/cpapi1

 Output (none)

This function does not return output.

Parameters

ParameterTypeDescriptionPossible ValuesExample
src
string

Required

The URL to redirect.

Any valid URL.
http://www.example.com/redirect-me
type
string

Required

Whether the redirect is temporary or permanent.

  • temp - use return code 301  — The redirect is temporary.
  • permanent - use return code 302  — The redirect is permanent.
temp - use return code 301
urlstring

Required

The URL to which to redirect the visitor.

A valid URL.
http://www.example.com/go-here-instead
domainstring

Required

The domain to which to redirect visitors.

A valid domain.

Note:

To redirect all of the account's domains, use a period followed by an asterisk. (.*) 

example.com
wildcardBooleanWhether to apply the redirect to all subdomains of the specified domain.
  • 1 — Redirect all subdomains.
  • 0 — Do not redirect subdomains.
0
rdwwwintegerWhether to apply the redirect to domains with and without the www hostname.
  • 2 — Redirect redirect only www. hostname.
  • 1 — Redirect all but www. hostname.
  • 0 — Redirect with or without www. hostname.
0

Returns

This function does not return output.