Forum Moderators: phranque

Message Too Old, No Replies

rewrite isn't working in a different server

rewrite 301 vs 302

         

Abba

9:56 pm on Nov 6, 2007 (gmt 0)

10+ Year Member



Hi,

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?

jdMorgan

10:07 pm on Nov 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That behaviour is not related to your code -- something else is doing that 301 redirect, because your code clearly specifies a 302 redirect. How and where is you www.subdomain1.com domain hosted?

[added] And for clarity, why are you redirecting to https? [/added]

Jim

[edited by: jdMorgan at 10:10 pm (utc) on Nov. 6, 2007]

Abba

3:02 am on Nov 7, 2007 (gmt 0)

10+ Year Member



First of all, thanks for your quick reply.

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.

jdMorgan

3:15 am on Nov 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> 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.

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]

Jim