The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

cPanel setredirecturl api function

Discussion in 'cPanel Developers' started by swbrains, Oct 5, 2016.

  1. swbrains

    swbrains Active Member

    Joined:
    Sep 13, 2006
    Messages:
    38
    Likes Received:
    2
    Trophy Points:
    8
    Hi,

    I'm having a tough time figuring out how to set the redirect URL for a domain I've just parked. I don't seem to be able to do it via the API (v2) when parking the domain, and the only other function that seems to do this is Park::setredirecturl in v1 of the API. But I can't for the life of me figure out how to format the command line to work properly. I'm calling it from Perl using LWP to send a GET request and my URL looks like this:

    "http://$domain:2082/xml-api/cpanel?...ion=1&domain=$parkdomain&topdomain=$forwardto";

    But I get an error "Could not find function 'setredirecturl' in module 'Park'" and the XML returns version 2 of the API. So I guess it makes sense that the function doesn't exist since it's not in v2 and the API thinks I'm calling a v2 function even though I specified v1

    Looking at some examples in the docs, I also tried this format:

    http://$domain:2086/xml-api/setredi...$user&domain=$parkdomain&topdomain=$forwardto

    But that returns the error "Unknown app (setredirecturll) requested for this version (1) of the API. " The docs say it's in module "Park" but I don't see where to specify the module in the version 1 format of the command I'm using.

    Can anyone suggest how to accomplish parking a domain with a redirect to another http: URL via the API?

    Thanks!
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    648
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello,

    You might find the following UAPI functions helpful for this purpose:

    UAPI Functions - Mime::list_redirects - Software Development Kit - cPanel Documentation
    UAPI Functions - Mime::delete_redirect - Software Development Kit - cPanel Documentation
    UAPI Functions - Mime::add_redirect - Software Development Kit - cPanel Documentation

    This will allow you to list the current redirect for a domain alias (parked domain), delete it, and add a new one with the URL of your preference. Using the UAPI command-line functionality as an example, let's say "cptest02.tld" is our alias. We can obtain information such it's target URL and current document root if a redirect already exists via a command such as:

    Code:
    uapi --user=$cpanel-username Mime list_redirects
    Then, if a redirect exists for this domain name, it's possible to delete it via a command such as:

    Code:
    uapi --user=$cpanel-username Mime delete_redirect domain=cptest02.tld docroot=/home/$cpanel-username/public_html
    Finally, you can add the new redirect with a command such as:

    Code:
    uapi --user=$cpanel-username Mime add_redirect domain=cptest02.tld redirect=http%3A%2F%2Fgoogle.tld%2F type=permanent redirect_wildcard=1 redirect_www=0
    Let us know if this helps.

    Thank you.
     
Loading...

Share This Page