View Single Post
  #1  
Old 2nd July 2013, 14:52
jaypabs jaypabs is offline
Member
 
Join Date: Jun 2013
Posts: 69
Thanks: 0
Thanked 1 Time in 1 Post
Default Non-www to www and vice versa

How can I rewrite nginx to redirect non-www to www and vice versa?

I have tried the following by adding it in the nginx directives without luck.

non-www to www:
Code:
	server {
		server_name example.com;
		rewrite ^(.*) http://www.example.com$1 permanent;
	}
www to non-www:
Code:
	server {
		server_name www.example.com;
		rewrite ^(.*) http://example.com$1 permanent;
	}
Reply With Quote
Sponsored Links