1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

My site shows up as www and non www but logs people out if visiting one or the other

Discussion in 'Server Configuration and Hosting' started by surfsup, Jun 30, 2014.

  1. surfsup

    surfsup Well-Known Member

    Not sure if I have my .htaccess setup wrong or what but anyone can visit our site with www or no www (our site is also setup with SSL) - but if someone logs in via www.truckmountforums.com and then tries to visit without the www. it doesnt show up as logged into the site.

    What should I do on my end?
     
  2. RoldanLT

    RoldanLT Well-Known Member

  3. Coop1979

    Coop1979 Well-Known Member

    It's only setting a cookie on either the www or bare domain, not both. If you want the bare domain with SSL, so this:
    Code:
    RewriteEngine On
    RewriteCond %{HTTPS} !^on$
    RewriteRule (.*) https://yourdomain/$1 [R,L]
     
  4. HWS

    HWS Well-Known Member

    Set the cookie domain in config.php to solve this issue.
     
    AzzidReign likes this.
  5. surfsup

    surfsup Well-Known Member

    Well I want to redirect the non www to www, what should it be for this? Because above is for non www right?

    Thanks and here is a copy of my htaccess:

    Code:
    #    Mod_security can interfere with uploading of content such as attachments. If you
    #    cannot attach files, remove the "#" from the lines below.
    #<IfModule mod_security.c>
    #    SecFilterEngine Off
    #    SecFilterScanPOST Off
    #</IfModule>
    
    ErrorDocument 401 default
    ErrorDocument 403 default
    ErrorDocument 404 default
    ErrorDocument 500 default
    
    <IfModule mod_rewrite.c>
        RewriteEngine On
    
        #    If you are having problems with the rewrite rules, remove the "#" from the
        #    line that begins "RewriteBase" below. You will also have to change the path
        #    of the rewrite to reflect the path to your XenForo installation.
        RewriteBase /
    
        RewriteRule [^/]+/([\d]+)-.+-([\d]+).html showthread.php?t=$1&page=$2 [NC,L]
        RewriteRule [^/]+/([\d]+)-.+.html showthread.php?t=$1 [NC,L]
    
        #    This line may be needed to enable WebDAV editing with PHP as a CGI.
        #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    
        RewriteCond %{REQUEST_FILENAME} -f [OR]
        RewriteCond %{REQUEST_FILENAME} -l [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml) - [NC,L]
            RewriteRule (robots\.txt)$ robots.php [NC,L]
        RewriteRule ^.*$ index.php [NC,L]
    RewriteRule ^[^/]+/mobile /threads/tmf-mobile-app-free-limited-time.37750/ [R=301,L]
    RewriteRule ^[^/]+/freehandout /resources/free-customer-google-yelp-facebook-review-guide-handout.190/ [R=301,L]
    </IfModule>
     
  6. melbo

    melbo Well-Known Member

    If you want to redirect all non www to www
    AND
    force all http traffic to https
    AND
    set the 301 (permanently moved) redirect


    Add this to your .htaccess (right below your ErrorDocuments)
    Code:
    # Force non-ssl and non www to https
    RewriteCond %{SERVER_PORT} 80 [OR]
    RewriteCond %{HTTP_HOST} !^www.YOURDOMAIN\.com$
    RewriteRule ^(.*)$ https://www.YOURDOMAIN.com/$1 [R=301,L]


    If you only want to redirect non www to www (Although if you have SSL, I'd force it now) Add this to .htaccess below ErrorDocuments:
    Code:
    # non-www to www
    RewriteCond %{HTTP_HOST} ^YOURDOMAIN.com
    RewriteRule ^(.*)$ http://www.YOURDOMAINcom/$1 [R=301,L]


    If you don't think you need the 301 directives, (You probably do and they can't hurt)
    Code:
    Change the [R=301,L]
    to
    [R,L]
    Also, have you told Google which urls to display in Web Master Tools? there is a setting for www nor non www

    all rewrite rule glory goes to @Jake Bunce who helped me with the above
     
    surfsup likes this.
  7. NeoCHI

    NeoCHI Active Member

    So if I wanted to go from www to non-www I would add this to my htaccess:

    Code:
    # www to non-www
    RewriteCond %{HTTP_HOST} !^mydomain\.com
    RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301,L]
    
    correct?
     
  8. NeoCHI

    NeoCHI Active Member

    It doesn't seem to redirect for admin pages. Is that normal?
     

Share This Page