Tuesday, 20 August 2013

PHP on IIS get the current rewritten URL

PHP on IIS get the current rewritten URL

Is there anyway of getting the current full rewritten URL in PHP on IIS.
For instance, I have a URL like:
http://www.domain.com/searchresults.php?section=99&page=1&model=section-name
which is rewritten to: http://www.domain.com/section99/page1/section-name
I've been able to piece together the original URL using :
function selfURL(){
if(!isset($_SERVER['REQUEST_URI'])){
$serverrequri = $_SERVER['PHP_SELF'];
}else{
$serverrequri = $_SERVER['REQUEST_URI'];
}
$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s"
: "";
$protocol = "http";
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" :
(":".$_SERVER["SERVER_PORT"]);
return
$protocol."://".$_SERVER['SERVER_NAME'].$port.$serverrequri.$_SERVER['QUERY_STRING'];
}
print(selfURL());
Is there anyway I can easily pick the rewritten URL to avoid the overhead
of having to work out the friendly URL from a number of different formats
and variables depending on the current page type?

No comments:

Post a Comment