How to redirect mail.domain.com to domain.com/mail for all user

smbongtoi85

New member
Joined
Dec 9, 2019
Messages
4
My question as my title. Just is I dont want redirect by each host'user.
I find file alias where is "conf/extra/httpd-alias.conf", but I dont know how to write it, I think it is so simple, plz, help me, thanks.
1575952410275.png
 

smbongtoi85

New member
Joined
Dec 9, 2019
Messages
4
I tested, and roundcube doesn't get js, css (asset) for code. How to fix it?
In virtual hosts you can only point the domain to the Document Root. My question seem is REDIRECT
1575976096860.png
 

smbongtoi85

New member
Joined
Dec 9, 2019
Messages
4
First of all, I would say to thanks to @system-admin for your answers. It seems that my question is REDIRECT, I am not sure that it can use REDIRECT in Ngix-Apache, I didn't search it on Google, because I had way to redirect it on my server. As @system-admin has instructed, I can point domain "mail.domain.com" to "DOCUMENT ROOT", and from there I think that I can create new file "my_redirect_to_mail.php" to redirect it, and its code is:

PHP:
<?php

function get_domain($url)
{
    $domain = $url;
    if(preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs))
    {
        return $regs['domain'];
    }
    return false;
}

$domain = get_domain($_SERVER['SERVER_NAME']);

header('Location: http://' . $domain . '/mail');
die();

?>
I created it in directory: "/var/www/html/roundcube". This is not really is true of what it means to be "DOCUMENT ROOT" (I think so), but it worked. I'm not good in PHP, I just search it on Google, but it works well with my server. If there is a better solution or anything is wrong with my way, please send feedback, again, thanks for reading.
Apache config:
for "/usr/local/directadmin/data/templates/custom/virtual_host2.conf.CUSTOM.4.post":


</VirtualHost>

<VirtualHost |IP|:|PORT_80| |MULTI_IP|>

   ServerName mail.|DOMAIN|

   ServerAdmin |ADMIN|

   DocumentRoot /var/www/html/roundcube/my_redirect_to_mail.php

   CustomLog /var/log/httpd/domains/|DOMAIN|.bytes bytes

   CustomLog /var/log/httpd/domains/|DOMAIN|.log combined

   ErrorLog /var/log/httpd/domains/|DOMAIN|.error.log

   <IfModule !mod_ruid2.c>

       SuexecUserGroup webapps webapps

   </IfModule>

</VirtualHost>

<VirtualHost |IP|:|PORT_443| |MULTI_IP|>

   ServerName mail.|DOMAIN|

   ServerAdmin |ADMIN|

   DocumentRoot /var/www/html/roundcube/my_redirect_to_mail.php


   SSLEngine on

   SSLCertificateFile |CERT|

   SSLCertificateKeyFile |KEY|

   |CAROOT|


   CustomLog /var/log/httpd/domains/|DOMAIN|.bytes bytes

   CustomLog /var/log/httpd/domains/|DOMAIN|.log combined

   ErrorLog /var/log/httpd/domains/|DOMAIN|.error.log

   <IfModule !mod_ruid2.c>

       SuexecUserGroup webapps webapps

   </IfModule>
 
Top