The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Auto-redirect www subdomain

Discussion in 'cPanel Developers' started by Xavior82, Oct 13, 2009.

  1. Xavior82

    Xavior82 Active Member
    PartnerNOC

    Joined:
    Oct 5, 2006
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Montreal
    Hello,

    Using my current configuration, when I create a new account in WHM it allows users to access the site using:

    http://domain.com

    AND

    http://www.domain.com

    How can I make it so that by default, when *any* new account is created, all accesses from http://domain.com be redirected automatically to http://www.domain.com.

    What I'm looking for here is not a one-time solution (I know this type of manipulation can be done manually by editing the .htaccess file on the newly created account), but rather a global solution that I can apply to the whole server and that would be applied to any newly created accounts.

    I know search engines can penalize sites for showing duplicate content on different subdomains so would like to be able to avoid this, if at all possible.

    Thanks!
     
  2. bvierra

    bvierra Well-Known Member

    Joined:
    Jul 28, 2006
    Messages:
    55
    Likes Received:
    1
    Trophy Points:
    8
    Location:
    Southern California
    just make a .htaccess file and drop it into the the skel dir
     
  3. Xavior82

    Xavior82 Active Member
    PartnerNOC

    Joined:
    Oct 5, 2006
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Montreal
    I don't know what syntax I would use to make .htaccess rules that would be valid on different domains.

    I would normally set it up like this (for redirecting www to non-www):

    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www.domainexample.com$ [NC]
    RewriteRule ^(.*)$ http://domainexample.com/$1 [R=301,L]
    
    How would I make this work as a general solution for *any* domain?

    Thanks!
     
  4. Arcat

    Arcat Registered

    Joined:
    Oct 29, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Ok, so looking at your example for www to non-www, if you wanted that to work on ANY domain, then you need to build up a regular expression to capture that appropriately (and of course, reverse it, since your original question was to go from non-www to www). Here is an article with some pretty good starter points:
    non-www to www for any domain (primary and parked domains)

    Hope that helps!

     
Loading...

Share This Page