One of the sites that I’ve been working on recently for some odd reason would not log users in (or at least not constantly). After looking into it further, I realized it had to do with the PHP function “header” redirecting the user if the login query was successfully.
The problem came when a user came to the site without typing in “www”. The page was redirecting to the site WITH the “www” and the $_SESSION vars were not getting set.
So to force every page to include the “www”, I added the following 3 lines to the .htaccess file and everything seems to be working fine.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301]
Similar Posts:
- Copy/Transfer Files Between Two Servers Using Linux scp
- Alternate Background Colors Using PHP
- Javascript Close Popup and Refresh or Redirect Parent Window with OnLoad (Solution)
- How to Install SSL Certificate on a Subdomain within Plesk 9
- Display Last.fm’s Recent Tracks on Web Site with PHP Function


November 9th, 2008 @ 1:02 pm
Thanks! This was a huge help. Should have figured this one out on my own though!