<div dir="ltr">The way I do this is to use multiple server {} blocks, and put all the non-canonical hostnames / port 80 requests in a server block with a return 301 to the canonical (and HTTPS) host which only listens on 443 and the canonical hostname.</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 11, 2016 at 9:12 PM, mevans336 <span dir="ltr"><<a href="mailto:nginx-forum@forum.nginx.org" target="_blank">nginx-forum@forum.nginx.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">We currently use the following method to perform an http to https rewrite.<br>
<br>
rewrite ^ https://$server_name$request_uri permanent;<br>
<br>
I am planning to change it to the preferred method of:<br>
<br>
return 301 https://$server_name$request_uri;<br>
<br>
However, we'd like to also make sure any requests for <a href="http://domain.com" rel="noreferrer" target="_blank">domain.com</a> are sent to<br>
<a href="http://www.domain.com" rel="noreferrer" target="_blank">www.domain.com</a>, whether someone tries to access <a href="http://domain.com" rel="noreferrer" target="_blank">domain.com</a> via http or<br>
https.<br>
<br>
How would I write the redirect statement to rewrite http:// to https:// but<br>
also rewrite <a href="http://domain.com" rel="noreferrer" target="_blank">domain.com</a> to <a href="http://www.domain.com" rel="noreferrer" target="_blank">www.domain.com</a>?<br>
<br>
Posted at Nginx Forum: <a href="https://forum.nginx.org/read.php?2,265257,265257#msg-265257" rel="noreferrer" target="_blank">https://forum.nginx.org/read.php?2,265257,265257#msg-265257</a><br>
<br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" rel="noreferrer" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br>
</blockquote></div><br></div>