场景,示例域名描述 pc端:www。wendabaike。com(用于pc端访问官网) 移动端:m。wendabaike。com(用于移动端访问) 现在的需求是这样: 在pc端访问www。wendabaike。com和m。wendabaike。com都跳转到www。wendabaike。com 而在手机移动端访问www。wendabaike。com和m。wendabaike。com都跳转到m。wendabaike。com pc端配置:www。wendabaike。com server{ listen80; servernamewww。wendabaike。 charsetkoi8r; accessloglogshost。access。 下面根据useragent可以获取 if(httphost!www。wendabaike。com){ rewrite(。)http:www。wendabaike。com1 } if(httpuseragent(mobilenokiaiphoneipadandroidsamsunghtcblackberry)){ rewrite(。)http:m。wendabaike。com1 } location{ indexindex。htmlindex。 } } 作用部分代码如下: if(httphost!www。wendabaike。com){ rewrite(。)http:www。wendabaike。com1 } if(httpuseragent(mobilenokiaiphoneipadandroidsamsunghtcblackberry)){ rewrite(。)http:m。wendabaike。com1 } 移动端配置:m。wendabaike。com server{ listen80; servernamem。wendabaike。 charsetkoi8r; accessloglogshost。access。 非移动端跳转到www。wendabaike。com if(httpuseragent!(mobilenokiaiphoneipadandroidsamsunghtcblackberry)){ rewrite(。)http:www。wendabaike。com1 } location{ indexindex。htmlindex。 } } 作用部分代码如下: if(httpuseragent!(mobilenokiaiphoneipadandroidsamsunghtcblackberry)){ rewrite(。)http:www。wendabaike。com1 } 至此完成了相关配置 作者:阿亮私语