How to 301 Redirect from http to https after SSL installation

Once you have an SSL certificate set up onto your website and have changed all URLs that load scripts and stylesheets to run over https, it’s important to redirect your old http URL’s over to the new https.  The correct way and best for SEO is to apply a 301 redirect.

To do this, you just need to edit the .htaccess file, normally found in the root of your WordPress install or your website index file.  All you need to do is add the following (in WordPress, add it AFTER the # End WordPress line):

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

Useful post? Share it

One comment on “How to 301 Redirect from http to https after SSL installation

  1. For me the code works only before the #BEGIN WordPress line

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

    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # END WordPress

Leave a Reply

Your email address will not be published. Required fields are marked *