# Redirecting Webmail Path

**URL:** <https://forum.hestiacp.com/t/redirecting-webmail-path/14563>\
**Category:** Mail\
**Created:** [May 29, 2024, 11:11pm UTC](https://forum.hestiacp.com/t/redirecting-webmail-path/14563 "2024-05-29T23:11:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![molero.renan](https://forum.hestiacp.com/user_avatar/forum.hestiacp.com/molero.renan/32/6521_2.png) [@molero.renan](https://forum.hestiacp.com/u/molero.renan)\
**Post date:** [May 29, 2024, 11:11pm UTC](https://forum.hestiacp.com/t/redirecting-webmail-path/14563/1 "2024-05-29T23:11:12Z")

</div>

I’d like to share a handy tip for those migrating from VestaCP to HestiaCP.

In VestaCP, the path to Webmail was:

> [https://www.mydomain.com/webmail](https://www.mydomain.com/webmail)

While in HestiaCP, it is:

> [https://webmail.mydomain.com](https://webmail.mydomain.com)

To avoid the inconvenience of informing all your clients about the URL change, you can resolve this issue with a simple change in your .htaccess file.

Just add the following code to your .htaccess file and your clients will be automatically redirected."

```auto
RewriteCond %{REQUEST_URI} ^/webmail(/|$|\?)
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule ^(.*)$ https://webmail.%1/ [L,R=301]

```

---

<div class="post-metadata">

**Author:** ![sahsanu](https://forum.hestiacp.com/user_avatar/forum.hestiacp.com/sahsanu/32/9318_2.png) [@sahsanu](https://forum.hestiacp.com/u/sahsanu)\
**Post date:** [May 30, 2024, 6:44am UTC](https://forum.hestiacp.com/t/redirecting-webmail-path/14563/2 "2024-05-30T06:44:13Z")

</div>

Thanks for sharing.

You can do it too adding a redirect in Nginx and it will be valid for Nginx Standalone and Nginx+Apache2.

Example:

Create two files:  
`/home/USER/conf/web/DOMAIN/nginx.conf_redirect-webmail`  
And  
`/home/USER/conf/web/DOMAIN/nginx.ssl.conf_redirect-webmail` (this one could be a symlink to the previous one)

With this content:

```auto
location /webmail {
      return 301 $scheme://webmail.HereTheDomain;
}

```

Script to modify at once all users that have a mail domain and a web domain.

```auto
#!/usr/bin/env bash
for i in $(v-list-users plain | cut -f1); do
        mail_dom="$(v-list-mail-domains "$i" plain | cut -f1)"
        if [[-n "$mail_dom"]]; then
                for f in $mail_dom; do
                        web_conf="/home/$i/conf/web/$f"
                        if [[-d "$web_conf"]]; then
                                echo "Redirecting webmail for user $i and domain $f"
                                redirect_file="/home/$i/conf/web/$f/nginx.conf_redirect-webmail"
                                redirect_ssl_file="/home/$i/conf/web/$f/nginx.ssl.conf_redirect-webmail"
                                cat <<EOF >"$redirect_file"
location /webmail {
      return 301 \$scheme://webmail.$f;
}
EOF
                                ln -sfr "$redirect_file" "$redirect_ssl_file"
                        else
                                echo "User $i doesn't have web domain for $f so no redirect applied"
                        fi
                done
        else
                echo "User $i doesn't have mail domains"
                continue
        fi
done
echo
if nginx -t &>/dev/null; then
        echo -n "Reloading nginx... "
        if systemctl reload nginx; then
                echo "OK"
        else
                echo "ERROR"
        fi
else
        echo "ERROR: nginx -t produced an error, review nginx conf" >&2
        nginx -t
fi

```

---

<div class="post-metadata">

**Author:** ![molero.renan](https://forum.hestiacp.com/user_avatar/forum.hestiacp.com/molero.renan/32/6521_2.png) [@molero.renan](https://forum.hestiacp.com/u/molero.renan)\
**Post date:** [May 30, 2024, 8:19pm UTC](https://forum.hestiacp.com/t/redirecting-webmail-path/14563/3 "2024-05-30T20:19:06Z")

</div>

Very good, Sahsanu.

Beautiful solution 🙂
