Plesk

How to redirect webmail of all domains to a specific webmail URL in Plesk for Linux

Question

How to redirect webmail of all domains to a specific webmail URL in Plesk?

Answer

For this solution to work, all domains must use a single webmail client: Roundcube or Horde. To enable only one webmail in Plesk, go to Tools & Settings > Webmail and leave only one webmail client enabled.

 

  1. Connect to a Plesk server via SSH.

  2. Create a directory for custom configuration templates:

    # mkdir -p /usr/local/psa/admin/conf/templates/custom/webmail

  3. Copy the original file webmail.php to the created directory:

    # cp /usr/local/psa/admin/conf/templates/default/webmail/webmail.php /usr/local/psa/admin/conf/templates/custom/webmail/webmail.php

  4. Open the file /usr/local/psa/admin/conf/templates/custom/webmail/webmail.php in a text editor. In this example, we are using the vi editor:

    # vi /usr/local/psa/admin/conf/templates/custom/webmail/webmail.php

  5. Add the lines below before the lines 
    "<?php echo $VAR->includeTemplate('domain/PCI_compliance.php')
    ?>"
    (there are two of them):

    Note: Replace example.com with a domain name and webmail.example.com with a webmail URL that will be used as an entry point for all users.

    <?php
    if ($VAR->domain->asciiName !== 'example.com') { echo "Redirect permanent / https://webmail.example.com/"; }
    ?>

  6. Save the changes and close the file.

  7. Regenerate configuration files for all domains:

    Note: During this operation websites will be unavailable for a short period of time. The execution time of this command depends on the number of domains on the server.

    # plesk repair web -y