我想从www.mydomain.com重定向到nginx中的domain.com.我搜索互联网并发现两种方式:
第一种方式
server {
listen 80;
server_name www.domain.com;
rewrite ^/(.*) http://domain.com/$1 permanent;
}
第二种方式
server {
listen 80;
server_name www.domain.com;
return 301 $scheme://domain.com$request_uri;
}
两种方式都有效.但是我应该使用哪一个?为什么?
最佳答案
第二种方式更好……
server {
listen 80;
server_name www.domain.com;
return 301 $scheme://domain.com$request_uri;
}
为什么
让我直接引用官方的Nginx维基在Pitfalls and Common Mistakes:
By using the built-in variable $request_uri,
we can effectively avoid doing any capturing or matching at all,
and by using the return directive,
we can completely avoid evaluation of regular expression.
我自己的想法……
默认情况下,正则表达式代价高昂,会降低性能.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。