Apache Http To Https Redirection

Posted on  by admin
  1. Apache Http To Https Redirection Portal
  2. Http To Https Redirect

You’ve bought your SSL secure certificate and successfully installed on Tomcat with the keytool but how do your redirect the entire site to go HTTPS and redirect any HTTP connection straight over to HTTPS.

You need to edit the 2 Tomcat configuration files; server.xml and web.xml and then when edited restart the tomcat service.

For eg this above snippet will redirect all request to http:www.example.com to https:www.example.com This ofcourse is the apache recommended way. But how would we redirect http to https even if request is based on IP. The first step to redirect HTTP to HTTPS involves editing of.htaccess file via FTP or cPanel & then redirect to HTTPS in Apache/NGINX.

Open server.xml typically found in tomcat/conf and change:

For eg this above snippet will redirect all request to http:www.example.com to https:www.example.com This ofcourse is the apache recommended way. But how would we redirect http to https.

to

Then openweb.xml (same directory) and add this snippet before the closing tag of /web-app:

Restart Tomcat and all pages should redirect to https.

-->

You can use the Azure portal to create a Front Door with a certificate for TLS termination. A routing rule is used to redirect HTTP traffic to HTTPS.

Create a Front Door with an existing Web App resource

  1. Sign in to the Azure portal at https://portal.azure.com.

  2. Select Create a resource found on the upper left-hand corner of the Azure portal.

  3. Search for Front Door using the search bar and once you find the resource type, select Create.

  4. Choose a subscription and then either use an existing resource group or create a new one. Select Next to enter the configuration tab.

    Note

    The location asked in the UI is for the resource group only. Your Front Door configuration will get deployed across all of Azure Front Door's POP locations.

  5. The configuration for Front Door happens in three steps - adding a default frontend host, adding backends in a backend pool and then creating routing rules to map the routing behavior for frontend host. Select the '+' icon on the Frontend hosts to create a frontend host.

  6. Enter a globally unique name for your default frontend host for your Front Door. Select Add to continue to the next step.

Create Backend Pool

  1. Select the '+' icon on the Backend pools to create a backend pool. Provide a name for the backend pool and then select Add a backend.

  2. Select the Backend Host Type as App service. Select the subscription where your web app is hosted and then select the specific web app from the dropdown for Backend host name.

  3. Select Add to save the backend and select Add again to save the backend pool config.

Tomcat

Create HTTP to HTTPS redirect rule

  1. Select the '+' icon on the Routing rules to create a route. Provide a name for the route, for example 'HttpToHttpsRedirect', and then set the Accepted Protocol field to 'HTTP only'. Ensure that the appropriate Frontend/domains is selected.

  2. Under the Route Details section, set the Route Type to Redirect. Ensure that the Redirect type get set to Found (302) and Redirect protocol get set to HTTPS only.

  3. Select Add to save the routing rule for HTTP to HTTPS redirect.

Apache Http To Https Redirection Portal

Create forwarding rule

Https
  1. Add another routing rule to handle the HTTPS traffic. Select the '+' sign on the Routing rules and provide a name for the route, for example 'DefaultForwardingRoute'. Then set the Accepted Protocols field to HTTPS only. Ensure that the appropriate Frontend/domains is selected.

  2. On the Route Details section, set the Route Type to Forward. Ensure that the right backend pool gets selected and the Forwarding Protocol is set to HTTPS only.

  3. Select Add to save the routing rule for request forwarding.

  4. Select Review + create and then Create, to create your Front Door profile. Go to the resource once created.

Http To Https Redirect

Next steps

  • Learn how Front Door works.
  • Learn more about URL redirect on Front Door.