Forum Moderators: phranque
I have two different sites:
1. [subdomain1.mysite.com...]
2. [subdomain1.com...]
What I've been trying to do is, for example, when users are tring to access a page abc.html for the first time, I want to make them to visit the page def.php first. Once users visit the page and click a button, a cookie will be created with value of VISIT and then automatically they will be redirected to whatever the page they wanted to see.
Here is what I did to accomplish the above scenario in .htaccess
RewriteCond %{HTTP_COOKIE}!^.*VISIT.* [NC]
RewriteRule (.*) [%{HTTP_HOST}...] [R,L]
I've test the above .htaccess in my site 1, which is [subdomain1.mysite.com....] Here is the log:
11.22.333.444 - - [01/Oct/2007:09:49:47 -0500] "GET /visitfirsthere/test/ HTTP/1.1" 302 248 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
11.22.333.444 - - [01/Oct/2007:09:49:47 -0500] "GET /visitfirsthere/def.php?t=/visitfirsthere/test/ HTTP/1.1" 200 637 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
11.22.333.444 - - [01/Oct/2007:09:49:51 -0500] "POST /visitfirsthere/def.php HTTP/1.1" 302 624 "http://subdomain1.mysite.com/visitfirsthere/def.php?t=/visitfirsthere/test/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
11.22.333.444 - - [01/Oct/2007:09:49:54 -0500] "GET /visitfirsthere/test/ HTTP/1.1" 200 254 "http://subdomain1.mysite.com/visitfirsthere/def.php?t=/visitfirsthere/test/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
However, when I try the same .htaccess in [subdomain1.com,...] it didn't redirect users def.php, the page users are forced to visit.
11.22.333.444 - - - [01/Oct/2007:09:51:37 -0500] "GET /visitfirsthere/test HTTP/1.1" 301 219 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
11.22.333.444 - - - [01/Oct/2007:09:51:37 -0500] "GET /visitfirsthere/test/ HTTP/1.1" 200 204 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)"
As you can see, it shows 301 redirect but it doesn't bring def.php. Can someone help me why it shows a different behavior and how I can make this work?
[added] And for clarity, why are you redirecting to https? [/added]
Jim
[edited by: jdMorgan at 10:10 pm (utc) on Nov. 6, 2007]
For security reasons, I can't put any info related to our actual sites and that's why I named like
[subdomain1.mysite.com...] and [subdomain1.com...]
Both sites are actually SSL enabled https.
Only I can think of anything related to 301 redirection is to adding www when users type
subdomain1.com
then, it will automatically add www in front of subdomain1.com.
I believe it uses 301.
Make sure that the "add www" code tests for http or https, and redirects using the correct protocol, for example:
# Redirect to www for https
RewriteCond %{SERVER_PORT} [b]^443$[/b]
RewriteCond %{HTTP_HOST} ^subdomain1\.com
RewriteRule (.*) htt[b]ps:[/b]//www.subdomain1\.com/$1 [R=301,L]
#
# Redirect to www for http
RewriteCond %{SERVER_PORT} [b]!^443$[/b]
RewriteCond %{HTTP_HOST} ^subdomain1\.com
RewriteRule (.*) ht[b]tp:[/b]//www.subdomain1\.com/$1 [R=301,L]