How to Get the Current Page\'s Full URL on Windows/IIS Servers?

Mary-Kate Olsen
Release: 2024-11-04 15:01:30
Original
364 people have browsed it

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>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!