Forum

non-www to www redirect

Gour
6 December 2012, 14:48
I'm posting here 'cause the old thread is closed..

What is 'ultimate' solution for redirecting all non-www requests to www?

I'm trying with:

VirtualHost {
Hostname = atmarama.net
WebSiteRoot = /some/path/net
UseToolkit = redirect_net, wordpress
StartFile = index.php
AccessLogFile = /some/path/log/net-access.log
ErrorLogFile = /some/path/log/net-error.log
TimeForCGI = 5
UseFastCGI = PHP5
}

VirtualHost {
HostName = www.atmarama.net
WebSiteRoot = /some/path/net
UseToolkit = wordpress
StartFile = index.php
AccessLogFile = /some/path/log/net-access.log
ErrorLogFile = /some/path/log/net-error.log
TimeForCGI = 5
UseFastCGI = PHP5
}


UrlToolkit {
ToolkitID = redirect_net
Match ^/(.*) Redirect http://www.atmarama.net/$1
}

UrlToolkit {
ToolkitID = wordpress
RequestURI exists Return
Match .* Rewrite /index.php
}


Otoh, FAQ entry recommends:

VirtualHost {
Hostname = www.website.net, *.website.net
...
}


but I wonder, due to SEO reasons, whether the above produces correct permanent 301 redirect?


Sincerely,
Gour

p.s. Maybe this topic deserves FAQ entry.
Gour
6 December 2012, 14:54
I'm also puzzled a bit by using wigwam to test the above redirect_net rule:

url: http://atmarama.net/index.php
Bad URL: missing leading slash.
old: http://atmarama.net/index.php



Why it reports "Bad URL: missing leading slash." ?
Hugo Leisink
6 December 2012, 18:34
The ultimate solution for me is to simply ignore whether visitors used www or not. Why would you care? And SEO is no reason, because Google and other search engines perfectly know that many sites can be visited with and without the leading www. My advice: let it be.

But, if you still want to redirect to www, you can take a look at this script [github.com].

You can also try to fix your solution: remove ', wordpress' from the UseToolkit setting in the VirtualHost block for atmarama.net. The WordPress rewrite rule is not required there, since you use that virtual host for redirecting only.

The missing leading slash error is because you entered a complete URL. Only the path part is needed.
url: /index.php
Gour
6 December 2012, 23:21
>The ultimate solution for me is to simply ignore whether visitors used www or not. Why would you care? And SEO is no reason, because Google and other search engines perfectly know that many sites can be visited with and without the leading www. My advice: let it be.

H...whenever I read about it, the conclusion was always to do 301 redirect either from non-www to www or vice verse (depending on the taste) since otherwise SEO rankings are divided into two.

> But, if you still want to redirect to www, you can take a look at this script.

Thank you.

> You can also try to fix your solution: remove ', wordpress' from the UseToolkit setting in the VirtualHost block for atmarama.net. The WordPress rewrite rule is not required there, since you use that virtual host for redirecting only.

OK. Thank you.

> The missing leading slash error is because you entered a complete URL. Only the path part is needed.

Ahh, OK. But how to test redirect rules then without entering complete URL?

Hugo Leisink
6 December 2012, 23:28
Hiawatha will show you the URL it redirects to. Entering a complete URL would be pointless, since Hiawatha never looks at the complete URL, only the path section of it.
Gour
7 December 2012, 11:14
> But, if you still want to redirect to www, you can take a look at this script.

Match ^/(.*) Redirect http://www.atmarama.net/$1


does not work, so I wonder if Hiawatha's URL toolkit can accomplish (without extra scripting) something like the following

$HTTP["host"] =~ "^atmarama\.net$" {
url.redirect = ( "^/(.*)" => "http://www.atmarama.net/$1" )
}


in lighttpd?
Gour
7 December 2012, 13:12
...since Hiawatha never looks at the complete URL, only the path section of it.


If I understand properly, then it means that the reason the above non-www to www rewrite rule fails due to some other misconfiguraton of Nginx?


Gour
7 December 2012, 16:23
The rule works - there was error in DNS entry. :-(
Hugo Leisink
7 December 2012, 19:09
Ok, good to hear it works.
This topic has been closed.