Redirect www to no-www with variable (for multiple domains)?

Sajan Parikh sajan at noppix.com
Sun Jul 7 18:47:17 UTC 2013


I should correct my server_name line. It should not have the variable, but the actual domain names. So I guess you'll still have to come back and add each domain. 

Sorry. On phone. 

Sajan Parikh

On Jul 7, 2013, at 6:47 AM, Sajan Parikh <sajan at noppix.com> wrote:

> Haven't testing this, but would you not be able to replace 'domain.com' with $host?
> 
> server {
>  server_name www.$host;
>  rewrite ^(.*)  $scheme://$host$request_uri permanent;
> }
> 
> That should work I think.  Right now, I do it the way you've descrived individually in all my .conf files for each domain.
> 
> - Sajan Parikh
> 
> On 07/07/2013 04:30 AM, lennart wrote:
>> According to http://wiki.nginx.org/Pitfalls#Server_Name this is the best
>> solution to redirect www to no-www for one domain:
>> 
>> server {
>>   server_name www.domain.com;
>>   return 301 $scheme://domain.com$request_uri;
>> }
>> server {
>>   server_name domain.com;
>>   [...]
>> }
>> 
>> Is there a way to do this with regex or variables? I've ~15 domains and it
>> would be more convenient to have only one entry "to rule them all" ;-)
>> 
>> Posted at Nginx Forum: http://forum.nginx.org/read.php?2,240622,240622#msg-240622
>> 
>> _______________________________________________
>> nginx mailing list
>> nginx at nginx.org
>> http://mailman.nginx.org/mailman/listinfo/nginx
> 
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx



More information about the nginx mailing list