Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Redirect all http request to https requests using apigee

Not applicable

Hi,

I have a webservice with http url. I want to apply https on top of it using apigee and want to redirect all http requests coming for that webservice url into https requests and then process through apigee other message processors.

I understood that by removing <VirtualHost>default</VirtualHost> from the api proxy xml, it will not allow http request and <VirtualHost>secure</VirtualHost> is for allowing https requests to the API.

But i want to redirect http requests to https using some configuration. Please let me know.

Solved Solved
0 12 4,277
1 ACCEPTED SOLUTION

Yes, you can.

First, add back the VirtualHost "default" to allow inbound http.

Then you must add a condition that checks client.scheme and compares it to http. And in that case, execute a JS policy that computes the https redirect URL, and execute a RaiseFault policy to send it back. Something like this.

<PreFlow name="preflow">
  <Request>
     <Step>
       <Name>JS-SetSecureUrl</Name>
       <Condition>client.scheme = "http"</Condition>
     </Step>
     <Step>
       <Name>RF-Issue302Redirect</Name>
       <Condition>client.scheme = "http"</Condition>
     </Step>
  </Request>
</PreFlow>

The RF (RaiseFault) policy just sets a Header called "Location" to a specific value, determined by a context variable.

The JS (JavaScript) policy sets the context variable. To figure out the JavaScript you need, you can refer to this documentation, which describes how to re-assemble the inbound URL .

View solution in original post

12 REPLIES 12