TheMedServ
TheMedServ

Reputation: 1

Wordpress + Local host proxy

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 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

I am out of options here. Thanks!

Upvotes: 0

Views: 164

Answers (2)

TheMedServ
TheMedServ

Reputation: 1

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

Upvotes: 0

Moh .S
Moh .S

Reputation: 2090

step 1: Edit your hosts file and add the domain you want, in my case it is dark.dev.com, like this 127.0.0.1 dark.dev.com.

step 2: Go to settings in your wordpress admin dashboard and edit both the Site Address (URL), and WordPress Address (URL) with your new domain name i.e dark.dev.com

Upvotes: 0

Related Questions