htaccess wordpress 301 redirect

I recently added SSL to my wordpress site and now if some goes to my http site, I would like to redirect them to my https site. I have tried the following below:

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase / 
RewriteRule ^index.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] 
RewriteRule . /index.php [L] 
</IfModule> 
# END WordPress

But got this error

Read More
Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.

What am I doing wrong?

Related posts

Leave a Reply

2 comments

  1. Here is the code that you should use for enforcing https:

    # BEGIN WordPress 
    <IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase / 
    
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 
    
    RewriteRule ^index.php$ - [L] 
    
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L] 
    </IfModule> 
    # END WordPress
    
  2. Try this :

    RewriteEngine on
    
    RewriteCond %{SERVER_PORT} 80
    
    RewriteRule ^(.*)$ https://{SERVER_NAME}/$1 [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^www.(.*)
    
    RewriteRule ^(.*)$ https://{SERVER_NAME}/$1 [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^http://.(.*)
    
    RewriteRule ^(.*)$ https://{SERVER_NAME}/$1 [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    
    RewriteCond %{REQUEST_FILENAME} -d
    
    RewriteRule ^.*$ - [NC,L]
    
    RewriteRule ^.*$ /index.php [NC,L]