Hypertext Transfer Protocol (HTTP) and Hypertext Transfer Protocol Secure (HTTPS) are protocols that allow computers to send and receive information, such as text, images, or videos, over the internet.
For example, a website visitor’s browser uses HTTP or HTTPS to request the page and its content from the website’s server. The server sends the data back, and the browser displays the website.
HTTPS is the secure version of HTTP and uses an SSL Secure Sockets Layer (SSL) or Transport Layer Security (TLS) certificate to encrypt data.
Encryption protects data (like passwords or credit card numbers) during transfer.
You can set up redirects for Nginx (an open-source web server software) by adding rules to your configuration files.
Here are two different ways to set up redirects in Nginx:
Redirecting All HTTP Sites to HTTPS
Redirecting all HTTP sites to HTTPS is ideal when you have multiple domains under a particular Nginx configuration and multiple SSL certificates.
Follow these instructions:
Open your Nginx configuration (nginx.conf) file or the relevant server block file, usually found in “/etc/nginx/.” If the file doesn’t exist, you may need to create a new one.
Add a server block (code) to the configuration file to catch all traffic on port 80 (traffic coming through the HTTP version of your sites) and redirect traffic to the HTTPS version:
Locate your server’s terminal and test your configuration by running the command sudo nginx -t. The output will show you if you have any errors, so you know what to fix.
If your test is successful, reload Nginx, so your changes take effect by running the command sudo systemctl reload nginx
Redirecting Specific Sites
Redirect specific sites if you have multiple apps or sites and don’t require an SSL certificate for each one.
Here’s how:
Open your Nginx configuration (nginx.conf) file or the relevant server block file, usually found in “/etc/nginx/.’ If the file doesn’t exist, you may need to create a new one.
Add this server block to the configuration file to redirect HTTP traffic to HTTPS
server { listen 80; server_name example.com; return 301 https://example.com$request_uri; }
Locate your server’s terminal and test your configuration by running the command sudo nginx -t. The output will show you if you have any errors so you know what to fix.
If your test is successful, reload Nginx, so your changes take effect by running the command sudo systemctl reload nginx
How to Redirect to HTTPS in Windows IIS
Redirect HTTP to HTTP in Windows IIS (a web software server from Microsoft) by editing your web.config file.
Follow these steps:
Download and install the (download the IIS URL Rewrite Module if you haven’t installed it). Then, open your IIS manager.
Select your site in the menu to the left. And click “URL Rewrite.”
Click “Add Rule(s)…,” choose “Blank Rule,” then name your rule.
Set the fields to “Matches the Pattern,” “Regular Expressions,” and “(.*)” And check the box next to “Ignore case.”
In the next window, set the fields to “{HTTPS},” “Matches the Pattern,” and “^OFF$.” And check the box next to “Ignore case.”
Once you get to the “Action” section, choose “Redirect” under “Action type” and set the destination to “https://{HTTP_HOST}/{R:1}.” And check the box next to “Append query string.”
Click “Apply.”
How to Do an HTTP Redirect in Apache
Set up HTTPS redirection in Apache by using an Apache Virtual Host or modifying the .htaccess file.
Redirecting with Apache Virtual Host
Redirect with Apache Virtual Host if you have full control over your server’s configuration files and want to manage files at the server level.
Here’s how:
Open your Virtual Host file in a text editor. Virtual Host files are usually found in “/etc/apache2/sites-available/.” The file name often corresponds to your domain (e.g., “yourdomain.conf”)
Set up a Virtual Host on port 80 by adding this block to your file:
Make sure a Virtual Host block with your SSL certificate details exists. This block may be in the same file you're working on or in a separate file. Add this block if you don’t have a Virtual Host block:
You can redirect HTTP to HTTPS with an .htaccess file if you don’t have access to your server’s configuration files.
Follow these steps:
Locate the .htaccess file in your site’s root directory
Open the file and add this code:
RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Save the file and check to make sure the redirect works. If it doesn’t, you may need to speak with your host and ask them to configure your server to allow .htaccess overrides in Apache’s main configuration file.
How to Verify the HTTPS Version of Your Site
Verifying the HTTPS version of your site ensures that the redirect works and will point both users and search engines to the correct version.
To do this, enter both the HTTP and HTTPS versions of your domain into a browser bar. You should end up on the HTTPS version in either case.
Next, verify the HTTPS version of your site in Google Search Console to make sure you can properly track performance:
Go to Search Console, sign in, and add a new property using your HTTPS URL prefix (for example, “https://yourdomain.com/”). Then click “Continue.”
Complete ownership verification using the recommended method
Click the drop-down to see that your website has been verified. Verified sites appear at the top of the list.
Check Your HTTPS Implementation for Issues
Moving to HTTPS can sometimes lead to unexpected problems like mixed content (when content loads in HTTP and HTTPS), which you can find with Semrush’s Site Audit tool.
The tool will bring you to a page with a list of issues you may want to fix.
For example, the audit below shows the site has an HTTP URL in its sitemap (i.e., a file outlining the structure of the site).
Click “Why and how to fix it” next to any issue that’s flagged to learn about it and how to address the problem.
Regular audits like this can ensure your site remains secure, fully optimized, and reliable for your visitors.
Want to check your HTTPS implementation?
Try Site Audit for free.
Share
Connor Lahey
Connor Lahey is a content strategist with over a decade of experience in content and SEO roles for both local businesses and large companies. He specializes in content strategy, search intent analysis, on-page SEO, local SEO, and SaaS SEO.