I cannot seem to figure out how to remove a folder from the url. For example, if a site's root is at / and you have a structure like so:
Home
- Folder
- SubContent1
-SubContent2
The url to subcontent1 is: /folder/subcontent1.
Is there any way to remove the "folder" portion from /folder/subcontent1, so it is /subcontent1?
umbracoHideTopLevelNodeFromPath is set to true in web.config, and I have tried all of the below, but they do not achieve the abovementioned goal of removing "folder" from the url.
If you want to implement it yourselves, there are mutliple ways to get there...
You can use
IIS url rewrite rules (if rewriting can be done by convention) or
UrlProviders and ContentFinders (if application logic is needed to
return correct content, or for the parts that are harder to write
with url rewrites)
Maybe you can use an example of an UrlProvider for stripping out a part of the url (in this example /companies/companyABC => /companyABC)
class CompanyUrlProvider : IUrlProvider
{
public IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current)
{
return Enumerable.Empty<string>();
}
public string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode)
{
var content = umbracoContext.ContentCache.GetById(id);
// Company url that starts from root
if (content != null && content.DocumentTypeAlias == "umbCompany")
{
//The company node will have /<company> instead of /companies/<company>.
return String.Format("/{0}/", content.UrlName);
}
return null;
}
}
Url issue - remove folders from url
I cannot seem to figure out how to remove a folder from the url. For example, if a site's root is at / and you have a structure like so:
Home - Folder - SubContent1 -SubContent2
The url to subcontent1 is: /folder/subcontent1.
Is there any way to remove the "folder" portion from /folder/subcontent1, so it is /subcontent1?
umbracoHideTopLevelNodeFromPath is set to true in web.config, and I have tried all of the below, but they do not achieve the abovementioned goal of removing "folder" from the url.
Thanks.
I believe this package might be what you are looking for:
https://our.umbraco.org/projects/backoffice-extensions/omit-segments-url-provider/
This is great, thanks, I'll check it out. Is there a way to do this natively?
Only by writing your own URL provider, which I imagine is quite tricky:
https://our.umbraco.org/documentation/reference/routing/request-pipeline/outbound-pipeline
If you want to implement it yourselves, there are mutliple ways to get there...
You can use
Maybe you can use an example of an UrlProvider for stripping out a part of the url (in this example /companies/companyABC => /companyABC)
Thanks Micha. How would you go about to do the IIS url rewrite?
In a somewhat similar discussion some examples of IIS url rewrites are shown: https://our.umbraco.org/forum/using-umbraco-and-getting-started/80821-umbraco-content-structure-advice#comment-258459
is working on a reply...