Forum Moderators: phranque

Message Too Old, No Replies

page stores different sessions with and w/o "www" in domain

can login with "www" but if remove "www" not logged in

         

phazei

4:18 pm on Jul 11, 2006 (gmt 0)

10+ Year Member



I didn't even realize this made a difference untill I was logging out and back in. I had a few windows open and I was testing the login system. Apparently I had logged in on both "www.domain.com" and "domain.com". I logged out of domain.com and went to signup but I typed www.domain.com/... to go sign up. It showed me as logged in still. Left me confused till I realized it was because of the "www"s. I've never noticed this happen on any other site so I figure it could mess up/confuse my users. So I was wondering if there was anything in the php I could do to fix that.

I looked around and found this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ [domain.com...] [R=301,L]

but that's for the .htaccess file. I tried it and it worked just fine, for the main domain at least. The other domain is in a subfolder and it gets all messed up when I try to use the RewriteEngine on it.
I realize this question is slipping away from the php side of questions... if there isn't a php solution i'll post this part of it in a different forum, but I'll continue here for now.
The server is setup like this:

public_html/domain1.php
public_html/domain2/domain2.php

When I use the RWEngine for domain2 and I type, say,
"www.domain2.com/index.php"
it redirects me to
"domain2.com/domain2/index.php"
which would be the right path if it were on domain1, but it's not... I found this:
[httpd.apache.org...]
But it didn't help much.

For domain1 it works fine
www.domain1.com/sadfa/asdfase/sdf.php goes to
domain1.com/sadfa/asdfase/sdf.php

I need it to do that for domain2 but I couldn't find what the $1 was. I tried $2 and it took me from
www.domain2.com/whatever/index.php to
domain2.com/

This is kind of a hack around the original problem anyway. Though getting either/both to work would be helpfull.

Thanks,
Adam

phazei

4:25 pm on Jul 11, 2006 (gmt 0)

10+ Year Member



Ahh, can't edit...

PS:

I know that at the top of every file I could put something
using HTTP_HOST and PHP_SELF, and strip the www if
it exists and use header("Location: ...")

but it would be nicer if I could tell php to store the PHPSESSID somewhere where there "www" wouldn't make a difference so it only paid attention to the domain itself.

phazei

4:58 pm on Jul 11, 2006 (gmt 0)

10+ Year Member



I had the .htaccess file in the public_html directory. It had the RewriteEngine for both domains in it. I moved the code for domain2 and put it into domain2's .htaccess file, problem fixed.

If it's not much trouble for anyone who might know, it would still be nice to know how to have gotten it working from the public_html directory as well.

-Adam

jdMorgan

6:50 pm on Jul 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The token $1 is a 'back-reference' to the first parenthesized sub-pattern in the RewriteRule, as documented in the Apache mod_rewrite documentation that you looked at. In the code you posted, it 'copies' the originally-requested local URL-path (e.g. "images/our_logo.gif") into the substitution (new) URL.

The reason that $2 didn't work is that there was no second parenthesized sub-pattern defined in your RewriteRule's pattern, so $2 was blank.

You could use a 'common' .htaccess only if both domains resolve to the same directory path -- This is the DocumentRoot setting in the httpd.conf server configuration file. As far as the 'rules' of the Web go, www- and non-www domains are not at all 'the same thing'; www.example.com is a subdomain of example.com, and need not host the same content, any more so than 'search.example.com' would be expected to host the same content.

Jim