Home > Article > Backend Development > How to Get the Full URL on a Windows/IIS Server for Accurate Redirects?
Getting the Current Page's Full URL on a Windows/IIS Server
When managing redirects on a Windows/IIS server, it's crucial to capture the full URL to ensure accuracy. However, this task can pose challenges, specifically when dealing with WordPress installations moved to new folder locations.
One challenge encountered is that both $_SERVER["REQUEST_URI"] and $_SERVER["PHP_SELF"] fail to provide the desired post title component of the URL. This is because IIS uses a different approach than Apache, which many recommendations assume.
To resolve this issue on an IIS server, the appropriate variable to utilize is $_SERVER['PATH_INFO']. This variable captures the requested portion of the URL, including the post title, in the format you require.
For instance, if your URL looks like this:
http:://www.example.com/OLD_FOLDER/index.php/post-title/
$_SERVER['PATH_INFO'] will return /post-title/.
Therefore, when configuring 301 redirects on a WordPress installation hosted on a Windows/IIS server, $_SERVER['PATH_INFO'] proves to be the reliable solution for retrieving the complete URL needed to achieve accurate redirects.
The above is the detailed content of How to Get the Full URL on a Windows/IIS Server for Accurate Redirects?. For more information, please follow other related articles on the PHP Chinese website!