2013-07-08 4 views

ответ

0

Это может быть сделано с помощью ряда регулярных выражений; Пример:

set $hasdashs u; # if we don't match .html we don't want to do a rewrite 
    if ($uri ~* "^(.*)\.html$") { # are we looking at a .html page? If so, get the base name 
    set $hasdashs n; 
    set $shorturi "$1"; 
    } 
    if ($uri ~ "^(.*)-s\.html$") { # are we looking at a secure page? Get the base name without -s 
    set $hasdashs y; 
    set $shorturi "$1"; 
    } 
    set $schemecheck "$scheme$hasdashs"; 

    if ($schemecheck = "httpy") { #we're using http and looking at a secure page 
    rewrite . "${shorturi}.html" redirect; 
    } 
    if ($schemecheck = "httpsn") { #we're using https and looking at an insecure page 
    rewrite . "${shorturi}-s.html" redirect; 
    } 

Обратите внимание, что это должно быть в блоке сервера и не расположение блока конфигурации. Протестировано на NGINX 1.2.1.

Смежные вопросы