1

I am working with apache mod_alias so using HTTP_POST doesn't give me the alias plus with HTTPS it's not there. The below line seems to work but could it fail? I understood SERVER_NAME needs to be configured on server but provided it is this ok?

$site_url = $_SERVER["REQUEST_SCHEME"] . "://" . $_SERVER["SERVER_NAME"] . $_SERVER["CONTEXT_PREFIX"];
user391986
  • 29,536
  • 39
  • 126
  • 205
  • What does $site_url return? print_r($_SERVER); ? – Glavić Sep 26 '12 at 19:27
  • I get `http://localhost/myalias` – user391986 Sep 26 '12 at 19:28
  • 3
    You could also leave out the scheme altogether, resulting in an URL starting with a double slash `//`. The resulting link will always use the same protocol as the current document your in. – feeela Sep 26 '12 at 19:28
  • If I don't put the scheme I'm getting some weirdness when I try for exmaple to put an img in html src it appends on top of $site_url the actual url as if nothing had been specified. – user391986 Sep 26 '12 at 19:29

1 Answers1

0

I use:

$_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']

Example Output:

https://example.com/alias-no-extension?query=1
Nuno
  • 3,082
  • 5
  • 38
  • 58