0

Hello I want to create a local sandbox for my wordpress and keep the exact same hostname than my hosting server; so when I re-upload all and the database everything stays 1:1.

I can’t do it via windows hosts file in windows because I need a different port than 80 and don’t want to set wordpress site url to something like mydomain.com:8080

I’ve tried set it up with FoxyProxy with some regex rules: I.E. redirect mydomain.com -> 192.168.0.x port: 8080

Eveyrhting works except wordpress: It creates this 301 infinite redirect and final url looks like so:

http://mydomain.comhttp//mydomain.comhttp//mydomain.com (note the missing colons on the next ones)

One of the header looks like so:

Status Code:301 Moved Permanently Remote Address:192.168.0.10:80

Referrer Policy:no-referrer-when-downgrade Response Headers view

source Content-Length:2 Content-Type:text/html; charset=UTF-8

Date:Wed, 16 Aug 2017 06:19:11 GMT

Location:http://mydomain.comhttp://mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp//mydomain.comhttp/mydomain.com/

Server:Apache/2.4.18 (Ubuntu) Request Headers view source Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8

Accept-Encoding:gzip, deflate

Accept-Language:en-US,en;q=0.8,fr-FR;q=0.6,fr;q=0.4

Cache-Control:no-cache Host:mydomain.comhttp Pragma:no-cache

Proxy-Connection:keep-alive Upgrade-Insecure-Requests:1

User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64)

AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90

Safari/537.36

Where can i find the php file that make the redirects so I can try to find what is going on? Thank!

EDIT: My HTACCESS File (I use the post-name permalinks):

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

EDIT: Just founded this: The wp_redirect looks wrong, I'll investigate further.

PHP Debug Backtrace at wp_redirect function:

array(8) {
  [0]=>
  array(4) {
    ["file"]=>
    string(69) "/home/mydomain/www/public_html/mydomain.com/wp-includes/canonical.php"
    ["line"]=>
    int(516)
    ["function"]=>
    string(11) "wp_redirect"
    ["args"]=>
    array(2) {
      [0]=>
      &string(37) "http://mydomain.comhttp/mydomain.com/"
      [1]=>
      &int(301)
    }
  }
  [1]=>
  array(2) {
    ["function"]=>
    string(18) "redirect_canonical"
    ["args"]=>
    array(1) {
      [0]=>
      &string(0) ""
    }
  }

Everything else than the index redirect, works #1: admin panel, login page etc.

Looks like there is something wrong in the redirect canonical function, I'll investigate the code to see whats is causing the issue.

Using FoxyProxy is really awesome. I can in one click switch from sandbox server to hosting server from anywhere, at any IP, any port without changing the hostname or anything inside the code.

  • Do you have a local htaccess file? If so, post the contents. ALso, assume that the proper URLs are in the wp_options table. Side note: I use the WP Clone plugin to move sites from development to production. It takes care of adjusting URLs and other things during the move. Very useful for moving sites and their content - but it does overwrite the 'target' site, so is only useful for the initial move. – Rick Hellewell Aug 16 '17 at 17:59
  • Awseome thks for the tip. I sent the info in edits of the post – TheMedServ Aug 16 '17 at 19:57
0

Found the problem / the solution:

while using the proxy, the servers variable REQUEST_URI is not the same

using FoxyProxy, server var 'REQUEST_URI' return the full url:

$_SERVER['REQUEST_URI'] -> "hxxp://mydomain.com/theurl"

using windows host file, server var 'REQUEST_URI' return just the end of the url: $_SERVER['REQUEST_URI'] -> "/theurl"

so I added this to the wordpress index.php and everything works #1 :D :

$_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;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.