How To Do 301 Redirect From HTTP to HTTPS In Apache, Nginx, IIS, and Hostinger

===================================
PAID TRAINING ADS

Upcoming SEO / WordPress bootcamps



1-on-1 SEO Consulting and Coaching - Exclusive to those working as SEOs already - All info here - All info here

PAID TRAINING ADS
===================================

To perform a 301 redirect from HTTP to HTTPS, you’ll need to configure your web server correctly. Below are the steps for common web servers:


1. Apache

Modify your .htaccess file or the server configuration file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
  • Ensure that the mod_rewrite module is enabled.
  • Place this code in your .htaccess file or within the <VirtualHost> block of your Apache configuration.

2. Nginx

Modify your server block configuration file:

server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;
    return 301 https://$host$request_uri;
}
  • Replace yourdomain.com and www.yourdomain.com with your domain name.
  • Restart Nginx with: sudo systemctl restart nginx

3. IIS (Windows Server)

Use the IIS Manager to set up a redirect:

  1. Open IIS Manager.
  2. Select your site.
  3. Double-click HTTP Redirect.
  4. Check Redirect requests to this destination and enter your HTTPS URL.
  5. Check Redirect all requests to exact destination (rather than relative to destination).
  6. Set the redirection type to Permanent (301).

4. .htaccess Alternative (if not using mod_rewrite)

You can also use mod_alias:

Redirect 301 / https://yourdomain.com/

Testing

  • Test the redirect using your browser.
  • You can also use online tools like Redirect Checker to verify that a 301 Moved Permanently status is returned.

If you’re hosting your website on Hostinger, you can set up a 301 redirect from HTTP to HTTPS by editing the .htaccess file or using the Hostinger control panel.


5. Hostinger

Method 1: Edit .htaccess File

  1. Log in to your Hostinger account.
  2. Navigate to File Manager (under Hosting → Manage → Files).
  3. Open the public_html directory and locate the .htaccess file.
    • If it doesn’t exist, create a new .htaccess file.
  4. Add the following code to redirect HTTP to HTTPS: RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
  5. Save the changes.

Method 2: Use Hostinger Control Panel

  1. Log in to your Hostinger account.
  2. Go to Hosting → Manage for your website.
  3. Under the Advanced section, click on SSL/TLS.
  4. Ensure that an SSL certificate is installed and active.
  5. Enable the Force HTTPS option to automatically redirect HTTP to HTTPS.

Testing

  • After making these changes, visit your website with http:// and verify it redirects to https://.
  • Use tools like Redirect Checker to confirm the status code is 301.

Chinkee Tan Interviews Coach Katherine Padilla About Freelancing

X