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

**URL:** <https://discourse.mailinabox.email/t/dns-rewrite-customizing-the-webmail-urls-for-multiple-domains-on-a-single-box/2436>\
**Category:** uncategorized\
**Created:** [August 24, 2017, 12:35am UTC](https://discourse.mailinabox.email/t/dns-rewrite-customizing-the-webmail-urls-for-multiple-domains-on-a-single-box/2436 "2017-08-24T00:35:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![peternemser](https://discourse.mailinabox.email/letter_avatar_proxy/v4/letter/p/e0b2c6/32.png) [@peternemser](https://discourse.mailinabox.email/u/peternemser)\
**Post date:** [August 24, 2017, 12:35am UTC](https://discourse.mailinabox.email/t/dns-rewrite-customizing-the-webmail-urls-for-multiple-domains-on-a-single-box/2436/1 "2017-08-24T00:35:05Z")

</div>

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](http://webmail.domain1.com) -\> [box1.domaina.com/webmail](http://box1.domaina.com/webmail)  
[webmail.domain2.com](http://webmail.domain2.com) -\> [box1.domaina.com/webmail](http://box1.domaina.com/webmail)

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

---

<div class="post-metadata">

**Author:** ![hachre](https://discourse.mailinabox.email/user_avatar/discourse.mailinabox.email/hachre/32/627_2.png) [@hachre](https://discourse.mailinabox.email/u/hachre)\
**Post date:** [August 24, 2017, 1:03am UTC](https://discourse.mailinabox.email/t/dns-rewrite-customizing-the-webmail-urls-for-multiple-domains-on-a-single-box/2436/2 "2017-08-24T01:03:41Z")

</div>

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:

```auto
<?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.

```auto
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.

---

<div class="post-metadata">

**Author:** ![peternemser](https://discourse.mailinabox.email/letter_avatar_proxy/v4/letter/p/e0b2c6/32.png) [@peternemser](https://discourse.mailinabox.email/u/peternemser)\
**Post date:** [August 24, 2017, 10:27pm UTC](https://discourse.mailinabox.email/t/dns-rewrite-customizing-the-webmail-urls-for-multiple-domains-on-a-single-box/2436/3 "2017-08-24T22:27:21Z")

</div>

Is there a way to do this without using php?

---

<div class="post-metadata">

**Author:** ![hachre](https://discourse.mailinabox.email/user_avatar/discourse.mailinabox.email/hachre/32/627_2.png) [@hachre](https://discourse.mailinabox.email/u/hachre)\
**Post date:** [August 24, 2017, 11:33pm UTC](https://discourse.mailinabox.email/t/dns-rewrite-customizing-the-webmail-urls-for-multiple-domains-on-a-single-box/2436/4 "2017-08-24T23:33:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![murgero](https://discourse.mailinabox.email/user_avatar/discourse.mailinabox.email/murgero/32/750_2.png) [@murgero](https://discourse.mailinabox.email/u/murgero)\
**Post date:** [September 6, 2017, 6:06pm UTC](https://discourse.mailinabox.email/t/dns-rewrite-customizing-the-webmail-urls-for-multiple-domains-on-a-single-box/2436/5 "2017-09-06T18:06:28Z")

</div>

@peternemser for HTML Redirect:

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

---

<div class="post-metadata">

**Author:** ![elsiehupp](https://discourse.mailinabox.email/user_avatar/discourse.mailinabox.email/elsiehupp/32/2592_2.png) [@elsiehupp](https://discourse.mailinabox.email/u/elsiehupp)\
**Post date:** [January 2, 2021, 10:57am UTC](https://discourse.mailinabox.email/t/dns-rewrite-customizing-the-webmail-urls-for-multiple-domains-on-a-single-box/2436/6 "2021-01-02T10:57:13Z")

</div>

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:

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

```

This made it so that [box.example.com](http://box.example.com) redirects to [box.example.com/admin](http://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.

---

<div class="post-metadata">

**Author:** ![daveteu](https://discourse.mailinabox.email/letter_avatar_proxy/v4/letter/d/b5e925/32.png) [@daveteu](https://discourse.mailinabox.email/u/daveteu)\
**Post date:** [January 2, 2021, 4:29pm UTC](https://discourse.mailinabox.email/t/dns-rewrite-customizing-the-webmail-urls-for-multiple-domains-on-a-single-box/2436/7 "2021-01-02T16:29:09Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![murgero](https://discourse.mailinabox.email/user_avatar/discourse.mailinabox.email/murgero/32/750_2.png) [@murgero](https://discourse.mailinabox.email/u/murgero)\
**Post date:** [January 13, 2021, 6:28am UTC](https://discourse.mailinabox.email/t/dns-rewrite-customizing-the-webmail-urls-for-multiple-domains-on-a-single-box/2436/8 "2021-01-13T06:28:10Z")

</div>

> [@daveteu](#):
>
> You can actually create a `custom.yaml` file in `/home/user-data/www/`

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.

---

<div class="post-metadata">

**Author:** ![daveteu](https://discourse.mailinabox.email/letter_avatar_proxy/v4/letter/d/b5e925/32.png) [@daveteu](https://discourse.mailinabox.email/u/daveteu)\
**Post date:** [January 13, 2021, 6:40am UTC](https://discourse.mailinabox.email/t/dns-rewrite-customizing-the-webmail-urls-for-multiple-domains-on-a-single-box/2436/9 "2021-01-13T06:40:30Z")

</div>

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

> <https://github.com/mail-in-a-box/mailinabox/issues/153#issuecomment-53196576>
>
> Hello Sir ,
> Thanks for the awesome installer , must appreciate your hard work ...
> I got an issue , if you have...
