Redirection from http to https
Good afternoon.
It costs Apache+nginx in .htaccess
I add
RewriteCond %{HTTP_HOST} ^site\.com\.ua [NC,OR]
RewriteCond %{HTTP:X-Forwarded-Proto} ^http$ [NC]
RewriteRule ^(.*)$ https://site.com.ua$1 [R=301,L]
Writes that На этой странице обнаружена циклическая переадресация
.
How to fix I need this redirection.
P. s. Thank you in advance.
1
2 answers
As an option:
RewriteEngine On
# This will enable the Rewrite capabilities
RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e. http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context
Source https://wiki.apache.org/httpd/RewriteHTTPToHTTPS
2nd option:
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [QSA,R=301,L]
4
Author: Visman, 2017-08-01 12:54:27
Error reason
Round-robin redirects occur due to your use of the logical "or": [OR]
.
See what happens for the address http://site.com.ua [NC,OR]
:
- The condition
RewriteCond %{HTTP_HOST} ^site\.com\.ua [NC,OR]
{[16 is triggered]} - The condition {[4] is triggered]}
- Redirects to
https://site.com.ua
- The condition
RewriteCond %{HTTP_HOST} ^site\.com\.ua [NC,OR]
{[16 is triggered]} - The second condition does not work, but it is not necessarily due to
[OR]
- Redirects to
https://site.com.ua
- Looping, starting from 4 points.
Solution
RewriteEngine on
RewriteCond %{HTTP_HOST} ^site\.com\.ua [NC]
RewriteCond %{HTTP:X-Forwarded-Proto} ^http$
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
2
Author: VenZell, 2015-08-06 07:52:57