How to send a URL in route parameter?

后端 未结 1 1278
庸人自扰
庸人自扰 2021-01-16 13:13

I have defined a route like this :

$app->map([\'GET\', \'POST\'],\'/abc/[{url}]\', function ($request, $response, $args) {

    return $response;
})->a         


        
相关标签:
1条回答
  • 2021-01-16 14:14

    Using an url inside the url

    When you adding the url with Slashes then the route do not get execute cause then there is additional path after the url which is not definied inside the route:

    E.g. example.org/abc/test works fine but example.org/abc/http://x will only work with a route definition like this /abc/{url}//{other}.

    Using an encoded url inside the url

    Apache blocks all request with %5C for \ and %2F for / in the url with a 404 Not Found error this is because of security reasons. So you do not get a 404 from the slim framework but from your webserver. So you'r code never gets executed.

    You can enable this by setting AllowEncodedSlashes On in you'r httpd.conf of apache.

    My Recommendation to fix this

    Add the url as a get parameter there is is valid to have encode slashes without changing the apache config.

    Example call http://localhost/abc?url=http%3A%2F%2Fstackoverflow.com

    $app->map( ['GET', 'POST'], '/abc', function ($request, $response, $args) {
        $getParam = $request->getQueryParams();
        $url= $getParam['url']; // is equal to http://stackoverflow.com
    });
    
    0 讨论(0)
提交回复
热议问题