Под nginx и codeigniter, как мне перенаправить определенные страницы с http на https

Я хочу, чтобы определенные страницы были доступны по https, но не по http. У меня есть рамки Code Igniter там.

Вот код из nginx conf:

server {
   listen         80;
   ......
        #enforce https
        if ($request_uri ~ "^(winkelmandje|(index.php/)?winkelmandje|(index.php/)?history|(index.php/)?mobile/winkelmandje|(index.php/)?winkelmandje/voegtoe)"){
                rewrite ^/(.*)$ https://$http_host/$1 permanent;
        }
....
}

server {
  listen      443;
  ssl         on;
   ....
        #enforce http
        if ($request_uri ~ "^(!(index.php/)?winkelmandje|!(index.php/)!mobile/winkelmandje|!(index.php/)?history|assets/|!lib_desktop/|!lib_mobile/|!images/|!widget/|!(index.php/)?winkelmandje/voegtoe)"){
                rewrite ^/(.*)$ http://$http_host/$1 permanent;
        }

   .....
}

если я захожу в свой домен /winkelmandje (эта страница - корзина) по http, я не перенаправляюсь на https.

Другой пример: если я получаю доступ к индексу домена по https, я не перенаправляюсь по http

1 ответ

Удалить ! в серверной директиве https и удалите ^ из http и https (поскольку request_uri также содержит домен).

server {
   listen         80;
   ......
        #enforce https
        if ($request_uri ~ "(winkelmandje|(index.php/)?winkelmandje|(index.php/)?history|(index.php/)?mobile/winkelmandje|(index.php/)?winkelmandje/voegtoe)"){
                rewrite ^/(.*)$ https://$http_host/$1 permanent;
        }
....
}

server {
  listen      443;
  ssl         on;
   ....
        #enforce http
        if ($request_uri ~ "(!(index.php/)?winkelmandje|!(index.php/)!mobile/winkelmandje|!(index.php/)?history|assets/|!lib_desktop/|!lib_mobile/|!images/|!widget/|!(index.php/)?winkelmandje/voegtoe)"){
                rewrite ^/(.*)$ http://$http_host/$1 permanent;
        }

   .....
}
Другие вопросы по тегам