1

When visiting my website using the www prefix from the no-www version (which I normally use) I find that I am no longer logged in... Why is this?

Is there a way to have the two versions of the site use the same SESSION variable or at least redirect to one version so as to prevent internal redirects switching users from one version to another (all my redirect use relative paths so I don't think it would be an issue, but I'm inexperienced so I don't know for sure)?

StrongJoshua
  • 975
  • 10
  • 24
  • www. vs. non-www: session-cookie domain settings. But forcefully redirecting all users to one or the other (pick one, stick with it) is the preferred solution as it has a multitude of other benefits. – Wrikken Sep 21 '14 at 02:24

1 Answers1

1

Add the following to your .htaccess file

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com$1 [R=permanent,L]

Redirecting it to one place (i.e. www.example.com) will help with the SEO and also fix your issue of different session variables as it will always fall under www version.

jagmitg
  • 4,236
  • 7
  • 25
  • 59
  • I wish to only use the no-www version of the site, so how will I format that code to fit (i.e. what do I replace)? – StrongJoshua Sep 21 '14 at 02:27
  • I would strongly recommend using www version instead of the non, much more benefits. As for thr file structure, create a `.htaccess` file on the root level of your application and add the above code. It should kick in – jagmitg Sep 21 '14 at 02:31
  • With `example.com`? I don't need to put in my website's URL? – StrongJoshua Sep 21 '14 at 02:36
  • Lol yes you do, change example.com to whatever you want. Just a note if you do want to change it so everything falls on non-www, then just change the URL's around – jagmitg Sep 21 '14 at 02:39