Apache - auto redirect the domain name to www url

  • How can I set that the URL of main domain to be redirected to www without subdomains.
    For example: domain.hu --> redirect --> http://www.domain.hu
    but the subdomains not: whatever.domain.hu --> no redirect --> http://www.whatever.domain.hu


    I tried to modify this file: apache/parts/custom.conf.tpl


    with the following content:

    Code
    1. RewriteCond %{HTTP_HOST} !^www\..*
    2. RewriteCond %{HTTP_HOST} ^(.*)
    3. RewriteRule (.*) http://www.%1$1 [L,R]


    But after that the subdomains will be redirected too.


    How can I configure this?


    Maybe the custom.conf should be cut into two files (custom_domain.conf and custom_subdomain.conf) ?