How to force all urls to have 'www.' in the beginning

Discussion in 'HTML & Website Design' started by nyczdevil, Sep 1, 2011.

  1. #1
    I have a forum and when browsing even though starting at 'www.' it will sometimes click to '.domain.com'. It interfers with the cookies and forces my users to log out. I want to make all URLs forced to have the 'www.'. I have tried using the .htacess file but doesn't seem to work. anyone know why?

    #RewriteCond %{HTTP_HOST} !^www\.xxxxxx\.com
    #RewriteRule (.*) http://www.xxxxxx.com/$1 [L,R=301]
    
    RewriteRule ^((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 [L]
    
    RewriteCond %{REQUEST_URI} !(admincp/|modcp/|cron|vbseo_sitemap)
    RewriteRule ^((archive/)?(.*\.php(/.*)?))$ vbseo.php [L,QSA]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !/(admincp|modcp|clientscript|cpstyles|images)/
    RewriteRule ^(.+)$ vbseo.php [L,QSA]
    PHP:
     
    nyczdevil, Sep 1, 2011 IP
  2. zinghana

    zinghana Well-Known Member

    Messages:
    1,970
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    125
    #2
    it's done via the .htaccess file..

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example\.com
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]
    Code (markup):
    Change "example.com" to match your domain... while this is for the base domain it should implement into all site links.

    EDIT: your .htaccess file posted in your opening post has the # symbol in front of the first two lines, this is commenting out the lines which is blocking the redirect, try removing the "#" symbol from the first two lines.. if that doesn't work try adding my code above near the top of your .htaccess file.

    Also make sure you do not have "RewriteEngine On" in there twice.

    Regards, Darren
     
    zinghana, Sep 1, 2011 IP
  3. nyczdevil

    nyczdevil Active Member

    Messages:
    116
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    wow i swear, i'm an idiot sometimes. you look so hard but don't look for the simple things.

    the # signs was what was wrong. i can't believe i didn't notice it. thank you so much for pointing that out.
     
    nyczdevil, Sep 1, 2011 IP
  4. zinghana

    zinghana Well-Known Member

    Messages:
    1,970
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    125
    #4
    do worries mate :)

    Happens to the best of us.. done that many times before i usually spend hours on something silly like that and take a look at it the next morning and bang it stands out.
     
    zinghana, Sep 2, 2011 IP
  5. drhowarddrfine

    drhowarddrfine Peon

    Messages:
    5,428
    Likes Received:
    95
    Best Answers:
    7
    Trophy Points:
    0
    #5
    Of note, using www is rather antiquated and is of no value in most cases. What those exceptions are, I can't even recall.
     
    drhowarddrfine, Sep 2, 2011 IP