0

I'm migrating my application to a new host. I'm now facing a problem wit the url's. For example when I visit www.mydomain.be/public/dashboard the app redirects to myservername.azurewebsites.net/public/dashboard.

A collegue pointed me at the "Laravel routes behind reverse proxy" but this is not working for me. I googled and tried the following:

In Middleware\TrustProxies.php

protected $proxies = [
        '**'
    ];

in .env

PROXY_URL = http://www.mydomain.be/public/
PROXY_SCHEMA = https

in routes/web.phpp

    $proxy_url    = getenv('PROXY_URL');
$proxy_schema = getenv('PROXY_SCHEMA');
if (!empty($proxy_url)) {
    URL::forceRootUrl($proxy_url);
}

if (!empty($proxy_schema)) {
    URL::forceScheme($proxy_schema);
}

I also tried in routes/web.php with

URL::forceRootUrl('https://www.mydomain.be/public');

but nothing is fixing the fact that in the url-balk myservername.azurewebsites.net/public/ is shown.

  • You are redirecting, you are not proxying so any solution that assumes you are proxying will not work since you are redirecting. The solution is to proxy the connection e.g. when someone connects to the server hosting `www.mydomain.be` then **the server** connects to myservername.azurewebsites.net forwards all the request information and transfers the response back to the client. The client should never be aware that this has happened. All major webserver have capabilities to do this e.g. apache has `mod_proxy` and `mod_proxy_http` – apokryfos Mar 20 '19 at 13:43
  • so I don't have to change something in laravel but the server-settings must be changed? – Tim Vanden Hende Mar 20 '19 at 13:48
  • In Laravel you still need to modify the trusted proxies to trust the incoming connection but other than that there shouldn't be any other changes necessary. However whatever methodology you use you should know how the [forwarded headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded) are set and modify the `$headers` property in `TrustProxies` accordingly as well. – apokryfos Mar 20 '19 at 13:49

1 Answers1

0

use laravel URL facade here with forceRootUrl method (working on laravel 7.1)

Add this line into AppServiceProvider with boot meethod

URL::forceRootUrl('http://localhost/proxy/');
Jignesh Joisar
  • 13,720
  • 5
  • 57
  • 57