-4

The duplicate question deals with .htaccess issue. I deal with the fact that /index.php may or may not be part of original URL

One way to do so is to do

http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']

The problem is if URL is http://domainname.com the

http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']

will yield

http://domainname.com/index.php

instead.

I need something that yield http://domainname.com

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
user4951
  • 32,206
  • 53
  • 172
  • 282
  • 1
    And why don't you just use `http://'.$_SERVER['HTTP_HOST']` then? – Burki Nov 24 '15 at 08:51
  • The linked duplicate uses `REQUEST_URI` instead of `PHP_SELF`. It also includes a bunch of other methods that work with proxy forwarding. – h2ooooooo Nov 24 '15 at 08:53
  • Because I want to show http://domainname.com/hello/bla.bla.php when users indeed access http://domainname.com/hello/bla.bla.php – user4951 Nov 24 '15 at 08:57

1 Answers1

0

You have to user HTTP_HOST for your current host name :-

http://'.$_SERVER['HTTP_HOST']
Harsh Sanghani
  • 1,666
  • 1
  • 14
  • 32