A client has requested that their site needs to always contain the 'www' in the URL. Is this something I can set in the Umbraco configs or does it need to be done externally with the DNS or in IIS?
I would set this is IIS. If you have the ability to do so, create a second Web site (bound to domain.com) that is a permanent redirect to www.domain.com (all docs). This should do it for your. Let us know if you need details on this.
Thanks Nik, I'm thinking that it might be difficult to do this with the current host, as it's on a shared package at Softsyshosting. Is there any way to do it within the confines of Umbraco? It need only be quite crude e.g. just the homepage so that the main domain 'http://thedomain.com' always redirects to 'http://www.thedomain.com'.
Ok, in that case I would create yet another top node (homepage node) in your content tree and bind that to your thedomain.com. Then add a new property on the homepage called umbracoRedirect which simply redirects to www.thedomain.com. So:
Create the second homepage node
"Manage Hostnames" on the two top nodes and add the respective domains
Add umbracoRedirect (textbox) to your homepage docType
Set the umbracoRedirect on your thedomain.com homepage
I have not tried this, but it should work. Please let me know how it works out.
I've set that up but it doesn't seem to redirect. Ordinarily the 'umbracoRedirect' field would be a content picker as opposed to a text string. Using a content picker the redirect happens, but only to the non-www homepage not the www homepage i.e. I can't dictate a full URL with the content picker, only the node to redirect to. Doing it as a content picker with a textstring data type using the full URL in the redirect field makes it not redirect at all.
I've just done a little investigating actually and the 'umbracoRedirect' field takes a numerical node id. If I enter the node id of the www homepage into the textstring umbracoRedirect field it redirects, but again, doesn't do the www part.
you may also want to check the location that you're in and 1) only do this on the homepage, or 2) check the rest of the URL and append that to the redirect.
Thanks Nik - I couldnt' get the 301 package to work (unsure what data type to use and whether it can even handle absolute URLs or whether it's limited to just the content picker again). I created the usercontrol and that works fine, so thanks for that.
Just to point out that the 301 redirect package only handles the path part of the URL - it doesn't do anything with the domain - so doesn't help in your problem.
There's probably a way to achieve the force-www using UrlRewritingNet - but I don't know the syntax off the top of my head.
The approach you have taken with the code-behind will work ... but if you are after performance gains - I'd recommend moving it to a HttpModule, as it's executed earlier down the ASP.NET page life-cycle / pipeline. More efficient! ;-)
This also carries through any querystring parameters that might have been in the original request. Depending on your needs, you might prefer to set the redirectMode to Permanent. Happy coding!
Force www in URL
Hi,
A client has requested that their site needs to always contain the 'www' in the URL. Is this something I can set in the Umbraco configs or does it need to be done externally with the DNS or in IIS?
Thanks
I would set this is IIS. If you have the ability to do so, create a second Web site (bound to domain.com) that is a permanent redirect to www.domain.com (all docs). This should do it for your. Let us know if you need details on this.
See second post in this thread for some tips: http://www.windowshostingasp.net/windows_hosting_forums/showthread.php?t=35
Thanks,
Nik
Thanks Nik, I'm thinking that it might be difficult to do this with the current host, as it's on a shared package at Softsyshosting. Is there any way to do it within the confines of Umbraco? It need only be quite crude e.g. just the homepage so that the main domain 'http://thedomain.com' always redirects to 'http://www.thedomain.com'.
Ok, in that case I would create yet another top node (homepage node) in your content tree and bind that to your thedomain.com. Then add a new property on the homepage called umbracoRedirect which simply redirects to www.thedomain.com. So:
Nik
I've set that up but it doesn't seem to redirect. Ordinarily the 'umbracoRedirect' field would be a content picker as opposed to a text string. Using a content picker the redirect happens, but only to the non-www homepage not the www homepage i.e. I can't dictate a full URL with the content picker, only the node to redirect to. Doing it as a content picker with a textstring data type using the full URL in the redirect field makes it not redirect at all.
I've just done a little investigating actually and the 'umbracoRedirect' field takes a numerical node id. If I enter the node id of the www homepage into the textstring umbracoRedirect field it redirects, but again, doesn't do the www part.
Right, sorry. You're right that takes a nodeId and not a string. So, you could create a UC that simply does something like this:
That should do it...hopefully :)
Thanks,
Nik
you may also want to check the location that you're in and 1) only do this on the homepage, or 2) check the rest of the URL and append that to the redirect.
-- Nik
Oh, and I just saw that this package was addedd recently. Perhaps you can use this? http://our.umbraco.org/projects/301-moved-permanently
Cheers,
Nik
Thanks Nik - I couldnt' get the 301 package to work (unsure what data type to use and whether it can even handle absolute URLs or whether it's limited to just the content picker again). I created the usercontrol and that works fine, so thanks for that.
10-4, glad to help.
-- Nik
Just to point out that the 301 redirect package only handles the path part of the URL - it doesn't do anything with the domain - so doesn't help in your problem.
There's probably a way to achieve the force-www using UrlRewritingNet - but I don't know the syntax off the top of my head.
The approach you have taken with the code-behind will work ... but if you are after performance gains - I'd recommend moving it to a HttpModule, as it's executed earlier down the ASP.NET page life-cycle / pipeline. More efficient! ;-)
Cheers, Lee.
Nice point Lee. That would make total sense.
Cheers,
Nik
You can do this in IIS fairly easily. Check out a blog post I wrote on this topic a few months ago:
"How to 301 Redirect example.com to www.example.com in IIS"
Good luck!
Right, but he didn't have access to this at his host (as noted in the beginning of the thread). Thanks.
-- Nik
Just wanted to chime in here.
It is really easy to do this using the UrlRewriting.config file:
An you can also do it the other way
This will make the 301 redirect for any url on the site.
Thanks Morten, I was hoping someone would chime in with that. Great to know!
plus one for Morton -- i use this method often!
Oops. Sorry! Saw the IIS in the question and missed that response.
And thanks Morten for URL Re-writing option. That rocks.
check this link http://goo.gl/7fxh3
I had issues with the solutions above. The following worked for me in Umbraco 4.9.1 - In the UrlRewriting.config, use this:
This also carries through any querystring parameters that might have been in the original request. Depending on your needs, you might prefer to set the redirectMode to Permanent. Happy coding!
is working on a reply...