Levi Putna
Levi Putna

Reputation: 3073

PHP get the user agent request URL

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.

Upvotes: 1

Views: 606

Answers (1)

kums
kums

Reputation: 2701

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

Upvotes: 1

Related Questions