A
AlleyKat
Guest
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:
- 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.
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'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.