• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

subdomain to domain on the fly

N

NightStorm

Guest
Got a bit of a challenge. Running Plesk 7.5.3, and with a single domain I want to have sub.domain.com redirect automatically to domain.com/sub
I've set the wildcard entry in the domain's DNS, but the mod_rewrite part is kicking the **** out of me.
Basically, * must redirect, with the exception of webmail, chat, and www.

Here's what I have in the domains root vhost.conf so far (found it here on the forum), but it seems to create a loop that causes the browser to return an error about too many redirects.
Code:
ServerAlias *.domain.com
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain.com$
RewriteCond %{HTTP_HOST} !^chat\.domain.com$
RewriteCond %{HTTP_HOST} !^webmail\.domain.com$
RewriteCond %{HTTP_HOST} ^[^.]+\.domain.com$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^([^.]+)\.domain.com(.*) /home/httpd/vhosts/domain.com/httpdocs/$1$2
Can anyone see what I'm missing in this?
 
Actually, it looks ok. After you create the sub folder, you need to put at least an index.html file in it, if you don't then you will probably get a 404 error. And you then need to do the following 2 things:

/usr/loca/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=domain.com

and then restart httpd (apache) from either the Plesk CP or from command line.

I just tested your additions to vhost.conf and they do work.

Your entire vhost.conf file should look like this:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteMap lowercase int:tolower
ServerAlias *.domain.com
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain.com$
RewriteCond %{HTTP_HOST} !^chat\.domain.com$
RewriteCond %{HTTP_HOST} !^webmail\.domain.com$
RewriteCond %{HTTP_HOST} ^[^.]+\.domain.com$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^([^.]+)\.domain.com(.*) /home/httpd/vhosts/domain.com/httpdocs/$1$2
</IfModule>
 
Back
Top