Results 1 to 5 of 5

Thread: How do I redirect all subdomains to main domain ?

  1. #1

    Default How do I redirect all subdomains to main domain ?

    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.



  2. #2

    Default

    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.
    Parallels Certified Automation Professional | Parallels Product Expert | Lemonbit Internet | lemonbit.com



  3. #3

    Default

    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.)



  4. #4

    Default

    You need just that one line that I posted.
    Parallels Certified Automation Professional | Parallels Product Expert | Lemonbit Internet | lemonbit.com



  5. #5

    Default

    Thank you. You help me a lot . This works.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •