I'm trying to use Environment Variables in Apache2 httpd.conf. The point would be to redirect port 80 to a https connection on same host and stay there.
I need it to get the HOSTNAME or HTTP_HOST as i don't previously know it. Using redirect or mod_rewrite is not the real question.
The problem is, I can't even output any of this variables. When I add %{HOSTNAME} or %{HTTP_HOST} and then browse to http://example.com/ it redirects (literally) to https://%{HOSTNAME}
I'm using CentOS, and probably missing something very important. Any help will be appreciated.
Edit 1: Listing Env Variables i can see HOSTNAME is defined, but HTTP_HOST is not there.
Doubt A: If I Define HTTP_HOST, what value should i give? Since I need it to output the current HTTP Host whenever it changes.
Doubt B: As suggested in documentation and other answers the correct sintax for this vars in httpd.conf would be (for example) %{HTTP_HOST}%{REQUEST_URI} I did use it this way, and tried also with HOSTNAME, expecting it to output the value instead of "%{HOSTNAME}" literally. If i have this one defined, why isn't it outputing the value?
Edit 2 SOLVED: Turned out HTTP_HOST wasn't working for this reason: https://stackoverflow.com/questions/10910541/is-the-http-host-server-variable-always-defined
As I am using IP Adress, because i still don't know what the HTTP_HOST will be.