Nginx 301永久重定向非www的域名定向到含www下

Apache 的配置:
#.htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com
RewriteRule (.*) http://www.yourdomain.com$1 [R=301,L]

Nginx 的配置:
# /etc/nginx/nginx.conf
if ($http_host !~ “^www\.yourdomain\.com$”) {
rewrite ^(.*) http://www.youdomain.com$1 permanent;
}

Nginx的 Rewrite Flags:
last – 基本上都用这个Flag。
break – 中止Rewirte,不在继续匹配
redirect – 返回临时重定向的HTTP状态302
permanent – 返回永久重定向的HTTP状态301

2011年7月16日 | 归档于 程序代码
标签:
  1. 2011年7月20日 15:49 | #1

    暂时还用不到哈

发表评论

XHTML: 您可以使用这些标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>