-1

I would like to improve the method ,instead of working to use HTTP

Our method is :

<VirtualHost *:80>
    ServerName example.com
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^example.com
    RewriteRule ^(.*)$ https://example.com/$1?referer_id=186 [QSA]
    RewriteRule ^      https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Nic3500
  • 8,144
  • 10
  • 29
  • 40
  • 2
    Unclear question. What does "improve" mean to you? What you have here is a configuration that forces the user to use https, and is common. You do not control what a user does, so doing it this way forces http user to switch to https. What else do you want? – Nic3500 Aug 28 '22 at 23:54
  • i agree ,its unclear , sorry for that ,it's all about cookies ,it suppose redirect to ?referer_id=186 every time which is refresh the cookies of new logo but i notices when user delete or clear the history of Brower and try to visit the website by https the cookies not refresh again ,unless visit http the cookies refresh to new so why http keeps referer_id=186 cookies while https after delete the cookies the https impacted , i want the behavior of http as https whether user delete cookies or it keep always visit ?referer_id=186 – Momen Rashad Aug 29 '22 at 10:34
  • you can try by visit (https://gps.tolivery.com) and then delete the cookies and again visit the same link , you will notices the cookies changed and ?referer_id=186 ignored , to fix this i have to visit without ssl (http://gps.tolivery.com) or using ssl with ?referer_id=186 (https://gps.tolivery.com/?referer_id=186) , i just want always the https by this link (https://gps.tolivery.com) redirect to ?referer_id=186 automatic to refresh the cookies like the same behavior of http (http://gps.tolivery.com) whether user delete cookies or not – Momen Rashad Aug 29 '22 at 11:11
  • Ok so going `http://....` redirects to `https://...?referer_id=186` and that is ok. But if the user goes to `https:/...` directly he is missing the referer part? So setup your VirtualHosts like this: http -> https, keep it like that. https -> https with referer. https with referer already there, do not redirect. – Nic3500 Aug 29 '22 at 15:09
  • hmm interesting ! so the logic you want implement **https -> https with referer. https with referer already there, do not redirect** can you kindly share with me the method , it will really helpful – Momen Rashad Aug 29 '22 at 16:19

1 Answers1

1

In your https VirtualHost, add this:

<VirtualHost *:443>
    [ ... the rest of the configuration ... ]

    RewriteEngine On
    RewriteCond %{QUERY_STRING} "!referer_id=186"
    RewriteRule ^/(.*)$ https://example.com/$1?referer_id=186 [R,QSA]

</VirtualHost>
  • RewriteCond: matches when "referer_id=186" is absent
  • RewriteRule: adds the "referer_id=186" to the redirection.
  • QSA: will keep any query string parameters already present, thus added the 186 part, but not deleting others present.
Nic3500
  • 8,144
  • 10
  • 29
  • 40