How to Redirect HTTP to HTTPS (4 Methods)

5 months ago 83
ARTICLE AD BOX

What Are HTTP and HTTPS?

Hypertext Transfer Protocol (HTTP) and Hypertext Transfer Protocol Secure (HTTPS) are protocols that let computers to nonstop and person information, specified arsenic text, images, oregon videos, implicit the internet.

For example, a website visitor’s browser uses HTTP oregon HTTPS to petition the leafage and its contented from the website’s server. The server sends the information back, and the browser displays the website.

HTTPS is the unafraid mentation of HTTP and uses an SSL Secure Sockets Layer (SSL) oregon Transport Layer Security (TLS) certificate to encrypt data. 

Encryption protects information (like passwords oregon recognition paper numbers) during transfer. 

Here’s an illustration of however HTTPS works:

A browser connects to a server with a idiosyncratic    ID and password. With HTTPS, a hacker sees an encrypted idiosyncratic    ID and password.

Why Should You Redirect HTTP to HTTPS?

You should redirect HTTP to HTTPS due to the fact that it protects delicate accusation and tin boost your website’s quality to fertile (appear) precocious successful search motor results pages (SERPs).

A due redirect sends postulation from the non-secure HTTP mentation of your tract to the unafraid HTTPS one.

If you bargain an SSL certificate from your hosting provider, your big volition usually grip the redirect automatically.

But you mightiness request to unit the redirect manually if you person a customized setup. 

The nonstop process tin alteration based connected the benignant of server you use, truthful we’ll spell implicit a fistful of ways to bash this.

How to Redirect HTTP to HTTPS successful WordPress

You tin redirect HTTP to HTTPS successful WordPress with a plugin oregon by editing your files manually. 

Here’s however to bash both: 

Using a Plugin

WordPress plugins similar Really Simple Security connection no-code solutions to redirect from HTTP to HTTPS.

Here’s however to usage it:

Log successful to your WordPress account. Head to “Plugins” and hunt for “Really Simple Security.”

Click “Install Now” and activate the plugin aft installation is complete.

AD_4nXeAUWTrMvBPDjKd5CI3h9q0pprtajAbfPfs8ehjEuuaA--pGXIIyGGg-6dxK7jF21uLlfKIEbgMkCWyXogitdh31X_VKMA5ckBqEqyvH7xIVPUXE-igAjTHjYZaOTgWh_HlGoovGA?key=slCHbKjVXUUuIXzUZmE_M-EU

Follow the plugin’s onboarding wizard. It volition inquire you to supply accusation similar your big and email code to trial the configuration.

The setup wizard detects an SSL certificate.

Your tract should automatically guardant users and hunt engines to the HTTPS mentation of your tract erstwhile you’ve completed the onboarding flow.

Editing WordPress Files Manually

Edit WordPress files manually if you similar a hands-on attack oregon if your hosting situation won’t let a plugin.

Go to your WordPress dashboard to get started. 

Click “Settings,” prime “General,” and find “WordPress Address (URL)” and “Site Address (URL).”

Replace “http://” with “https://” successful some URL fields.

To redirect http to https successful  WordPress, the URL is updated.

Click “Save Changes.”

Then, you’ll request to edit your configuration files (i.e., files utilized to customize your web server).

Then record you request to edit depends connected which server hosts your website:

  • For an Apache server: Edit your .htaccess file (a configuration record often recovered successful your basal folder) with this code:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  • For a Windows IIS server: Update the web.config record (a configuration record usually recovered successful your basal directory)

<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Force HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

How to Set Up an HTTP Redirect successful Nginx

You tin acceptable up redirects for Nginx (an open-source web server software) by adding rules to your configuration files.

Here are 2 antithetic ways to acceptable up redirects successful Nginx:

Redirecting All HTTP Sites to HTTPS

Redirecting each HTTP sites to HTTPS is perfect erstwhile you person aggregate domains nether a peculiar Nginx configuration and aggregate SSL certificates.

Follow these instructions:

  1. Open your Nginx configuration (nginx.conf) record oregon the applicable server artifact file, usually recovered successful “/etc/nginx/.” If the record doesn’t exist, you whitethorn request to make a caller one.
  1. Add a server artifact (code) to the configuration record to drawback each postulation connected larboard 80 (traffic coming done the HTTP mentation of your sites) and redirect postulation to the HTTPS version:

server { 
listen 80 default_server; 
server_name _; 
return 301 https://$host$request_uri; 
}

  1. Add different server artifact listening connected larboard 443 with your SSL certificate details for each domain:

server {
listen 443 ssl;
server_name www.example.com;
ssl_certificate www.example.com.crt;
ssl_certificate_key www.example.com.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
...
}

  1. Locate your server’s terminal and trial your configuration by moving the bid sudo nginx -t. The output volition amusement you if you person immoderate errors, truthful you cognize what to fix.
  1. If your trial is successful, reload Nginx, truthful your changes instrumentality effect by moving the bid sudo systemctl reload nginx

Redirecting Specific Sites

Redirect circumstantial sites if you person aggregate apps oregon sites and don’t necessitate an SSL certificate for each one.

Here’s how:

  1. Open your Nginx configuration (nginx.conf) record oregon the applicable server artifact file, usually recovered successful “/etc/nginx/.’ If the record doesn’t exist, you whitethorn request to make a caller one.
  1. Add this server artifact to the configuration record to redirect HTTP postulation to HTTPS

server {
listen 80;
server_name example.com;
return 301 https://example.com$request_uri;
}

  1. Locate your server’s terminal and trial your configuration by moving the bid sudo nginx -t. The output volition amusement you if you person immoderate errors truthful you cognize what to fix.
  1. If your trial is successful, reload Nginx, truthful your changes instrumentality effect by moving the bid sudo systemctl reload nginx

How to Redirect to HTTPS successful Windows IIS

Redirect HTTP to HTTP successful Windows IIS (a web bundle server from Microsoft) by editing your web.config file. 

Follow these steps:

  1. Download and instal the (download the IIS URL Rewrite Module if you haven’t installed it). Then, unfastened your IIS manager.
  1. Select your tract successful the paper to the left. And click “URL Rewrite.”
AD_4nXc9AaC4N64kTtVID6rD9rzPFIIjWdZINg7sdOumfWUKz6MRX-rWpfu03CVY5rax333xUnzxdB5EmpvkV5IClzNjmWmh5NqynhyywEIEDVca-ZWtO6xyQ_lTZ2Zbydu3-cwJ3bFkZA?key=slCHbKjVXUUuIXzUZmE_M-EU
  1. Click “Add Rule(s)…,” take “Blank Rule,” past sanction your rule. 
  1. Set the fields to “Matches the Pattern,” “Regular Expressions,” and “(.*)” And cheque the container adjacent to “Ignore case.”
Name the inbound rule, "HTTP to HTTPS."
  1. In the adjacent window, acceptable the fields to “{HTTPS},” “Matches the Pattern,” and “^OFF$.” And cheque the container adjacent to “Ignore case.”
  1. Once you get to the “Action” section, take “Redirect” nether “Action type” and acceptable the destination to “https://{HTTP_HOST}/{R:1}.” And cheque the container adjacent to “Append query string.”
Redirect benignant   is acceptable   to imperishable  301.
  1. Click “Apply.”

How to Do an HTTP Redirect successful Apache

Set up HTTPS redirection successful Apache by utilizing an Apache Virtual Host oregon modifying the .htaccess file.

Redirecting with Apache Virtual Host

Redirect with Apache Virtual Host if you person afloat power implicit your server’s configuration files and privation to negociate files astatine the server level. 

Here’s how:

  1. Open your Virtual Host record successful a substance editor. Virtual Host files are usually recovered successful “/etc/apache2/sites-available/.” The record sanction often corresponds to your domain (e.g., “yourdomain.conf”)
  1. Set up a Virtual Host connected larboard 80 by adding this artifact to your file:

<VirtualHost *:80>
ServerName yourdomain.com
Redirect 301 / https://yourdomain.com/
</VirtualHost>

  1. Make definite a Virtual Host artifact with your SSL certificate details exists. This artifact whitethorn beryllium successful the aforesaid record you're moving connected oregon successful a abstracted file. Add this artifact if you don’t person a Virtual Host block:

<VirtualHost *:443> 
ServerName yourdomain.com 
SSLEngine on 
SSLCertificateFile /path/to/your/certificate.crt 
SSLCertificateKeyFile /path/to/your/certificate.key /path/to/your/certificate.key </VirtualHost>

  1. Save and adjacent the configuration file
  1. Restart Apache for the changes to instrumentality effect

Redirecting with .htaccess

You tin redirect HTTP to HTTPS with an .htaccess record if you don’t person entree to your server’s configuration files.

Follow these steps:

  1. Locate the .htaccess record successful your site’s basal directory
The basal   directory successful  this illustration  is public_html. Then, take  .htaccess.
  1. Open the record and adhd this code:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  1. Save the record and cheque to marque definite the redirect works. If it doesn’t, you whitethorn request to talk with your big and inquire them to configure your server to let .htaccess overrides successful Apache’s main configuration file. 

How to Verify the HTTPS Version of Your Site

Verifying the HTTPS mentation of your tract ensures that the redirect works and volition constituent some users and hunt engines to the close version.

To bash this, participate some the HTTP and HTTPS versions of your domain into a browser bar. You should extremity up connected the HTTPS mentation successful either case.

Next, verify the HTTPS mentation of your tract successful Google Search Console to marque definite you tin decently way performance:

  1. Go to Search Console, motion in, and adhd a caller spot utilizing your HTTPS URL prefix (for example, “https://yourdomain.com/”). Then click “Continue.”
AD_4nXfipANy6uan5wjSKHi5EAdeP3H5Clau4oXidcl7FBshb6eZnex5tTU8BzRqszsbEcQOpj3toKUjwGDiXqYUpfMyDLF8qaOaVG3qOTx-gibhafbrLE5_Io2Wl3ZyGlSqJ82zZoNJvw?key=slCHbKjVXUUuIXzUZmE_M-EU
  1. Complete ownership verification utilizing the recommended method
The recommended method is via HTML file. Steps accidental    to download the file, upload to your site, past    click Verify to continue.
  1. Click the drop-down to spot that your website has been verified. Verified sites look astatine the apical of the list.
In Google Search Console, verified and not verified properties are shown.

Check Your HTTPS Implementation for Issues

Moving to HTTPS tin sometimes pb to unexpected problems similar mixed contented (when contented loads successful HTTP and HTTPS), which you tin find with Semrush’s Site Audit tool. 

After configuring Site Audit, click “View details” nether HTTPS.

Site Audit overview shows reports, tract  health, method  SEO errors, and HTTPS circumstantial  issues.

The instrumentality volition bring you to a leafage with a database of issues you whitethorn privation to fix.

For example, the audit beneath shows the tract has an HTTP URL successful its sitemap (i.e., a record outlining the operation of the site).

The mistake  says, "1 HTTP URL successful  sitemap.xml for HTTPS site."

Click “Why and however to hole it” adjacent to immoderate contented that’s flagged to larn astir it and however to code the problem.

The popular  up   explains the contented   and says to regenerate  each  HTTP URLs successful  your sitemap with HTTPS URLs.

Regular audits similar this tin guarantee your tract remains secure, afloat optimized, and reliable for your visitors.

Want to cheque your HTTPS implementation?

Try Site Audit for free.