On a client's website there are loads of redirects going to a particular page. This page somehow needs to have a way detecting whether the request was direct (URI typed in manually) or a redirect.
All of the redirects are 301 redirects. Due to SEO rules added indicators need to be avoided. (Google indexes urls with values separately)
I have tried checking all environment variables but all of them are empty (which assume is normal) and in this respect internal redirects are not any different (I reckon).
Detection needs to happen real time so log files are not an option.
The process in short, parameters are registered in cookies via a script, then it 301 redirects to the page where the content is cookie driven. While cookies are registered the content won't change back to original when someone retypes the address in the address bar.
I hope this makes sense.
PREVIOUSLY: I was thinking about status codes, but I am not sure if there is a way to read that on the destination page or not. (We've clearified that it won't work)
Google Analytics only provides the raw traffic numbers to the specific, final URL that each visitor ends up on. The data is not separated based on which URL forwarded visitors to the page, eliminating helpful metrics that might point out which redirect or campaign was most successful in increasing site traffic.
To test whether you've set up your 301 redirect correctly, type your customized URL into your browser's address bar. If everything is set up correctly, you should be redirected to the defined destination page.
Redirect information will be stored in the transition type of each visit. The current history API only has a boolean flag for redirects.
How about:
my $cgi = CGI->new;
print $cgi->redirect(
'http://example.com/this/page/that.html?redirect=yes'
);
What ever mechanism you are using to distinguish between redirects can then look at the query string to decide. Of course, this does not prevent users from bookmarking the URL with the redirect=yes
etc.
You could try the referer
header, but that has its own problems.
Depending on the browser and intermediate proxies, several things can happen. However, in most cases you can't depend on any one thing. The status codes are something the server sends back to the browser, so you won't get those in a request.
You don't say what problem you are trying to solve or why this bit is important. What problem are you trying to solve?
Instead of relying on something you don't control, turn it into something you can control.
Ensure that you're doing the right sort of redirect. There are redirections for permanent and temporary moves as well as other situation.
If you don't need the data in real time, you can figure out from log files. This is handy if you're trying to figure out traffic patterns, but not so useful in real time.
Instead of an external redirection, make it an internal redirection. You can track it through your web server's request cycle.
Set a cookie on the external redirection then look for it in the next request. This won't catch the people who don't set cookies though.
Add path info to the redirection, or maybe query parameters as Sinan suggested.
This is what I recently did to detect a redirect and expose it as a custom request header to the application: X-Redirect: 1
(using Apache's mod_rewrite and mod_headers).
On the source side, I redirect all requests to the target server by prepending an additional /redirect
to the URL path:
RewriteRule ^/(.*) http://target-server.com/redirect/$1 [L,R=permanent]
On the target side, I detect the /redirect
in the path, strip it via another redirect, and inject a custom cookie into the response:
RewriteRule ^/redirect/(.*)$ /$1 [R=permanent,L,CO=redirect:1:target-server.com:86400:/]
Also on the target side, I convert the cookie into an environment variable, "disable" the cookie, then convert the env variable into a custom request header:
RewriteCond %{HTTP_COOKIE} redirect=1 [NC]
RewriteRule ^(.*)$ /$1 [L,CO=redirect:0:target-server.com:86400:/,E=redirect:1]
RequestHeader set X-Redirect 1 env=redirect
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With