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