DNS /Rewrite? - Customizing the webmail urls for multiple domains on a single box?

I have multiple domains on a single box. Is there a way that I can create unique urls for accessing Roundcube?

eg

webmail.domain1.com -> box1.domaina.com/webmail
webmail.domain2.com -> box1.domaina.com/webmail

Can i create an Apache rewrite rule to accomplish this? Other thoughts?

You can create a dummy mail alias example@webmail.domain1.com for each domain that you have. Then go to the web section of the admin interface and configure a custom web path there. Finally put an index.php file into the directory on the server and fill its contents with:

<?php
header("Location: https://box1.domaina.com/webmail");
?>

You can also create a single folder on the server, for example webmail-redirect and put the file in there. Then after doing the admin interface step you can delete the folder you had to create and create a symbolic link to the webmail-redirect folder instead.

cd /home/user-data/www
rmdir webmail.domain1.com
ln -s webmail-redirect webmail.domain1.com

This way you will have the php file on the server just once and all domains will use the same redirect, which makes it easier to change later.

Is there a way to do this without using php?

You can use a JavaScript or HTML-based redirect instead but they would be client-dependent.

The only alternative is to directly adjust the nginx configuration but that is not supported by mail-in-a-box.

@peternemser for HTML Redirect:

<html>
<head>
<meta http-equiv="refresh" content="0; url=http://example.com/" />
</head>
</html>
2 Likes

Apologies for reviving a super old topic, but I just wanted to say that @murgero’s HTML redirect also served the purpose of fixing a related annoyance of mine. I modified the HTML code as follows:

<html>
<head>
<meta http-equiv="refresh" content="0; url=/admin" />
</head>
</html>

This made it so that box.example.com redirects to box.example.com/admin, which is convenient because web browsers only autocomplete the domain name, so I don’t have to manually type the “/admin” at the end anymore.

FWIW I think the above code might be a reasonable default for the default subdomains, rather than the “This is a Mail in a Box” text, which makes more sense for custom, per-user subdomains.

1 Like

You can actually create a custom.yaml file in /home/user-data/www/

mydomain:
  redirects:
    ^/$: $scheme://mydomain/mail

Then you need to go into mailinabox/management and do sudo ./mailinabox/tools/web_update to refresh the dns

This solution does not get overwritten during upgrades.

Is this a relatively new feature? at the time I posted my solution, I don’t believe MIAB had the option for custom configurations like that.

it was available at least since 2014, but it’s a hidden feature.

1 Like