Author Topic: Correct HTTP to HTTPS redirect  (Read 12431 times)

0 Members and 1 Guest are viewing this topic.

Offline
*
Correct HTTP to HTTPS redirect
« on: March 15, 2018, 10:25:27 PM »
Hi! I have weird problem - when I have HTTP to HTTPS redirect in my .htaccess

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

- my php and MySql code runs twice. I'm logging words, that users search on my site. If it is a first occurance - I INSERT it to the table with counter = 1. If word already exist in the table, then conter +1. When redirect is on, new words get counter=2 from the first search. If I turn off redirect - everything is ok - counter=1.

So, what is the best way to redirect to HTTPS?

I'm using the latest CWP7, PHP 7.2.3, MariaDB 10.2.13. Plain PHP - no frameworks or CMS
« Last Edit: March 15, 2018, 10:34:33 PM by dMole »

Offline
*
Re: Correct HTTP to HTTPS redirect
« Reply #1 on: March 15, 2018, 11:37:09 PM »
hi I use :

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

Offline
**
Re: Correct HTTP to HTTPS redirect
« Reply #2 on: March 15, 2018, 11:40:56 PM »
Code: [Select]
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]