[wp-trac] [WordPress Trac] #41661: Using proxy & HTTP 1.1 leads to full URL in REQUEST_URI variable in Apache
WordPress Trac
noreply at wordpress.org
Thu Apr 25 09:43:32 UTC 2019
#41661: Using proxy & HTTP 1.1 leads to full URL in REQUEST_URI variable in Apache
--------------------------+------------------------
Reporter: olygraph | Owner: (none)
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: General | Version:
Severity: normal | Resolution: duplicate
Keywords: | Focuses:
--------------------------+------------------------
Description changed by SergeyBiryukov:
Old description:
> When using a proxy the browser send a full URL in var REQUEST_URI
> $_SERVER['REQUEST_URI'];
>
> i.e.:
>
> With proxy: it returns http://mydomain.com/requestedurl
> No Proxy: it returns /requestedurl
>
> Solution:
> check the variable to see if it is full path and transform it:
>
> {{{#!php
> <?php
>
> $_SERVER['REQUEST_URI'] = requesturl_format($_SERVER['HTTP_HOST'],
> $_SERVER['REQUEST_URI']);
>
> function requesturl_format($m_host, $m_request){
> $m_regex = sprintf('#(https?://)(%s)(/.*)#', $m_host);
>
> if(preg_match( $m_regex, $m_request, $matches)){
> if(count($matches) == 4){
>
> $m_host = ($matches[1]);
> $m_domain = ($matches[2]);
> $m_url_req = ($matches[3]);
> return $m_url_req;
> }
> }
> return $m_request;
> }
> }}}
New description:
When using a proxy the browser send a full URL in var REQUEST_URI
`$_SERVER['REQUEST_URI'];`
i.e.:
With proxy: it returns http://mydomain.com/requestedurl
No Proxy: it returns /requestedurl
Solution:
check the variable to see if it is full path and transform it:
{{{#!php
<?php
$_SERVER['REQUEST_URI'] = requesturl_format($_SERVER['HTTP_HOST'],
$_SERVER['REQUEST_URI']);
function requesturl_format($m_host, $m_request){
$m_regex = sprintf('#(https?://)(%s)(/.*)#', $m_host);
if(preg_match( $m_regex, $m_request, $matches)){
if(count($matches) == 4){
$m_host = ($matches[1]);
$m_domain = ($matches[2]);
$m_url_req = ($matches[3]);
return $m_url_req;
}
}
return $m_request;
}
}}}
--
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41661#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list