ruby on rails - Remove "www" from all links to my website - nginx -


i created rails app , when put link pointing website, "www" removed.

for example when enters http://www.mydomain.com/users browser address, changed http://mydomain.com/users when page loads up.

so if working apache add lines .htaccess file:

rewriteengine on rewritebase / rewritecond %{http_host} ^www\.(.*)$ [nc] rewriterule ^(.*)$ http://%1/$1 [r=301,l] 

however working nginx , unicorn (i not sure if unicorn has this).

do place in nginx configuration?

any resource / point right direction helpful.

as @ricoxor answered, could use rewrite correct functionality; however, listed examplary pitfall in nginx pitfalls documentation.

the correct way write multiple server directives shown documentation:

server {   server_name www.domain.com;   return 301 $scheme://domain.com$request_uri; } server {   server_name domain.com;   [...] } 

the reason more 'correct' described @ page linked:

there 3 problems here. first being if directives. that's care now. why bad? did read if evil? if directives nginx forced evaluate every request domains. evaluating every request against if directives extremely inefficient. avoid using if directives , use 2 server directives shown.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -