Forum

redirect mydomain.com to www.mydomain.com

Alex
22 June 2010, 15:43
Hi Hugo,

how to redirect mydomain.com to www.mydomain.com?
maybe I can use Joomla - URL toolkit for my vHosts?

Thanks in advance!

Hiawatha version: 7.3
Operating System: Debian 5.0
Hugo Leisink
22 June 2010, 19:40
Create a virtual host for each hostname. Use the redirect URL toolkit option to redirect all requests to mydomain.com to www.mydomain.com. Something like this:
VirtualHost {
Hostname = mydomain.com
UseToolkit = redirect
...
}

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

UrlToolkit {
ToolkitID = redirect
Match ^/(.*) Redirect http://www.mydomain.com/$1
}

Please note: I have not tested the configuration above. It could contain some typo's.
Alex
23 June 2010, 06:33
a little bit extravagantly, but it works, thanks Hugo
Maybe there are shorter ways? Does nothing occur to you?
Hugo Leisink
23 June 2010, 08:16
The shortest way is to simply use both hostnames in the same virtual host
VirtualHost {
Hostname = www.mydomain.com, mydomain.com
...
}

Do you really care whether a user sees a hostname with or without www in his URL?
Alex
23 June 2010, 09:38
To me it would make no difference, but for the web search engine it is very important, you know Pagerank etc.
Hugo Leisink
23 June 2010, 09:42
My experience is that it's not the case. It's very common that http://domain.com/ shows the same website as http://www.domain.com/. Search engines can handle those aliases well.
Alex
23 June 2010, 10:03
I have read in a report for search engine optimization that it is recommended redirect the Domains on www, all famous web pages also do this, just look Google eBay etc.
Hugo Leisink
23 June 2010, 10:08
What you also could do is have one general redirect virtual host which redirects all domains to the www version.
VirtualHost {
Hostname = mydomain.com, mywebsite.com, blabla.com
...
}

Use a script to redirect all requests.
<?php
header("Location: http://www.".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]);
?>
Alex
23 June 2010, 10:28
Thank you Hugo, it is also redirected equally fast and requires less work
Alex
23 June 2010, 13:27
oops unfortunately, there is a problem in the last solution
if I give mydomain.com then I am redirected to www.mydomain.com, but if I give mydomain.com/images/test.png then gets 404 - not found
Hugo Leisink
23 June 2010, 13:36
Use the following UrlToolkit for the redirect virtual host:
UrlToolkit {
ToolkitID = redirect
Match .* Rewrite /index.php
}

This redirects all requests to index.php, which will redirect to the www version of the hostname.
Alex
23 June 2010, 14:05
Indeed, the first solution is more extravagantly, but it's better. The first solution redirect everything perfect, I remain in the first solution.
Thanks Hugo your Support is great!
This topic has been closed.