I've recently installed v. 4.11.3 to a shared hosting environment running Server 2008 and IIS7. Because my host does not allow me to set the "content root" as an application root in IIS, I've had no choice but to install Umbraco to its own directory. So the schema is "http://domain.com/wwwroot".
For the past few hours I've been working out a method to hide "wwwroot" from the URL but to no avail. Has anyone else had success with this?
For starters, what I've tried:
umbracoHideTopLevelNodeFromPath is set to a value of true
Numerous attempts to add redirect/rewrite scripts using UrlRewriter (in both UrlRewriting.config and web.config) have failed
I am checking with my host to see whether Url Rewriting is allowed but as of now I don't see any setting related to it in the dashboard
Am I overlooking something obvious that would allow me to hide wwwroot from the url? Any help is greatly appreciated.
I would turn on friendly urls. You should use the AddUrlRewriteRule.config. I dont know much about it but i guess you could use a regex or something to remove the wwwroot from url? Charles :)
Thanks for the suggestions, Charles. As I mentioned, despite my best efforts, I couldn't get the GoDaddy shared hosting environment to recognize the URL rewrite parameter specified in web.config. Would recognize a redirect, but no, not rewriters. Hours of research suggested this was probably a GoDaddy issue. I even found some who'd abandoned GoDaddy ship out of sheer frustrating.
Enter the workaround. Using Eric Herlitz's MasterPage Codefile generator, I wired up a brand new codebehind for the default master page (~/Umbraco/masterpages/default.Master). In that .cs file, I wrote a script that basically gets the current URL, strips out the root folder (in my case, wwwroot), then forces a 301 redirect to the new, directory-free page. One downside, it requires a cookie to prevent a redirect loop, but that's a minor inconvenience in my case. I'm sure people could think of other ways to avoid the redirect loop.
In all, the benefits outweigh the cons. Because it's the master page, it applies to all Umbraco child pages! And it even handles relative links specified by CMS users automatically. Lastly, thanks to ASP.NET 4.0's Response.RedirectPermanent, it's an SEO-conscious solution.
NOTE: For this to work, you must have your URL setup to forward straight to the directory. If you don't have that setup, you'll get 404s.
For the benefit of the public:
// Umbraco/masterpages/default.Master.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace masterpages
{
public partial class defaultMaster : System.Web.UI.MasterPage
Thanks, i will have a look at this. It looks like quite a neat little fix. Sorry did not realise there was a responce on here :) Was going to suggest just rewirting the url
I actually did manage to get a web config solution to work, and I'll share that too for everyone. This all assumes you have Umbraco installed to its own directory, as is required by a hosting provider such as GoDaddy, where you can't configure an ASP.NET application in IIS to run from the root directory.
In the system.webServer section of your ROOT web.config (*not* your umbraco web.config file), add the following, replacing "domain.com" and "wwwroot" with your domain the directory, respectively:
<rewrite> <rules> <!-- FIRST TWO RULES FORCE PERMANENT REDIRECT TO WWWROOT WHILE MASKING DIRECTORY FROM BROWSER AND SEARCH ENGINES --> <rulename="WWWROOT_AddTrailingSlash"stopProcessing="true"> <matchurl="(.*)"/> <conditionslogicalGrouping="MatchAll"> <addinput="{HTTP_HOST}"pattern="www.domain.com"/> <addinput="{URL}"pattern="^[^\.]+[^/]$"/> </conditions> <actiontype="Redirect"url="http://{HTTP_HOST}{URL}/"/> </rule> <rulename="WWWROOT_ForceRedirectAndMask"> <matchurl="(.*)"/> <conditionslogicalGrouping="MatchAll"> <addinput="{HTTP_HOST}"pattern="www.domain.com"/> <!-- If you have exceptions, note them in the pattern field --> <addinput="{REQUEST_URI}"pattern="^/(store|wwwroot/umbraco)"negate="true"/></conditions> <actiontype="Rewrite"url="wwwroot/{R:1}"/> </rule> <!-- WWWROOT RULE EXCEPTION FOR CMS ACCESS --> <rulename="WWWROOT_IgnoreForCMS"stopProcessing="true"> <matchurl="^~/umbraco"/> <actiontype="Redirect"url="http://www.domain.com/wwwroot/umbraco/"appendQueryString="false"redirectType="Permanent"/> </rule> </rules> </rewrite>
Hide Application root directory from URL
Hi all,
I've recently installed v. 4.11.3 to a shared hosting environment running Server 2008 and IIS7. Because my host does not allow me to set the "content root" as an application root in IIS, I've had no choice but to install Umbraco to its own directory. So the schema is "http://domain.com/wwwroot".
For the past few hours I've been working out a method to hide "wwwroot" from the URL but to no avail. Has anyone else had success with this?
For starters, what I've tried:
I would turn on friendly urls. You should use the AddUrlRewriteRule.config. I dont know much about it but i guess you could use a regex or something to remove the wwwroot from url? Charles :)
http://www.urlrewriting.net/160/en/documentation.html. The documentation is here. That should help i hope :)
Thanks for the suggestions, Charles. As I mentioned, despite my best efforts, I couldn't get the GoDaddy shared hosting environment to recognize the URL rewrite parameter specified in web.config. Would recognize a redirect, but no, not rewriters. Hours of research suggested this was probably a GoDaddy issue. I even found some who'd abandoned GoDaddy ship out of sheer frustrating.
Enter the workaround. Using Eric Herlitz's MasterPage Codefile generator, I wired up a brand new codebehind for the default master page (~/Umbraco/masterpages/default.Master). In that .cs file, I wrote a script that basically gets the current URL, strips out the root folder (in my case, wwwroot), then forces a 301 redirect to the new, directory-free page. One downside, it requires a cookie to prevent a redirect loop, but that's a minor inconvenience in my case. I'm sure people could think of other ways to avoid the redirect loop.
In all, the benefits outweigh the cons. Because it's the master page, it applies to all Umbraco child pages! And it even handles relative links specified by CMS users automatically. Lastly, thanks to ASP.NET 4.0's Response.RedirectPermanent, it's an SEO-conscious solution.
NOTE: For this to work, you must have your URL setup to forward straight to the directory. If you don't have that setup, you'll get 404s.
For the benefit of the public:
// Umbraco/masterpages/default.Master.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace masterpages
{
public partial class defaultMaster : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
// Remove root directory from default URL for user/SEO.
// Example default URL: www.domain.com/wwwroot/store/default.aspx
string thisURL = Request.Url.ToString();
if (thisURL.Contains("/wwwroot"))
{
// NEXT: Remove root directory from URL
thisURL = thisURL.Replace("/wwwroot", string.Empty);
// URL after above string.Replace: www.domain.com/store/default.aspx
// NEXT: Get relative path
thisURL = thisURL.Substring(thisURL.IndexOf('/'), thisURL.Length-thisURL.IndexOf('/'));
// URL after above string.Substring: /store/default.aspx
// Use cookie to note the page has been loaded (to avoid redirect loops).
HttpCookie page301ed = Request.Cookies["PageLoaded"];
// If that cookie doesn't exist, we're on the first load. Note it.
if (page301ed == null)
{
HttpCookie newCookie = new HttpCookie("PageLoaded");
newCookie.Value = "True";
newCookie.Expires = DateTime.Now;
Response.Cookies.Add(newCookie);
Response.RedirectPermanent(thisURL); // 301s out the root folder for search engines.
}
// If that cookie already exists, we've already been through this. Kill the cookie and stay put.
if (page301ed != null && page301ed.Value == "True")
{
// Kill cookie. Sometimes server time is off from local time, and cookies don't expire automatically.
page301ed.Expires = DateTime.Now.AddDays(-1D);
Response.Cookies.Add(page301ed);
}
}
}
}
}
Thanks, i will have a look at this. It looks like quite a neat little fix. Sorry did not realise there was a responce on here :) Was going to suggest just rewirting the url
Charles,
I actually did manage to get a web config solution to work, and I'll share that too for everyone. This all assumes you have Umbraco installed to its own directory, as is required by a hosting provider such as GoDaddy, where you can't configure an ASP.NET application in IIS to run from the root directory.
In the system.webServer section of your ROOT web.config (*not* your umbraco web.config file), add the following, replacing "domain.com" and "wwwroot" with your domain the directory, respectively:
Thanks for that :)
is working on a reply...