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

相关文章:

  • 2022-02-11
  • 2021-08-27
  • 2021-10-26
  • 2022-12-23
  • 2021-08-02
  • 2022-12-23
  • 2022-01-02
  • 2022-01-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-17
  • 2021-10-10
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案