"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Get the Full URL on a Windows/IIS Server for Accurate Redirects?

How to Get the Full URL on a Windows/IIS Server for Accurate Redirects?

Published on 2024-11-08
Browse:456

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.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3