Answer the question
In order to leave comments, you need to log in
How to set up a redirect to https in .htaccess?
In general, the site on Wordpress, in htasses now is this
# BEGIN WordPress
<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
Answer the question
In order to leave comments, you need to log in
https://www.reg.ru/support/hosting-i-servery/sajty...
RewriteEngine On
RewriteCond %{HTTPS} =off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [QSA,L]
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
here is another option
RewriteCond %{ENV:HTTPS} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Who DOES NOT help anything, like me.
This site online-generators.ru is connected to CloudFlare . There were problems with him.
It was decided this way: we go into the CloudFlare account in the Page Rules section. There we set the rule to redirect all pages of the site to a secure protocol.
RewriteCond %{HTTP:X-HTTPS} !1
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
masterhost
RewriteCond %{HTTP:PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
https://www.sslshopper.com/apache-redirect-http-to...
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Hosting active.by (if anyone needs it):
RewriteCond %{ENV:HTTPS} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
for hts.ru hosting
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:X-SSL} !^yes$
RewriteRule (.*) https://gu77.ru/$1 [R=301,L]
</IfModule>
For Gino Hosting
RewriteEngine On # Если этой строки нет выше
RewriteCond %{HTTP:X-Forwarded-Protocol} !=https
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
This option helped me.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Helped me like this:
RewriteEngine On
RewriteCond %{HTTP:SSL} !1
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [QSA,L,R=301]
For a static / self-written site in PHP (not Wordpress) on Timeweb hosting, the code helped me:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^site.ru[nc]
RewriteRule ^(.*)$ https://site.ru/$1 [r=301,nc]
# или RewriteRule ^(.*)$ https://www.site.ru/$1 [r=301,nc] если нужно с www
Using the free Let's Encrypt SSL certificate, the rule should end up looking like this:
# SSL
RewriteCond %{REQUEST_FILENAME} !^/\.well-known(.*)$
RewriteCond %{HTTP:X-HTTPS} !1
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
Here is a working version
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
After adding this code to .htaccess, the following problem may occur:
"website *site.name* redirected too many times."
To avoid this, you need to add the following not to .htaccess, but to wp-config:
define('FORCE_SSL_ADMIN', true);
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
$_SERVER['HTTPS']='on';
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Protocol} !=https
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
Temporarily threw the new engine into the folder below the root of the old site and only "Option 3" from Geograph helped (the rest threw it to the root) .
Thank you))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question