Skip to main content

Redirect automatically created subdomains to the real addon domains dynamically

Comments

5 comments

  • cPRex Jurassic Moderator

    Hey there!  Unfortunately no, there isn't going to be a global way to redirect these.  As you've found, you need to know both the source and destination domains and those document roots will change depending on how the domain is configured.

    Are you getting abnormal traffic to these domains on the system?  Unless a bot is crawling things, a user would need to manually type in "addon.domain.com" instead of "addondomain.com" in order to visit that page, which seems to be uncommon.

    0
  • frzsombor

    Hey cPRex,

    Yes, I was indeed receiving some traffic on a cPanel-related subdomain. While it wasn’t anything serious or disruptive, I like to keep things clean, this is why I was wondering if there’s a quick and universal solution I can apply across all accounts and domains to prevent any unexpected issues.

    0
  • cPRex Jurassic Moderator

    Update - one of our developers has been looking into a solution for this so we've created case CPANEL-46168 to see if there is a good way to workaround this behavior.

    If I hear any updates on my end I'll be sure to post them here.

    0
  • frzsombor

    Wow, that sounds great, thanks for caring about this issue too!

    In the meantime - as most of our websites are custom WordPress sites developed by us and all contains our "core" plugin, - I've implemented a (WordPress only) solution with PHP in our plugin. This way, we don't have to manually edit any server/cPanel/account settings or files, just update our core plugin in all our customers' websites (which we do regularly anyways).

    If anyone finds this topic in the future and uses WordPress, here is the code:

    $server_name = $_SERVER['SERVER_NAME'];
    $server_host = explode( ':', $server_name )[0] ?? '';
    $wp_home_parsed = wp_parse_url( home_url() );

    if ( $server_host
    && $server_host !== $wp_home_parsed['host']
    && $server_host !== 'www.' . $wp_home_parsed['host']
    ) {
    header('HTTP/1.0 403 Forbidden');
    exit;
    }
    0
  • cPRex Jurassic Moderator

    Thanks for sharing!

    0

Please sign in to leave a comment.