0

My problem is that a particular webpage (where I start a php session) can be loaded either with www.mywebpage.com or just mywebpage.com

And due to how my application works I need it to be an static one. otherwise I can have 2 sessions created (one with www and other without it) and that messes up my data.

I know I can name the session but I wonder if there's a way to force the page to always load with or without the www. prefix? so that the session will always be www.mywebpage.com?

1 Answers1

0

I would suggest that you use a rewrite rule to achieve this result.

Inside of your .htaccess file for the virtual host directory in question add the following:

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

This will validate what protocol you are using, check the host value and redirect in a somewhat dynamic way.

I trust this helps.

P.S Please reference this article: .htaccess - how to force "www." in a generic way?

Community
  • 1
  • 1
mwatts
  • 41
  • 2