PHP, How to Redirect/Forward HTTP Request with header and body?

前端 未结 3 1383
故里飘歌
故里飘歌 2021-01-30 09:14

I have a PHP page, main.php which is on server 1.

I have a PHP page main.php (same page, different code) on server 2.

main.php is a WebService.

I would l

3条回答
  •  无人及你
    2021-01-30 10:03

    If you have access to the Apache server config you can create a virtualhost with the following settings:

    ProxyPreserveHost Off
    ProxyPass / http://remotesite.domain.tld/
    ProxyPassReverse / http://remotesite.domain.tld/
    ProxyPassReverseCookieDomain remotesite.domain.tld proxysite.tld
    

    You'll need to enable mod_proxy and mod_proxy_http for this. Substitute remotesite.domain.tld to the site you forward to, and proxysite.tld to the forwarder.

    If you don't have access to the server config files, you can still do in php, by manually setting up curl and forward everything.

    
    

    EDIT:

    And of course the script must be in the root directory of a (sub)domain. And you should have a .htaccess that rewrites everything to it:

    RewriteEngine On
    RewriteRule .* index.php
    

提交回复
热议问题