www or not

Discussion in 'PHP' started by badabinger, Sep 7, 2009.

  1. #1
    I have a site, and am deciding whether to have www in the domain or not. I understand that I will add the below code to my .htaccess file (typically the one inside public_html). What I don't know is which I should choose and why. If anyone could provide advice I would be grateful as I do not program php or anything so have a low knowledge base.

    # Never use www in the domain
    # Replace 'example.com' with your domain name
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www\.(([a-z0-9_]+\.)?example\.com)$ [NC]
    RewriteRule .? http://%1%{REQUEST_URI} [R=301,L]

    Always use www in the domain
    # Replace 'example.com' with your domain name
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^([a-z.]+)?example\.com$ [NC]
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule .? http://www.%1example.com%{REQUEST_URI} [R=301,L]
     
    badabinger, Sep 7, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Wrong forum. (SEO is what you need) - Anyway, it doesn't matter at all, personal preference. Google doesn't care one way or the other. Fact is, most sites put www in it, so it's probably best just to follow that convention.
     
    premiumscripts, Sep 7, 2009 IP
  3. Dollar

    Dollar Active Member

    Messages:
    2,598
    Likes Received:
    82
    Best Answers:
    0
    Trophy Points:
    90
    #3
    Historically "www" meant world wide web, domains having that meant they were accessible for the public by the web. While you could have a completly different domain like login.example.com which is not meant for accessing via port 80 for the www , but maby telnet login or something completly different. Hostnames dont just exist for the web. There meant to just map to a IP for easier referencing. But It doesn't really matter anymore now does it. Those things are just historical blips that have lost their meaning. But most people are still following the old convention of using 'www'. But its not necessary. Use whatever you want. ;)
     
    Last edited: Sep 7, 2009
    Dollar, Sep 7, 2009 IP
  4. hamidof

    hamidof Peon

    Messages:
    619
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I like www. because it's nicer if you want to have sub domains later on, like blog. forums. etc.

    But it's a matter of personal preference and which ever you choose, stick with it...
     
    hamidof, Sep 7, 2009 IP
  5. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I'd keep www and re-direct non-www to www.
     
    wd_2k6, Sep 7, 2009 IP
  6. Brandon_R

    Brandon_R Peon

    Messages:
    330
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #6
    If you have subdomains don't use WWW however if you have folder type urls use the WWW extension. Also don't forget to redirect all non WWW to WWW type urls if you choose this round or vice-versa.
     
    Brandon_R, Sep 7, 2009 IP
  7. badabinger

    badabinger Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Sorry about getting the wrong forum i thought this was a code issue.

    "If you have subdomains don't use WWW however if you have folder type urls use the WWW extension. Also don't forget to redirect all non WWW to WWW type urls if you choose this round or vice-versa."

    Does Wordpress automatically do this, or is it a hosting issue? And if it is not automated, how does one do it?

    Thanks!
     
    badabinger, Sep 7, 2009 IP
  8. Brandon_R

    Brandon_R Peon

    Messages:
    330
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Well there are 3 ways to redirect. The meta, a php header redirect or the .htaccess file. You should use the .htaccess redirect because it it in heritable by folders inside it and you can use regex to match file names and folder names also. For subdomain WWW to NON WWW use the following code:

    Replace example with your site. You should always use permanent (301) redirects to make sure there are no duplicate content issues.
     
    Last edited: Sep 7, 2009
    Brandon_R, Sep 7, 2009 IP
  9. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #9
    Kaizoku, Sep 7, 2009 IP
  10. badabinger

    badabinger Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    It took me an hour with the excellent Hostgator support to define all the steps, but I have done it now. For anyone trying to do this...

    1 Go to file manager
    2 Select Web Root (public_html/www) to open
    3 Click on show hidden files
    4 Click on the folder icon next to "public_html"
    5 Click "Create New File"
    6 In the empty text box, write .htaccess
    7 Connect to FTP
    8 Make sure show hidden files is selected in FTP
    9 Open .htaccess file in notepad
    10 In Worpress ensure that WordPress address (URL) includes the WWW (see settings-General)
    11 Enter code below
    "<Files .htaccess>
    order allow,deny
    deny from all
    </Files>
    # BEGIN WordPress # END WordPress
    #RewriteEngine On
    #RewriteCond %{HTTP_HOST} ^DOMAIN.com [NC]
    #RewriteRule ^(.*)$ http://www.DOMAIN.com/$1 [L,R=301]"
     
    badabinger, Sep 9, 2009 IP
  11. badabinger

    badabinger Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    once you have completed it per the above is there no need to change it google's webmaster tools?
    http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=44231

    when i tried to do it, it said that i had to verify the non WWW version of the site, but since I have already verified the WWW version this seems odd to me and I dont know what i am supposed to do/verify
     
    badabinger, Sep 15, 2009 IP