-1

I need to access the current browser uri which is something like www.example.com/page/some-page/ . This is a rewritten url using .htaccess.

I have used the $_SERVER["REQUEST_URI"]. but it returns the page.php instead of /page/some-page/.

How do I get the browser uri at server side?

GunJack
  • 1,928
  • 2
  • 22
  • 35
  • _"This is a rewritten url using .htaccess."_ - rewritten how? In general this _is_ the way to do it (see https://stackoverflow.com/a/6768831/1427878), so you'll need to give us some details what makes your situation different. – CBroe Jul 25 '22 at 13:26
  • As said, `REQUEST_URI` us literally the path requested by the browser (the rest of the URL is not sent anywhere so you need to reconstruct it yourself). If it's wrong for you, there must be something else going on. Either your redirections aren't transparent (you return a `Location:` header to send the browser elsewhere) or you have a proxy messing around. – Álvaro González Jul 25 '22 at 14:17
  • `var_dump($_SERVER)` and see the available paths. – Markus AO Jul 25 '22 at 18:46

1 Answers1

0
  <?php  
    if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')   
         $url = "https://";   
    else  
         $url = "http://";   
    // Append the host(domain name, ip) to the URL.   
    $url.= $_SERVER['HTTP_HOST'];   
    
    // Append the requested resource location to the URL   
    $url.= $_SERVER['REQUEST_URI'];    
      
    echo $url;  
  ?>   

Check : https://www.javatpoint.com/how-to-get-current-page-url-in-php

Vüsal Hüseynli
  • 889
  • 1
  • 4
  • 16