Copied to clipboard

Flag this post as spam?

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


  • Ryan 35 posts 129 karma points
    Apr 01, 2013 @ 16:05
    Ryan
    0

    Query string to friendly URL rewrite rule

    Hi

    I'm having some issues with a URL rewrite rule.  I've searched the forums/web and found similar posts, but I am not able to get this working.

    We need a rule to make query strings like this: http://www.mysite.com/page.aspx?something=something

    To something like this automatically: http://www.mysite.com/page/something/something

    If the query string was something like page.aspx?something=/something/something/something would it still work?  If umbracoUseDirectoryUrls are turned on the in the web.config, will that cause an issue?  Are there any other config changes that need to be made?  Will the rewritten URL be linkable and crawlable for search/seo?

    Thanks for your help!

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 01, 2013 @ 18:32
    Tom Fulton
    1

    Hi Ryan,

    You should be able to use the built-in UrlRewriting library to achieve this, by adding a rule to the config file @ /config/urlRewriting.config.  There's an example there that should get you started.  Did you already try this and are having problems?

    Directory URLs shouldn't matter since you're using a querystring.

    The rewritten URL should be linkable and crawlable, but it's up to you to add links to it in the right format across your pages.

    Let us know how you get on

    -Tom

  • Ryan 35 posts 129 karma points
    Apr 01, 2013 @ 19:19
    Ryan
    0

    Hi Tom,

    Thanks for the help.  I've been trying to tweak the example in the file without any luck.  Are you able to provide an example for me to try?  Thanks again!

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 01, 2013 @ 19:28
    Tom Fulton
    1

    I think this should work.  You might need to touch your web.config in order for the change to take effect:

     

    <add name="test"
    virtualUrl="^~/page/something/(.*)"
    rewriteUrlParameter="ExcludeFromClientQueryString"
    destinationUrl="~/page.aspx?something=$1"
    ignoreCase="true" />

    -Tom

  • Ryan 35 posts 129 karma points
    Apr 01, 2013 @ 20:09
    Ryan
    0
    <add name="test" virtualUrl="^~/healthlibrary/(.*)" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/healthlibrary.aspx?test=$1" ignoreCase="true" />

    If I type in my address ... /healthlibrary.aspx?test=blah, nothing happens.  I've tried adding a comment to the web.config and did an iisreset.  I toggled the umbracoUseDirectoryUrls true false as well for the heck of it.  Thoughts?  Thanks again!

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 02, 2013 @ 05:00
    Tom Fulton
    0

    When you say nothing happens, are you getting a 404 or a blank page or something else?

    If you're not able to get to your destination URL that sounds like another issue.  If you comment out the new rule, can you then get to the /healthlibrary.aspx?test=xxxx URL?  If so, what URL are you using to test?

  • Ryan 35 posts 129 karma points
    Apr 03, 2013 @ 15:26
    Ryan
    0

    Hi Tom, it is working.  I was just expecting it to redirect to the friendly URL, but that's not what the rewrite does.  The more I though about it, the directory URLs still allow the .aspx.  I'm not getting a 404 anymore, so it is working.

    Is there an easy way to automatically redirect the query string to the friendly URL?  Thanks for your help.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 03, 2013 @ 18:24
    Tom Fulton
    0

    Hmm, not sure about that.  You could possibly add another rewrite rule that matches the querystring version of the URL and does a Redirect (not a rewrite) to the "clean" version, but not sure if that will end up in an infinite loop.  You might also be able to put some code on your page that somehow detects you're on the querystring version and redirects, not too sure if that will work though.

    I don't think it's an issue as long as you link to the "clean" version in all your code.  Or are you worried users already have links to the querystring version?

Please Sign in or register to post replies

Write your reply to:

Draft