• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

How do I redirect all subdomains to main domain ?

N

Neantis

Guest
Hello,

I manage a server for a small association, and for their new website based on a complex dymaic back end they want to redirect all requests on subdomains to the main domain. First, I thought I can add a virtual host, but I tried and I failed. So, can you describe me how to redirect all subdomains to main domain ? ( (.+)\.domain\.com$ => domain.com?sub=$1 )

Thank you.

PS: Sorry for my english, I'm french and I haven't seen any quality forum about plesk in my language.
 
You'll need a wildcard DNS A record that maps *.example.com to the IP address of the main domain. Also setup a ServerAlias for the domain (see Including Directives into Web Server Configuration File):

Code:
ServerAlias *.example.com

When this is set up all subdomains will just hit the files on the main domain.

Then you can for instance set up a mod_rewrite rule or use some script to decide what to do depending on which subdomain was requested.
 
This doesn't work :/
What I need to add in my domain /conf/vhost.conf ?

I have tried this :
<VirtualHost 127.0.0.1:80>
ServerName mydomain.com:80
ServerAlias *.mydomain.com
</VirtualHost>
With this command after :
/usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=mydomain.com
And I have a PleskFatalException which explain that Plesk can't restart apache.

I have added the DNS record before doing all that.

(I have changed domain and IP here, but in the reality I have entered the right data.)
 
Back
Top