search

Home  >  Q&A  >  body text

php - nginx redirect http to https and let second-level domain name redirect to top-level domain name

How can I redirect http to https and redirect second-level domain names to top-level domain names in the same nginx conf?

習慣沉默習慣沉默2753 days ago590

reply all(1)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-16 13:14:42

    HTTP redirects to HTTPS (HTTPS listens to port 443. If you have multiple domain names on the same port, you need to set server_name)

    server {

    listen  80;  
    server_name domain.com;
    rewrite ^(.*)$  https://$host permanent;  

    }

    Second-level domain name redirects to top-level domain name:

    server {

    listen  80;
    server_name *.domain.com;
    rewrite ^/(.*) http://domain.com/ permanent;

    }

    reply
    0
  • Cancelreply