0

I want to do no redirect of a request if a custom header is set (just proceed the request as it is). The htaccess part of that look like the following:

RewriteBase /
RewriteCond %{HTTP:My-Header} !=1
RewriteRule ^somefolder/(.*)$ /someAuthentication.php&url=$1 [QSA,R=302,L]

The authentication where the header is set:

header('HTTP/1.1 307 Temporary Redirect'); // ...to prevent browser caching of redirects
header('My-Header: 1');
header('Location: /somefolder/' . $_GET['url']); // ... redirect to previously requested file

But if I e.g. redirect to some other script there and check the existing headers with getallheaders(), it seems like My-Header was not send as request header what explains why i am just getting ERR_TOO_MANY_REDIRECTS.

Do i misunderstand the usage / definition of headers, set the header incorrectly or is the htaccess condition faulty? Because in my opinion it should be correct as it is, like:

request file 
    -> if header set 
        -> ignore redirect (pass through)
    -> if header is not set 
        -> redirect
            -> set header
                -> redirect to request file

1 Answer 1

1

PHP's header function sets a response header. It's the headers going from the server to the client. The client will initiate a redirect based on the 307 response header. That redirect takes the form of a completely new HTTP request formed by the client. That request will not contain any of the previous response headers.

In a nutshell: there's no way you can make the client send any one specific header during a redirect. Put some sort of flag into the URL itself instead, that's the only thing guaranteed to be consistent between the redirect response and request.

Sign up to request clarification or add additional context in comments.

1 Comment

Indeed, that sounds more logical to me. The client is doing the request afterwards, not the server. Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.