Home > Linux > Plesk: RewriteRule to redirect from subdomains mail, ftp, ns1, ns2 to main domain

Plesk: RewriteRule to redirect from subdomains mail, ftp, ns1, ns2 to main domain

November 11th, 2009

By default in Plesk the is such interesting configuration. When you try to access virtual subdomain, for example mail.domain.com or ftp.domain.com, via HTTP, in browser you see the last added in Plesk domain!

To fix it you’ll need to write additional Apache .conf file:

<VirtualHost <ip1>:80 <ip2>:80 <ip3>:80>
 ServerName mail
 ServerAlias mail.*
 ServerAlias ns1.*
 ServerAlias ns2.*
 ServerAlias ftp.*

 RewriteEngine On
 RewriteCond %{HTTP_HOST} ^(?:www\.)?(?:ftp|mail|ns1|ns2)\.(.*)$ [NC]
 RewriteRule ^(.*) http://%1$1 [L,R]

</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost  <ip1>:443 <ip2>:443 <ip3>:443>
 ServerName mail
 ServerAlias mail.*
 ServerAlias ns1.*
 ServerAlias ns2.*
 ServerAlias ftp.*

 RewriteEngine On
 RewriteCond %{HTTP_HOST} ^(?:www\.)?(?:ftp|mail|ns1|ns2)\.(.*)$ [NC]
 RewriteRule ^(.*) https://%1$1 [L,R]

</VirtualHost>
</IfModule>

Name this file subdomains_redirect.conf and place it to /etc/httpd/conf.d or /etc/apache2/conf.d

Download subdomains_redirect.conf (590 bytes)

Categories: Linux Tags: ,
Comments are closed.