Redirect .htaccess to ssl is not working

I’m trying to redirect xyz.com to https://xyz.com

My code

Read More
# BEGIN WordPress
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^xyz.com$
RewriteRule ^(.*)$ https://xyz.com/$1 [R=301]

RewriteRule ^index.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*.php)$ $1 [L]
RewriteRule . index.php [L]
RewriteRule ^(.*/)?sitemap.xml wp-content/sitemap.php [L]

# END WordPress

and also i try the following code

RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www.)?(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

it shows this error
The page isn’t redirecting properly

actually it’s a WordPress site.

how to solve that problem?

Thanks in advance

Related posts

Leave a Reply

4 comments

  1. Have your rule as this:

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} ^www. [NC]
    RewriteRule ^ https://xyz.com%{REQUEST_URI} [R=301,L]
    

    Also make sure in your WP permalink settings you have home and site URL reflecting https://xyz.com/

  2. Please add the below code to your .htaccess file to redirect whole site to https.

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

    If you want to redirect selected pages, then rewrite rule as below.

    RewriteRule ^page1(.*) https://%{SERVER_NAME}/page1$1 [R,L]
    

    If you prefer plugin, you can use this plugin: https://wordpress.org/plugins/https-redirection/.