0

I have an apache web server, version: Apache/2.4.34 (Red Hat), on it I have multiple virtual hosts

now, in .htaccess, I have a redirect to cut the trailing slashes, but there, the variables HTTP_HOST and SERVER_NAME are always loaded with default (first) virtual host, and not with the current virtual host

and the problem to be even strange, in php those variables are loaded correctly

any idea what to do ? I spent few hours digging google with no result :(

LE seems like is not clear enough, let's just say that I have only 2 virtual hosts: www.ex.com and mail.ex.com, and first is also the default virtual host when I type httpd -S ... now, when I access mail.ex.com, in .htaccess HTTP_HOST is loaded with www.ex.com and not mail.ex.com

TTudor
  • 1
  • 2
  • 1
    _“any idea what to do ?”_ - giving us a _proper_ problem description, would be a start … Please go read [ask] and [mre]. – CBroe Sep 14 '20 at 11:51
  • Have you enabled the virtual host? I can't comment on Red Hat but with Ubuntu you need to a2ensite virtualhostname to enable the host. – user1020496 Sep 14 '20 at 11:56
  • "any idea what to do ?” - giving us a proper problem description, would be a start … Please go read How to Ask and minimal reproducible example. – CBroe", can you please tell me what is not clear ? I have wrong value for http_host and server_name but only in .htaccess, what else I need to explain ? – TTudor Sep 14 '20 at 12:04
  • "Have you enabled the virtual host? I can't comment on Red Hat but with Ubuntu you need to a2ensite virtualhostname to enable the host. – user1020496 7 mins ago" virtual hosts are working properly, and I have several ... – TTudor Sep 14 '20 at 12:04
  • You say they are _both_ "loaded with default (first) virtual host" - what exactly do you mean by that? Are they both set to the value of the `ServerName` directive? The problem with that is that the `HTTP_HOST` server variable has nothing to do with the `ServerName` as defined in _any_ vHost. It is _always_ set to the value of the `Host` header on the HTTP request (hence its name). (Which could be affected if you are behind a front-end proxy?) Are you sure the other vHosts are even being triggered? – MrWhite Sep 14 '20 at 12:45
  • I think is obvious, i have for exampe www.example.com as first and default virtual host, but when I try to access mail.example.com then in .htaccess HTTP_HOST is loaded still with www.example.com instead of mail.example.com – TTudor Sep 14 '20 at 14:17
  • "I think is obvious" - No, it's not "obvious". Particularly since what you appear to be describing is "impossible". As I stated above, the `HTTP_HOST` is never changed to "match the virtual host" (by which I assume you mean the value of the `ServerName` directive (or `ServerAlias`?)). Assuming you do have a `ServerName` directive defined and are not allowing the server to calculate this? `SERVER_NAME` on the other hand will change to match the value of the `ServerName`, only if `UseCanonicalHost On` is set. However, only one vHost can be processed/matched - so again, this does not make sense. – MrWhite Sep 14 '20 at 16:11
  • This is presumably your own server, with no hosting control panel installed (like cPanel)? Please post your server config (including vHost containers). – MrWhite Sep 14 '20 at 16:17

0 Answers0