2011-09-19 51 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; 
    } 
}