• Halloween is coming! To celebrate the occasion, we dusted off a couple of old skins, and even created a brand new one (Pixel).
    To get into the festive spirit, install the Skins extension.
  • The new Python extension is now available. It allows customers to deploy and manage WSGI-based Python applications on their websites directly from Plesk.
  • The Plesk Mobile apps for iOS and Android and the Plesk Mobile Center extension have been deprecated, and are no longer available for new installations. In Plesk Obsidian 18.0.84, the Plesk Mobile Center extension will be removed from servers during the upgrade, and the Plesk Mobile apps will lose their server management features.
  • The Social Login extension has been deprecated and will be removed in Plesk Obsidian 18.0.84. After that, it will no longer be possible to log in to Plesk with a Google, Facebook, GitHub account, or with a passkey. Plesk usernames and passwords, as well as logging in with a WebPros Account, are not affected.

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