[wp-trac] [WordPress Trac] #36201: Admin Pagination URLs Use Wrong Hostname

WordPress Trac noreply at wordpress.org
Mon Jul 22 13:58:40 UTC 2024


#36201: Admin Pagination URLs Use Wrong Hostname
-------------------------------------------------+-------------------------
 Reporter:  grimmdude                            |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  reopened
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  Administration                       |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch needs-testing dev-         |     Focuses:
  feedback                                       |  administration
-------------------------------------------------+-------------------------

Comment (by provesource):

 I was wondering what kind of redirect issues did you have?
 We have wordpress behind a reverse proxy + on a directory of the main
 domain
 Setting the $_SERVER['HTTP_HOST'] and other params seems to have fixed the
 issue for us.

 Had to go through the wordpress core code to find this issue before
 stumbling on this now 8 year old (!!) ticket.

 Replying to [comment:40 timinaust]:
 > I found setting HTTP_HOST caused other redirect issues.  My workaround
 to this - providing you have access to the proxy...
 >
 > Set the proxy to add a header on requests being passed through with the
 request host name, then add the following at the end of wp-config.php.  It
 corrects pagination/sorting for both normal and ajax admin calls.
 >
 > Example is for apache proxy, nginx proxy should work exactly the same if
 you add the same header.
 >
 > {{{#!php
 > /**
 >  * Filter to fix up admin URLs when running behind a reverse proxy.
 >  * On the proxy, add a header to requests for X_ORIGINAL_HOST.
 >  *
 >  * On and apache proxy add the following RequestHeader line in the proxy
 block.
 >  *   <Location ...>
 >  *     ProxyPass ....
 >  *     ProxyPassReverse ....
 >  *      ....
 >  *     RequestHeader set X-Original-Host "expr=%{HTTP_HOST}"
 >  *    ....
 >  *   </Location>
 >  */
 > function proxied_url_rewrite ($url,$scheme,$orig_scheme) {
 >       if ($_SERVER["HTTP_X_ORIGINAL_HOST"] && ($scheme == "https" ||
 $scheme == "http") && $_SERVER['HTTP_HOST'] !=
 $_SERVER["HTTP_X_ORIGINAL_HOST"] )
 >               $url = str_replace("://".$_SERVER['HTTP_HOST']."/",
 "://".$_SERVER["HTTP_X_ORIGINAL_HOST"]."/",$url);
 >       return $url;
 > };
 > if ( is_admin() && $_SERVER["HTTP_X_IS_REVERSE_PROXY"])
 add_filter('set_url_scheme','proxied_url_rewrite',10,3);
 >
 > }}}
 >
 > You may also need to add in wp-config.php if you are proxying from https
 -> http
 > {{{#!php
 > $_SERVER['HTTPS'] = 'on';
 > }}}
 >

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/36201#comment:46>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list