Copied to clipboard

Flag this post as spam?

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


  • Garðar Þorsteinsson 119 posts 565 karma points
    Nov 04, 2013 @ 14:22
    Garðar Þorsteinsson
    0

    Url rewrite condition, rewrite all paths where querystring is added

    Hey,

    I would appreciate all the help you guys could give me.

    I'm trying to rewrite all urls where specific querystring is added to f.ex

    http://Site.com/X/X?queryString=123 -> http://Site.com/X/X/123

    http://Site.com/X?queryString=123 -> http://Site.com/X/123

    http://Site.com/X/X/X?queryString=123 -> http://Site.com/X/X/X/123

    And so on...

    This querystring can be on any level on the page and i want to be able to link to page with the friendly url parth like : http://Site.com/X/X/X/123 or link with http://Site.com/X/X/X/?queryString=123 so long as is it will be rewritten.

    I'm trying to use the http://www.urlrewriting.net/ included in the Umbraco but I can use MVC routing to.

    Any thoughts on the issue would be really helpful !

     

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Nov 04, 2013 @ 14:49
    Lee Kelleher
    0

    Hi Garðar,

    I'd try using a UrlRewriting rule like this:

    <urlrewritingnet xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
        <rewrites>
            <add name="category-listing"
                 virtualUrl="~/(.*)/?queryString=(.*)"
                 destinationUrl="~/$1/$2"
                 rewriteUrlParameter="ExcludeFromClientQueryString"
                 ignoreCase="true" />
        </rewrites>
    </urlrewritingnet>
    

    Hope this helps?

    Cheers,
    - Lee

  • Garðar Þorsteinsson 119 posts 565 karma points
    Nov 04, 2013 @ 15:18
    Garðar Þorsteinsson
    0

    Thank you Lee for the quick response.

    I did try your rewrite but does not seem to work.

    When I try http://Site.com/X/?queryString=123 nothing is rewritten, if I try http://Site.com/X/123 the page is not found.

    Do you have any other ideas ? :)

     

     

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Nov 04, 2013 @ 15:22
    Lee Kelleher
    0

    Does "http://Site.com/X/?queryString=123" work as intended? As in the page functions as you want it? (just checking)

    Not sure why the UrlRewriting didn't work though. Maybe look at using IIS's/.NET's built-in rewriting module?
    I don't have an example to hand, but more info here: http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module

  • Garðar Þorsteinsson 119 posts 565 karma points
    Nov 04, 2013 @ 15:28
    Garðar Þorsteinsson
    0

    Yes the path with the querystring is working as intended.

    When I try to hardcode the path it works like : 

    <add name="rewrite"

    virtualUrl="^~/A/B/(.*)"

    rewriteUrlParameter="ExcludeFromClientQueryString"

    destinationUrl="~/A/B/?queryString=$1"

    ignoreCase="true" />

    This works too but it will ofcourse conflict with to many pages :)

     <add name="rewrite"

    virtualUrl="^~/(.*)/(.*)/(.*)"

    rewriteUrlParameter="ExcludeFromClientQueryString"

    destinationUrl="~/$1/$2/?queryString=$3"

    ignoreCase="true" />

    Does this info help ?

     

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Nov 04, 2013 @ 15:36
    Lee Kelleher
    0

    Ah, yes - I misunderstood, I thought you wanted to rewrite from the querystring to the URL without it.

    You could try something like this?

    <add name="rewrite"
         virtualUrl="~/(.*)/([\d]*)"
         destinationUrl="~/$1/?queryString=$2"
         rewriteUrlParameter="IncludeQueryStringForRewrite"
         redirectMode="Permanent"
         ignoreCase="true" />
    

    Cheers,
    - Lee

  • Garðar Þorsteinsson 119 posts 565 karma points
    Nov 04, 2013 @ 15:45
    Garðar Þorsteinsson
    0

    Wow thanks Lee ! 

    This rewrite did the job, but one thing that it seems to conflict with is my custom MVC section inside Umbraco.

    Can I make this rule only work inside the page and not affect anything in the Umbraco ?

    I'm not using this specific querystring inside the MVC routing if that helps.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Nov 04, 2013 @ 15:49
    Lee Kelleher
    0

    Hmmm... maybe by adding "/umbraco" into the RegEx for the match?

    virtualUrl="~/(.*|!^umbraco)/([\d]*)"
    

    ... but I'm no RegEx master, so it probably needs tweaking :-)

  • Garðar Þorsteinsson 119 posts 565 karma points
    Nov 04, 2013 @ 16:06
    Garðar Þorsteinsson
    0

    Ahh I found out that this is not really conflicting with Umbraco, the section is inside App_Plugins folder and there it conflicts.

    So I would need to exclude the rule from this path, your last edit did not seem to get the job done so I'm reading upon regex at the moment :)

    Thank you really mutch for this help ! saved me alot of time !

    If you do find out how to exclude a path it would be appreciated :) 

  • Garðar Þorsteinsson 119 posts 565 karma points
    Nov 05, 2013 @ 13:05
    Garðar Þorsteinsson
    0

    Any thoughts on the matter ? :)

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Nov 05, 2013 @ 13:07
    Lee Kelleher
    0

    Only thought is to hack around with the RegEx to exclude the folder/path that conflicts.

  • Garðar Þorsteinsson 119 posts 565 karma points
    Nov 20, 2013 @ 23:28
    Garðar Þorsteinsson
    0

    Here is the solutions I'm using at the moment.

    I use Url rewrite module in the IIS

    This will change :

    /archive/article/2013/11/18/Alias  to /archive/article?id=Alias

     

     <rewrite>

     <rules>

     <rule name="uArticles" stopProcessing="true">

     <match url="^(?!(app_plugins|umbraco))(.*)/[0-9]+/[0-9]+/[0-9]+/([_0-9a-z-]+)$" />

     <action type="Rewrite" url="{R:2}/?Id={R:3}" />

     </rule>

     

     </rules>

     </rewrite>

  • mary pablate 2 posts 22 karma points
    Jan 25, 2014 @ 17:36
    mary pablate
    0

    Well, you can use Long Path Tool for such problems, I will say.

Please Sign in or register to post replies

Write your reply to:

Draft