1
votes

I have a Plesk VPS with several hundred domains. Most have the same IP.

If a user goes to an invalid sub domain, they are always redirected to the 1st domain I setup. How can I force invalid subdomain requests such as xyz.domain.com to redirect to www.domain.com either via htaccess or DNS ?

2

2 Answers

0
votes

Below is the htaccess rule you should place in htaccess file for you domain "domain.com

# Check for invalid subdomain
RewriteCond %{HTTP_HOST} !^(www\.)?yourdomain.com$
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,QSA,R=301]
0
votes

It's can be done via .htaccess because invalid subdomains are not hit into valid virtual host.

Think it can be done via wildcard CNAME DNS record via Tools&Settings > DNS template (but please test it first on some test site)

(Pay attention that this operation may be not applied for domains with customized DNS records)

(Pay attention that if you tried to force applying DNS template than all domains DNS customization may be lost(I've not remember exactly this bihaviour))

In case you can't use DNS template you always can add new DNS records to every domain automatically via command /usr/local/psa/bin/dns