Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Raja 11 posts 81 karma points notactivated
    May 05, 2016 @ 13:11
    Raja
    0

    UrlRewriting

    Hi, I created Umbraco Templates for MVC Project.here i have list of categories and based on category i will display the product images.

    i will pass the Category Name by using a href tag from umbraco template to other umbraco templte, by using query string i got the categoryname, from here i called the my action result(i mean controller action by using Html.Action()). total its working fine. like this i was calling <a href="@childPage.Url?categoryname=@categoryname" >@childPage.Name</a>

    The Problem is I called category Name by using <a href> ,when click category it shows like: (fordon is my categoryname) http://localhost:51888/forden/?categoryname=categoryname" >

    but i want to display like:http://localhost:51888/forden/categoryname i want to hide the parameter in url, Is it possible .help me if any one knows.

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    May 05, 2016 @ 18:53
    Dan Diplo
    0

    The prefered way would be to use the IIS Url Rewrite module and then you can create rewrites in web.config. See examples at http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module

    If you can't install it, then you can also create rewrite rules in the file /config/urlRewriting.config in Umbraco. In your case the latter would be something like:

    <add name="Category Rewrite"
      virtualUrl="~/(.*)/forden/(.*)/"
      rewriteUrlParameter="ExcludeFromClientQueryString"
      destinationUrl="~/$1/forden/?categoryname=$2"
      ignoreCase="true" />
    

    You might need to experiment, but that's the basics.

  • Nicholas Westby 2054 posts 7104 karma points c-trib
    May 05, 2016 @ 20:13
    Nicholas Westby
    0

    While URL rewriting is a workable solution, I would recommend trying to use a content finder and URL provider first:

    Basically, content finders allow you to use custom URL's to find your content. And URL providers ensure Umbraco is aware of what URL's you want to use for a given content node (e.g., when you type Model.Content.Url).

    The URL provider might not be as useful in your case if you have only one content node and multiple URL's (though I think it'd probably still work). The content finder would definitely be a good bet.

  • Manish 373 posts 932 karma points
    May 06, 2016 @ 05:32
    Manish
    0

    Well, umbracoalias is one of the option to go with and you can modify your url accordingly https://our.umbraco.org/wiki/reference/umbraco-best-practices/umbracourlalias/

    Manish

  • Raja 11 posts 81 karma points notactivated
    May 06, 2016 @ 05:46
    Raja
    0

    Thank you Manish, If u Don't mind can you explain clearly please , i can't get what u said.

  • Raja 11 posts 81 karma points notactivated
    May 06, 2016 @ 05:49
    Raja
    0

    Hi Dan,

    I tried your Example but it display same thing in the Url like <http://localhost:51888/forden/?categoryname=categoryname" > is there any possibility go Get <http://localhost:51888/forden/categoryname" > like this

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    May 06, 2016 @ 18:58
    Dan Diplo
    0

    A URL rewrite means that you can enter the URL of http://localhost:51888/forden/categoryname but it will translate that to http://localhost:51888/forden/?categoryname=categoryname

    So to use URL rewrites you need to generate the URL yourself in your links, and then the rewrite will do the job of passing on the query string. See docs at https://github.com/aspnetde/UrlRewritingNet/tree/master/docs

  • Manish 373 posts 932 karma points
    May 06, 2016 @ 05:52
  • Nicholas Westby 2054 posts 7104 karma points c-trib
    May 06, 2016 @ 19:18
    Nicholas Westby
    0

    You may have to tinker with Dan's example rewrite rule before it will work for you. For example, I noticed he has a trailing slash, but your example URL does not have a trailing slash.

    Also, Dan is using automatic capture groups (or whatever they are called). Note that you can also used named capture groups to be more explicit. Here is an example UrlRewriting.config file from one of my sites for your reference:

    <?xml version="1.0" encoding="utf-8"?>
    <urlrewritingnet xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
      <rewrites>
        <add
          name="Localize URL" rewriteUrlParameter="ExcludeFromClientQueryString" ignoreCase="true"
          virtualUrl="^~/(?&lt;culture&gt;[a-z]{2}-[a-z]{2})(?&lt;url&gt;/.+$|$)"
          destinationUrl="~${url}?lang=${culture}" />
    
        <!-- Sitemap.xml. -->
        <add name="Sitemap"
             virtualUrl="~/sitemap.xml"
             destinationUrl="~/seositemap"
             rewriteUrlParameter="ExcludeFromClientQueryString"
             ignoreCase="true" />
    
        <!-- RSS Feed.
        <add name="RSS Feed"
             virtualUrl="~/feed"
             destinationUrl="~/rssfeed"
             rewriteUrlParameter="ExcludeFromClientQueryString"
             ignoreCase="true" /> -->
      </rewrites>
    </urlrewritingnet>
    

    There are a few rules in there you can use to serve as a reference. As an example, the first one ensures that when a user visits ~/en-us/some-page, the server will interpret that URL as ~/some-page?lang=en-us. It will not do a redirect (i.e., the user will always see ~/en-us/some-page)... it's just that the server will see the modified URL.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies