totemofwolf commented on issue #900: bug: Too many redirects when setting `http to https` by redirect plugin URL: https://github.com/apache/incubator-apisix/issues/900#issuecomment-558961674 > > I have found the root cause of this problem, which the use of plugin is not determined by conditions. For the above example, request **http://gitea.nsa.work** and **https://gitea.nsa.work** are the same, the plugin `redirect` will be enabled. So I think the plugins should support the condition filtering or Do you have any other ideas? > > @moonming @membphis > > Sorry for my limited understanding. Condition filtering has been already supported in route, but does not support in the UI. > > For the above example, two routes should be configured. One for HTTP and another for HTTPS. > > Create route via `/apisix/admin/routes` Like below: > > For HTTP route: > > ```json > { > "uris":[ > "/hello" > ], > "hosts":[ > "abc.com" > ], > ... > ... > "vars": [ > ["scheme", "==", "http"] > ], > "plugins":{ > "redirect":{ > "uri":"https://abc.com:9443\${uri}", > "ret_code":302 > } > } > } > ``` > > For HTTPS route: > > ```json > { > "uris":[ > "/hello" > ], > "hosts":[ > "abc.com" > ], > ... > "plugins":{ > }, > "vars":[ > ["scheme", "==","https"] > ] > } > ``` > > It seems that APISIX capabilities has been prefected, but the UI cannot keep up with its progress. > @totemofwolf it works. 👍🏻 # Https route also need `upstream_id` Below is the success test case: @moonming @membphis ``` # for http # curl -i 127.0.0.1:9180/apisix/admin/routes -X POST -d '{"uris":["/*"],"hosts":["gitea.nsa.work"],"vars":[["scheme", "==", "http"]],"upstream_id":"00000000000000000043","plugins":{"redirect":{"ret_code":302,"uri":"https://gitea.nsa.work"}},"desc":"gitea.nsa.work"}' HTTP/1.1 201 Created Date: Wed, 27 Nov 2019 06:50:12 GMT Content-Type: text/plain Transfer-Encoding: chunked Connection: keep-alive Server: APISIX web server {"node":{"value":{"plugins":{"redirect":{"uri":"https:\/\/gitea.nsa.work","ret_code":302}},"uris":["\/*"],"hosts":["gitea.nsa.work"],"vars":[["scheme","==","http"]],"desc":"gitea.nsa.work","upstream_id":"00000000000000000043"},"createdIndex":76,"key":"\/apisix\/routes\/00000000000000000076","modifiedIndex":76},"action":"create"} # for https # curl -i 127.0.0.1:9180/apisix/admin/routes -X POST -d ' { "uris":[ "/*" ], "hosts":[ "gitea.nsa.work" ], "plugins":{ }, "vars":[ ["scheme", "==","https"] ], "upstream_id":"00000000000000000043" }' HTTP/1.1 201 Created Date: Wed, 27 Nov 2019 07:03:08 GMT Content-Type: text/plain Transfer-Encoding: chunked Connection: keep-alive Server: APISIX web server {"node":{"value":{"plugins":{},"uris":["\/*"],"hosts":["gitea.nsa.work"],"vars":[["scheme","==","https"]],"upstream_id":"00000000000000000043"},"createdIndex":77,"key":"\/apisix\/routes\/00000000000000000077","modifiedIndex":77},"action":"create"} # test ➜ ~ curl -I http://gitea.nsa.work HTTP/1.1 302 Moved Temporarily Date: Wed, 27 Nov 2019 07:03:50 GMT Content-Type: text/html Content-Length: 215 Connection: keep-alive Location: https://gitea.nsa.work Set-Cookie: SERVERID=69e48c1ea229c07f80a7f37ab0f0d76f|1574838230|1574838230;Path=/ ➜ ~ curl -I https://gitea.nsa.work HTTP/2 200 content-type: text/html; charset=UTF-8 date: Wed, 27 Nov 2019 07:03:55 GMT server: APISIX web server x-request-id: 001ae571f90aaa7c0024d40a602b2b3f x-protected-by: OpenRASP x-content-type-options: nosniff x-download-options: noopen x-frame-options: sameorigin x-xss-protection: 1; mode=block ```
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
