Nginx rewrite non-www-prefixed domain to www-prefixed domain

后端 未结 7 1121
旧时难觅i
旧时难觅i 2021-01-30 11:05

I see the Nginx HttpRewriteModule documentation has an example to rewrite a www-prefixed domain to a non-www-prefixed domain:

if ($host ~* www\\.(.*)) {
  set $h         


        
相关标签:
7条回答
  • 2021-01-30 11:36

    HTTP & HTTPS without if conditions:

    server {
        listen          80;
        listen          443;
        server_name     website.com;
    
        return 301 $scheme://www.website.com$request_uri;
    }
    server {
        listen          80;
        listen          443 default_server ssl;
        server_name     www.website.com;
    
        # Your config goes here #
    }
    
    0 讨论(0)
提交回复
热议问题