I have the below code, that I can use the below to set a variable:
SetEnvIf Host (.*) custom_host=$1
What I want is a variable of the requesting host/computer.
For example, if the website http://example.com:32/welcome is making the request, I want this as the variable?
Instead of Host you need Referer to access the HTTP Referer header that is sent in the request. For example:
SetEnvIf Referer (.*) custom_referer=$1
However, depending on the server-side scripting language you are using, you rarely need to assign this to another variable. You can usually reference it directly as required.
Also note, the HTTP Referer header might not be set. The referring site and the user's browser can both block this.
UPDATE:
how can i have just the protocol, domain and host without the path.
Try changing the regex to something like:
SetEnvIf Referer ^(https?://[^/]+) custom_referer=$1
If the Referer is http://example.com:32/welcome, then this should result in just http://example.com:32 being stored in the custom_referer variable.
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