2011-09-19 50 views
0

我正在用http和https服務配置Nginx服務器。我想才達到以下配置:在Nginx服務器中重寫配置問題

redirect every page to HTTPS, except for the home page 

在我的「HTTP」服務器配置,我已經第二改寫條件的工作,但是我找不到寫的第一方式。

location =/{ 
    what goes here??? 
} 

location/{ 
    rewrite ^(.*) https://mydomain.com$1 permanent; 
} 

想法?

回答

0

Zenofo的答案應該基本能工作(只需要正規表達式「〜*!」來代替),但會重定向請求,其中包括名稱主頁和其他人一起。

使用「$ uri」代替「$ request_uri」並在正則表達式中拼出主頁文件名可以解決這個問題。

location/{ 
    if ($uri !~* ^/index.html) 
    { 
     # Redirect non home page requests 
     rewrite^https://$host$request_uri? permanent; 
    } 

    # Process homepage requests 
    .... 

} 

如果運行PHP這裏的一切經歷的index.php(前端控制器),那麼你可以使用

location/{ 
    if ($uri !~* ^/index.php$) 
    { 
     # Redirect non home page requests 
     rewrite^https://$host$request_uri? permanent; 
    } 

    # Process homepage requests 
    .... 

} 
0

使用$request_uri,是這樣的:(我沒有測試)

location/{ 
    if ($request_uri != ^/$) 
    { 
     rewrite ^(.*) https://mydomain.com$1 permanent; 
    } 
}