Home > Software design >  Wordpress: Force HTTPS using .htaccess
Wordpress: Force HTTPS using .htaccess

Time:01-11

Problem Using .htaccess to force HTTPs on my Wordpress site does not work

Tried solution On my Wordpress site I have the following .htaccess code

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

But to force using HTTPs I'am trying to replace it with this code:


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} mydomain\.dk [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mydomain.dk/$1 [R,L]
</IfModule>

Result The website is no longer working (here is the website response):

This page isn’t working
www.mydomain.dk redirected you too many times.

Try clearing your cookies.
ERR_TOO_MANY_REDIRECTS

Questions

  1. Why can't I force using HTTPs on my Wordpress website?
  2. What can I do to make it work?

Best regards, Henning

CodePudding user response:

Before trying the surggested solutions - I tried to change the URL in the Wordpress settings to HTTPS and now it works.

Thanks for taking the time to answer my question, I was just about to try the Really Simple SSL plugin.

CodePudding user response:

If your web server is running Apache, you can redirect all HTTP traffic to HTTPS by returning to the default .htaccess configuration and than adding the following code to your .htaccess file. This is also the recommended method for redirecting WordPress to Apache:

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

However, probably the easiest way to implement HTTPS on your WordPress site would be to install the following plugin:

https://wordpress.org/plugins/really-simple-ssl/

  •  Tags:  
  • Related