Welcome! Log In Create A New Profile

Advanced

Re: remove www from the url

February 17, 2011 09:52AM
On 2/17/11 9:44 AM, whiskybar wrote:
> Hello everyone,
>
> I used to use the following trick to cut the initial www. from the
> address so that www.mysite.com would redirect to mysite.com:
>
> [code]
> server {
> server_name mysite.com www.mysite.com;
>
> if ($host ~* www\..*) {
> rewrite ^(.*)$ $1 permanent;
> }
> [/code]


Wrong way!

server {
server_name mysite.com;
...
}

server {
server_name www.myite.com;
rewrite ^ http://mysite.com$request_uri? permanent;
}

>
> Well, this method no longer works. I do not know when it stopped working
> but I will get "The page isn't redirecting properly" in Firefox. It
> still puzzles me the documentation still implies this should work:
>
> [quote]"Note that if a redirect is relative (has no host part), then
> when redirecting Nginx uses the "Host" header if the header match name
> of server_name directive or the first name of server_name directive, if
> the header does not match or is absent. If no server_name is set, then
> the local hostname is used. If you want Nginx to always use the "Host"
> header, you can use a wildcard "*" server_name (but see the restrictions
> on doing so)"[/quote]
>
> Why is that and more importantly, what trick should I use to redirect
> www.mysite.com --> mysite.com?
>
> Thank you!
>
> Posted at Nginx Forum: http://forum.nginx.org/read.php?2,176137,176137#msg-176137
>
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://nginx.org/mailman/listinfo/nginx


--
Jim Ohlstein

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

remove www from the url

whiskybar February 17, 2011 09:44AM

Re: remove www from the url

Jim Ohlstein February 17, 2011 09:52AM

Re: remove www from the url

edogawaconan February 17, 2011 09:52AM

Re: remove www from the url

Luit van Drongelen February 17, 2011 09:54AM

Re: remove www from the url

Dayo February 17, 2011 10:03AM

Re: remove www from the url

Jim Ohlstein February 17, 2011 10:12AM

Re: remove www from the url

Dayo February 17, 2011 10:34AM

Re: remove www from the url

whiskybar February 17, 2011 10:08AM

Re: remove www from the url

Igor Sysoev February 17, 2011 10:18AM

Re: remove www from the url

Francis Daly February 17, 2011 10:54AM

Re: remove www from the url

whiskybar February 17, 2011 11:15AM

Re: remove www from the url

Francis Daly February 17, 2011 06:46PM

Re: remove www from the url

lifeisjustabout February 17, 2011 11:31PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 301
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready