Forum Moderators: phranque

Message Too Old, No Replies

Identify if a url is a redirect

Identify if a url is a redirect

         

umakanth

4:03 pm on Jul 20, 2005 (gmt 0)

10+ Year Member



Is there a way to know the requested url is redirected from another server. I need to identify and use mod_rewrite to redirect it to exception page.

Thanks
Umakanth

umakanth

4:24 pm on Jul 20, 2005 (gmt 0)

10+ Year Member



I used remote_addr and the mod_rewrite works fine, but when I use remote_host or http_refereer it does not work...any ideas

RewriteCond %{REMOTE_ADDR} ^161\.127\.49\.104$

#RewriteCond %{REMOTE_HOST} ^http://apply.mysite.com/.*$ [NC]

#RewriteCond %{HTTP_REFERER} ^http://grommit.nam.nsroot.net/$ [NC]

RewriteRule ^.*$ /mypls/page2\.htm$1 [PT,L]

The second and the third option on the RewriteCond does not work...

jdMorgan

10:02 pm on Jul 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> Is there a way to know the requested url is redirected from another server?

No, there is no header available to indicate that the client has followed a redirect. However, if the redirect is from another page on your site, you could set a cookie or append a query string to the redirect target URL to identify it as a redirect.

Remote address: Visitor's IP address. Usually traceable to visitor's ISP.
Remote host: Visitor's hostname. Usually traceable to visitor's ISP.
HTTP referrer: URL of page where the link to your site was found. Does not include redirects.

Jim

umakanth

2:23 pm on Jul 21, 2005 (gmt 0)

10+ Year Member



Jim, Thanks for the response.

I tried remote_host, information is not always found on this header variable.

I am confused of the remote_addr, is this the address of the original client or the address of the server that redirected initial request to our server.

http_referer, I came to know that you cannot use info. from this to code around rewrite logic...correct?

what I need to do is if a client is accessing

www.mysite.com or www.mysite.com/index.htm then I want to respond with index.htm (usual server response)

if client is accessing www.mysite.com from a redirect on another server (I know the host name of this server)

then I want to respond with index2.htm

Thanks
Umakanth

jdMorgan

2:57 pm on Jul 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> I am confused of the remote_addr, is this the address of the original client...

This is the IP address of the person clicking on the link.

There is no way to detect redirects from another server, unless that server uses a unique URL to redirect to your site. Then you might detect that unique URL and assume that it is a redirect from the other server. But you still can't be sure... Someone else may have copied the unique URL from that server to another page.

Detecting redirects is simply not supported by the HTTP protocol.

Jim

umakanth

3:43 pm on Jul 21, 2005 (gmt 0)

10+ Year Member



Jim,

This is what I have and it is working, what do you think?

RewriteCond %{HTTP_REFERER} ^http://otherwebserver\.net/.*$ [NC]
RewriteRule .* /login2\.htm$1 [PT,L]

I am getting the result, that any request with
HTTP_REFERER has otherserver in it, go always to login2.htm

The reason I am asking you this question is that on the net there was a mention that http_referer works only 75% of the time...anything you have noticed.

Thanks
Umakanth

jdMorgan

4:58 pm on Jul 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You shouldn't need the [PT] flag to rewrite to an html page -- I'm not sure why you're using it.

Your $1 is undefined, and should be blank. Again, I'm not sure why you are using it there.

HTTP_REFERER is dropped by many ISP (such as AOL) and corporate caching proxies, and is blocked by many users of Norton Internet Security and similar programs. In these cases, you cannot tell where the request was referred from, becuae the referrer will be blank.

Jim

umakanth

6:02 pm on Jul 21, 2005 (gmt 0)

10+ Year Member



Jim,

Thanks for the info, I need [PT] the html page was for my example, in actual its going to be a script page.

"we do not need $1 in that rewrite rule" so will it be same as this

RewriteRule .* /login2\.htm [PT,L]

is same as

RewriteRule .* /login2\.htm$1 [PT,L]

Let me know...

Thanks
Umakanth