Nginx仅在根域时重写

前端之家收集整理的这篇文章主要介绍了Nginx仅在根域时重写前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我想做一个Nginx重写,我有两个域:domain.com和domain.net,具有以下规则:

1)如果用户转到http://www.domain.net/,他将被重定向http://www.domain.com/
2)如果用户转到http://www.domain.net/anything_else.html,则不会进行重写.

这是我失败的尝试:

server {
  listen 80;
  server_name www.domain.net domain.net;
  location / {
    rewrite / http://www.domain.com/ permanent;
  }
}

非常感谢正确的格式!

最佳答案
也许这有效:

server {
  listen 80;
  server_name www.domain.net domain.net;
  location / {
    rewrite "^$" http://www.domain.com/ permanent;
  }
}
原文链接:https://www.f2er.com/nginx/434340.html

猜你在找的Nginx相关文章