1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Url Rewirting

7 posts, 0 answered
  1. Mike
    Mike avatar
    221 posts
    Registered:
    19 Aug 2008
    10 Dec 2008
    Link to this post
    Does the URL rewrite rules have to be fully qualified paths? Is there a way to use ~ to get the app root?

    So instead of:

        <urlrewrites>
          <rule>
            <url>/PFV3cms/product(.*)</url>
            <rewrite>/PFV3cms/Results.aspx?ProdId=$1</rewrite>
          </rule>
        </urlrewrites>

    i can do this: (Although this does not work)

        <urlrewrites>
          <rule>
            <url>~/product(.*)</url>
            <rewrite>~/Results.aspx?ProdId=$1</rewrite>
          </rule>
        </urlrewrites>

    Duncan
  2. Vlad
    Vlad avatar
    498 posts
    Registered:
    19 Jun 2017
    11 Dec 2008
    Link to this post
    Hi Duncan,

    Currently, "~/" is not supported in the rewrite rule, but you can skip the virtual directory path from it, i.e.:

        <urlrewrites>
          <rule>
            <url>/product(.*)</url>
            <rewrite>/Results.aspx?ProdId=$1</rewrite>
          </rule>
        </urlrewrites>


    Hope this helps.

    Regards,
    Vlad
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Mike
    Mike avatar
    221 posts
    Registered:
    19 Aug 2008
    11 Dec 2008
    Link to this post
    The issue that i have with this is the development environment. http://localhost/PFV3cms/ when in production this would just be the domain.

    Is there perhaps a Regular Expression i could use to accomplish this?

    Duncan
  4. Vlad
    Vlad avatar
    498 posts
    Registered:
    19 Jun 2017
    12 Dec 2008
    Link to this post
    Hi Duncan,

    Actually the provided in the previous post example (without specifying 'PFV3cms' in the rule pattern) should work on the both: your development and production servers. Here it is again:

    <urlrewrites ignoreCase="true">
          <rule>
            <url>/product(.*)</url>
            <rewrite>/Results.aspx?ProdId=$1</rewrite>
          </rule>
    </urlrewrites>


    Maybe the issue you have is related to something else. Could you please check this out and give us more details?

    Kind regards,
    Vlad
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Mike
    Mike avatar
    221 posts
    Registered:
    19 Aug 2008
    12 Dec 2008
    Link to this post
    Yeah you are correct, that does seem to work. I could have sworn i tried that... (nearing the end of the week, sorry about that)

    Thanks,

    Duncan
  6. Mike
    Mike avatar
    221 posts
    Registered:
    19 Aug 2008
    12 Dec 2008
    Link to this post
    Just an additional note on this... I have a page structure within SiteFinity that goes something like this:

    Product > Results
    Product > Details

    etc...

    <urlrewrites ignoreCase="true">
          <rule>
            <url>/product/(.*)</url>
            <rewrite>/Results.aspx?ProdId=$1</rewrite>
          </rule>
    </urlrewrites>


    The url rewrite seriously messes things up within the admin part of SiteFinity. When i created a new page under /product/ it duplicated Results.aspx page because the admin pages where rewriting the url to this page...

    Additionally even through i have programed catches in to check for querystring
    "ProdId", because of the rewrite being this way it does not matter it will alwasy try rendering the page with this querystring (as expected but a little annoying), needless to say the page throws exceptions because of this.

    Duncan
  7. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    Registered:
    09 Sep 2007
    13 Dec 2008
    Link to this post

    Hey Duncan,

    Thanks for providing this additional note.

    The URL rewriting happens prior to Sitefinity's execution.  By using it, you're essentially overriding Sitefinity's native handling of URLs.  This is perfectly fine and very powerful, but once it's done, there isn't really anything the Sitefinity can do to override your rules.


    -------

    Here are a couple of random thoughts:

    1.  Remove the URL rewriting pattern and begin managing all the ~/product/ pages in Sitefinity.  You could create external page links and point each external page link to whatever URL you wanted.

    Example:  ~/product/1234.aspx  redirects to ~/Results.aspx?ProdId=1234

    This is a very easy solution, but it might be cumbersome to maintain if you have TONS of links.

    2.  Make your URL matching pattern less greedy so it doesn't get applied to ~/product/ pages you're attempting to create in Sitefinity.

        <urlrewrites>
          <rule>
            <url>/product/_([a-z1-9_\-]*)</url>
            <rewrite>/Results.aspx?ProdId=$1</rewrite>
          </rule>
        </urlrewrites>

    Now the URL rewriting pattern only gets engaged if the product page is proceeded by an underscore.  Example:

    ~/product/_MyProduct.aspx

    If the page doesn't have a leading underscore, then the pattern won't be engaged.

    Gabe Sumner
    http://www.sitefinitywatch.com/

Register for webinar
7 posts, 0 answered