S
S
Sergey Nozdrin2016-02-10 12:19:55
Computer networks
Sergey Nozdrin, 2016-02-10 12:19:55

How to make a proper redirect from http to https?

Good afternoon!
I recently connected an SSL certificate to a WordPress site https://suvorovski.ru At the moment, the site is available via both http and https protocols. I want to make a 301 redirect from http to https through the .htaccess file in the root of the site for all pages of the site.
I thought that the task was simple, but I got confused in the end. Here, I ask for help.
Right now my .htaccess file looks like this:

# BEGIN WordPress

<Files wp-login.php>
Order Deny,Allow
Deny from all
</Files>

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

# END WordPress

I also found that redirecting from http to https looks like this:
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI}

But where to put this code? If I just add it to my .htaccess file, a 500 error will occur and the site will crash (probably because of the redirect loop). If you leave only this code and remove everything else, then the redirect will work, but all pages except the main one will give a 404 error.
How can I write the correct .htacess file for my task? Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Burov, 2016-02-10
@light204

RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
to the very beginning

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question