Question

I have problem with following .htaccess rewrites.

RewriteEngine On
RewriteRule ^([a-zA-Z0-9\-\,]+)$ index.php?s=$1
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

When I access site with http://ssl.droth-admin.ogicom.pl/kalkulator it redirects to https://ssl.droth-admin.ogicom.pl/kalkulator?s=kalkulator. When I access site with directly with https everything works well, ?s=kalkulator is not showing.

Test php:

<?php
//if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) AND $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
if (!empty($_SERVER['HTTPS']))
{
    echo ("SSL active");
    echo ("<br />");
    echo ("s=".$_GET['s']);
}
else
{
    echo ("SSL not active");
    echo ("<br />");
    echo ("s=".$_GET['s']);
}
?>

Is there any solution for the ?s=kalkulator to not show up after ssl redirection? I tried to switch redirects but it didn't work.

Was it helpful?

Solution

Change order of your rules:

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d    
RewriteRule ^([a-zA-Z0-9,-]+)/?$ index.php?s=$1 [L,QSA]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top