1. Please take a little time for this simple survey! Thank you for participating!
    Dismiss Notice
  2. Dear Pleskians, please read this carefully! New attachments and other rules Thank you!
    Dismiss Notice
  3. Dear Pleskians, I really hope that you will share your opinion in this Special topic for chatter about Plesk in the Clouds. Thank you!
    Dismiss Notice

www alias on subdomains guide

Discussion in 'Plesk for Linux - 8.x and Older' started by AlleyKat, Jan 18, 2006.

  1. AlleyKat

    AlleyKat Guest

    0
     
    As a lot of users still type www in front of everything, it's a pretty good idea to add such an alias to all subdomains.

    Here's how I did it:

    Make a new file, let's call it new_wwwsubdomainalias.sh with contents:
    Code:
    #!/bin/bash
    cd /var/www/vhosts/$1/subdomains/$2/conf
    touch vhost.conf
    cp vhost.conf vhost.conf.bak
    
    cat >> /var/www/vhosts/$1/subdomains/$2/conf/vhost.conf <<EOF
    
    # Directive to use WWW aliases on subdomains
    	ServerAlias  [url]www.[/url]$2.$1
    EOF
    
    /etc/init.d/httpd restart 
    
    - here assuming that the path to the domains is /var/www/vhosts/ - many systems use a different path like /home/httpd/vhosts/ or such, and if this is the case, replace it all over in above file.

    Here's what the file does:
    1) Change to directory for subdomain conf
    2) 'Touch' vhost.conf file, make sure it exist
    3) Backup vhost.conf file to .bak
    4) Add the 3 lines to the vhost.conf
    5) Ask the httpd (Apache) service to restart



    Put the file into /usr/local/psa/bin/ (assuming you're root) and chmod it to 774.


    Now log in to Plesk 7.5.4 as admin, and goto System > Server -> Event Manager.

    Press Add New Event Handler and in the new window, find the event "Subdomain created" in the dropdown. Change priority if you must, make sure "root" is the user, and add the line:

    /usr/local/psa/bin/new_wwwsubdomainalias.sh <new_domain_name> <new_subdomain_name>
    - then OK, and you're fully done.

    A vhost.conf which is automatically included by the apache config is created or has lines added with the www alias for the subdomain.

    Extra advantage/disadvantage: restarts Apache on-the-fly making created subdomains active immediately.

    Thx to: Apache guide, Plesk manual, the authors of the AWstats thread for making me realize this simple and effective solution. Comments & corrections are very welcome. :)
     
  2. FlashMagnuM

    FlashMagnuM Guest

    0
     
    Man, I have always asked myself, why didn't SWSoft implemented it? I mean all subdomains should have a www alias by default, like they have in a CPanel or DirectAdmin solution.

    Anyway thaks for the .sh file ... I will use it!
     
  3. FlashMagnuM

    FlashMagnuM Guest

    0
     
    The thing is that I wanted to do it manually for one subdomain (put the ServerAlias directive manually), but there is no vhost.conf in:

    /var/www/vhosts/my_domain/subdomains/my_subdomain/conf/

    There is the conf directory, but its empty .... actually there is no vhost.conf in my system, because I have search it.

    I'm running Plesk 7.5.4 on a SuSe Linux 9.1 ... so if know what to do ... please help me!
     
  4. AlleyKat

    AlleyKat Guest

    0
     
    Thats also why I 'touch' the file in the shell script - if it doesn't exist, make one.

    However, there should be a httpd.include file in the folder? That's where my vhost.conf is included (seems to be a default thing).
     
  5. FlashMagnuM

    FlashMagnuM Guest

    0
     
    Well in the conf directory of each subdomain, there is nothing: no httpd.include, no vhost.conf ... nothing!

    Should I create a vhost.conf file manually in a subdomain, and add:
    ServerAlias www.subdomain.domain.com
     
  6. AlleyKat

    AlleyKat Guest

    0
     
    Hmm if there's no httpd.include I highly doubt it will work - that's where my vhost.conf is included...

    You could take a look at your entire Apache setup to see where and how - that's pretty much how I learned to handle mine.
     
  7. FlashMagnuM

    FlashMagnuM Guest

    0
     
    Man ... its OK like you said, I have found the httpd.include file and read there, it seems that a vhost.conf file should resolve the alias ... but I have a question:

    Shouldn't be there a DNS record for the www.subdomain.domain ... in the DNS Zone, for this Alias to work?
     
  8. FlashMagnuM

    FlashMagnuM Guest

    0
     
    So, nobody can answer me ... shouldn't be a DNS record for the www alias to work?
     
  9. AlleyKat

    AlleyKat Guest

    0
     
    Well, only answer I can give you is that this works perfectly for me. But it'd be interesting to know - above could probably be extended to do that too with some command; I've just no idea how.
     
Loading...