Forum

UrlToolKit Redirect help

John
29 December 2009, 10:11
Hiawatha version: 6.17.1
Operating System: Debian 5.0.3

I am trying to do a 301 redirect from http://domain.com to http://www.domain.com

I want it to have the www prefix but I can't manage to get it even after reading the manual. Below is my conf.

Hope you can assist me in this. Thanks alot
VirtualHost {
Hostname = www.domain.com
WebsiteRoot = /var/www/www.domain.com
StartFile = index.php
AccessLogfile = /var/www/www.domain.com/log/access.log
ErrorLogfile = /var/www/www.domain.com/log/error.log
TimeForCGI = 5
UseFastCGI = PHP5
UseToolkit = nailsdb
PreventCMDi = yes
PreventCSRF = yes
PreventSQLi = yes
PreventXSS = yes
}
UrlToolkit {
ToolkitID = nailsdb
Match http://^domain\.com$ Redirect http://www.domain.com
}
Hugo Leisink
29 December 2009, 10:56
Hiawatha only supports rewriting of the URL part after the hostname. In your case, there are two options.

The first option is to add 'domain.com' to the hostname. Then you don't need a rewrite, because both URLs will show the website.
VirtualHost {
Hostname = www.domain.com, domain.com
...


Second option is to redirect all requests from 'domain.com' to 'www.domain.com' via a second virtual host.
VirtualHost {
Hostname = www.domain.com
...
}

VirtualHost {
Hostname = domain.com
...
UseToolkit = redirect
}
UrlToolkit {
ToolkitID = redirect
Match ^/(.*) Redirect http://www.domain.com/$1
}
John
29 December 2009, 18:03
I used the second option =)

Wishing you Happy New Year 2010 in advance!

Thank you Hugo!
Martin Tournoij
17 January 2010, 01:25
This options works, however, I have a bunch domains I would like to redirect, creating an additional virtualhost AND urltoolkit for them is not something I'm looking forward to.

With lighttpd for example it is pretty simple using mod_redirect:

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


But even a simple (regexp-less) redirect option would be a lot better/cleaner IMO, i.e.

VirtualHost {
Hostname = example.com, *.example.com
Redirect = 301:example.com:www.example.com
}


... Just my two cents ... This is the only feature I miss after switching from lighttpd ...
Hugo Leisink
17 January 2010, 10:01
My advice would be, don't redirect to an URL with www. What is the problem when a user uses http://domain.com/ instead of http://www.domain.com/?

If you still want to redirect, use one virtual host to do so.
VirtualHost {
Hostname = www.domain1.com
...
}

VirtualHost {
Hostname = www.domain2.com
...
}

VirtualHost {
Hostname = domain1.com, domain2.com
...
}


Use a simple redirect script for the last virtual host:
<?php
header("Location: http://www.".$_SERVER["HTTP_HOST"]."/");
?>
Martin Tournoij
18 January 2010, 11:36
My advice would be, don't redirect to an URL with www. What is the problem when a user uses http://domain.com/ instead of http://www.domain.com/?


Cookies for one. Consistency for another. I could also be better for SEO ... But I'm not an expert on that (I've just heard other people claim so).

But yeah, it's not the biggest/most important thing, it's just a "Would be rather nice"...
Hugo Leisink
18 January 2010, 13:37
Cookies won't be a problem if the hostname stays the same during a visit.

Consistancy, well. I think no visitor cares about the hostname. If it shows the website he/she wants to see, it's all fine.

SEO: redirecting is bad for SEO. An URL with www or without www, it won't damage SEO results. Take slashdot.org for example. One of the busiest websites of this planet does just fine without www in its URL. Other things like a title matching the content, the correct keywords and description are far more important than www in your hostname.
Martin Tournoij
29 January 2010, 00:56
Hugo, I worked at a tech helpdesk, more than once (often actually) I've had cases where people type in "www.192.168.1.1" when asked to go to an address such as "192.168.1.1" ...

As for slashdot:

[~]% telnet www.slashdot.org 80 
Trying 216.34.181.48...
Connected to www.slashdot.org.
Escape character is '^]'.
GET / HTTP/1.1
Host: www.slashdot.org

HTTP/1.1 301 Moved Permanently
Server: Apache/1.3.41 (Unix) mod_perl/1.31-rc4
Location: http://slashdot.org/
Content-Type: text/html; charset=iso-8859-1
Content-Length: 297
Date: Thu, 28 Jan 2010 23:53:48 GMT
X-Varnish: 1107128597 1107127750
Age: 46
Connection: keep-alive

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>301 Moved Permanently</TITLE>
</HEAD><BODY>
<H1>Moved Permanently</H1>
The document has moved <A HREF="http://slashdot.org/">here</A>.<P>
<HR>
<ADDRESS>Apache/1.3.41 Server at www.slashdot.org Port 80</ADDRESS>
</BODY></HTML>


It gives me a 301, which is exactly what I would like ...

Anyway, I'll go with a CGI python/php solution similar to what you suggested before ... Thanks for your time!
This topic has been closed.