1

Background

I have a little site that has been setup for our marketing team, it is configured on the same server as our core site. The site has been setup as marketing.lan in Apache. We have configured things so that any request made to our core site via the /marketing url load the marketing.lan pages. Example:

https://www.coresite.com/marketing/test.php

will point to the test.php script on the marketing.lan site. No redirection done, the browser URL will still be

www.coresite.com/marketing/test.php.

Apache is doing this by setting the host to marketing.lan for all request made via the 'www.coresite.com/marketing/' URL.

Problem

The problem is this, when I try and get the URL the page was accessed via using $_SERVER['HTTP_HOST'] I get marketing.lan/test.php not www.coresite.com/marketing/test.php, even with the browser showing the correct URL.

Question Is it possible to get the actual 'URL the script was accessed by? Or is this hidden by Apache? How would I do that.

Levi Putna
  • 2,863
  • 6
  • 30
  • 47
  • 1
    The value of `$_SERVER['HTTP_HOST']` is coming from the config of the host, not from the request. `that any request mate to our core site via the /marketing url load the marketing.lan pages.` How is it done? You can add some additional info to that request. – Cheery Oct 28 '14 at 00:52
  • 1
    try to use $_SERVER['REQUEST_URI'] – jay temp Oct 28 '14 at 00:56
  • I had a chat with the system admin, they have configured Apache to change the host to marketing.lan for nay requests that come in from the coresite.com/marketing. – Levi Putna Oct 28 '14 at 01:06
  • Jay, The REQUEST_URI will only return the request bit of the URL not the domain. – Levi Putna Oct 28 '14 at 01:07
  • @Cheery — No, `HTTP_HOST` reflects the contents of the `Host:` request header sent by the client ([See this answer, for example](http://stackoverflow.com/a/2297421/1679849)). You're possibly thinking of `SERVER_NAME`. – r3mainer Oct 28 '14 at 01:37
  • @squeamishossifrage it does not really matter, because server should have this in the config to answer on the request with that host. Moreover, by the link, `after checking the answer of Pekka on your question which contains a link to bobince's answer that PHP would always return HTTP_HOST's value for SERVER_NAME` May be it is fixed, but the host that corresponds to host: gets response. Or the first in config, but I do not think this is a case. – Cheery Oct 28 '14 at 01:41
  • @Cheery — often they're the same (and `SERVER_NAME` may not even be set). But it *does* matter where this information comes from. If you lead people into believing that `$_SERVER['HTTP_HOST']` contains trusted information provided by the server itself, then they will be liable to expose themselves to cross-site scripting attacks. – r3mainer Oct 28 '14 at 01:48
  • @squeamishossifrage don't you think that that case is a problem of server configuration? Compared to that the info in php will be the smallest of all the evil. – Cheery Oct 28 '14 at 01:50

1 Answers1

1

My Understanding:

  1. Both the sites are in the same server (presumably, a Linux machine)

  2. www.coresite.com has a DocumentRoot something like /var/www/coresite.com/

  3. marketing.lan has a DocumentRoot something like /var/www/marketing.lan/

  4. You now want marketing.lan as a sub-site of www.coresite.com such that http://www.coresite.com/marketing/ shows the contents of http://marketing.lan/


How to do this

There is no need to modify their individual apache configuration; just create a symlink.

ln -s /var/www/marketing.lan /var/www/coresite.com/marketing

This will answer your question:

If your test.php has a line echo $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

  • Going to the url http://www.coresite.com/marketing/test.php will show

    www.coresite.com/marketing/test.php

  • Going to the url http://marketing.lan/test.php will show

    marketing.lan/test.php

kums
  • 2,661
  • 2
  • 13
  • 16