Home >Backend Development >PHP Tutorial >How to Get the Current Page\'s Full URL on Windows/IIS Servers?
Getting the Current Page's Full URL on Windows/IIS Servers
Encountering difficulties in setting up 301 redirects after relocating a WordPress installation on Windows/IIS? The issue may stem from retrieving the relevant part of the post URL.
Previous solutions online advocate using $_SERVER["REQUEST_URI"], but it seems to return an empty string. $_SERVER["PHP_SELF"] is also unreliable, merely providing "index.php."
The IIS Environment
Unlike Apache servers, IIS environments have a distinct way of handling URLs. The key is understanding the behavior of $_SERVER variables.
Resolution
Under IIS, you can leverage $_SERVER['PATH_INFO'] to fetch the required segment:
<code class="php">$url_segment = $_SERVER['PATH_INFO'];</code>
In your case, for URLs like "http://www.example.com/OLD_FOLDER/index.php/post-title/", $_SERVER['PATH_INFO'] would yield "/post-title/".
The above is the detailed content of How to Get the Current Page\'s Full URL on Windows/IIS Servers?. For more information, please follow other related articles on the PHP Chinese website!