More in this section

Forums / Developing with Sitefinity / Urlrewriting - redirect

Urlrewriting - redirect

10 posts, 0 answered
  1. Andreas
    Andreas avatar
    49 posts
    Registered:
    29 Dec 2007
    25 May 2009
    Link to this post
    Hello!

    I got a problem ahead of me that I need some help with or maybe just a few suggestions. Here's what I have..

    I need to handle some old URLs from a customers old website that are accessed via applications when we release the new one built on Sitefinity 3.6.

    Old URLs that needs handled could look like this:
    www.domain.com/search/app?catid=123&prodid=456&langid=789
    This needs to be picked up and redirected to an external domain while also renaming the variables e.g:
    www.anotherdomain.com/legacy/app?cid=123&pid=456&lid=789
    There will be several different URLs that needs matching and redirecting and I have no information on what they all will look like exactly.

    So anyway, I started setting this up with the advanced url rewriting in Sitefinity using wildcard mapping in the IIS. What I need help with now is the following...

    1. How do I set up the urlrewriting rules to pick up the different variables at the correct spots in the redirect url?
    2.  How should I set up the URL rewriting to redirect to an external url using Sitefinity 3.6?
    3. Did I even go about this the smoothest way? I get the nagging feeling that I should have handled this differently. Any suggestions on how to deal with this in another way are more than welcome.

    Thanks in advance.

    //Andreas
  2. Parvan
    Parvan avatar
    151 posts
    Registered:
    24 Sep 2012
    25 May 2009
    Link to this post
    Hi Andreas,

    Following are answers to your questions:

    1. How do I set up the urlrewriting rules to pick up the different variables at the correct spots in the redirect url?
    Setup instructions for Url Rewriter can be found in the User Manual - section Url Rewriting.
    The Url Rewriting feature of Sitefinity allows you to define the rules of input to match url and replacement string. Url rewriter uses .NET Regular expressions, but rewriting is not doing redirecting - it allows you to change the requested url to other url that is in the same ASP.NET application. Rules are written in the web.config file of the site.

    For example, let's suppose your Sitefinity site is located at this url: www.anotherdomain.com/legacy/app?cid=123&pid=456&lid=789
    You can use the url rewriter only in the boundaries of this application.
    Sample url rewrite rule (set it in the web.config file):
    <urlrewrites> 
        <url>/search/app?catid=([\d]+)&amp;prodid=([\d]+)&amp;langid=([\d]+)</url> 
        <rewrite>/legacy/app?cid=$1&pid=$2&lid=$3</rewrite> 
    </urlrewrites> 

    2. How should I set up the URL rewriting to redirect to an external url using Sitefinity 3.6?
    If you want to redirect to external domain you can use this solution - it allows you to define rules again but the replacement url can be external site. Then, there will be a real HTTP redirect. Example:
    <urlrewrites> 
        <url>/search/app?catid=([\d]+)&amp;prodid=([\d]+)&amp;langid=([\d]+)</url> 
        <rewrite>http://www.anotherdomain.com/legacy/app?cid=$1&pid=$2&lid=$3</rewrite> 
    </urlrewrites> 


    3. Did I even go about this the smoothest way? I get the nagging feeling that I should have handled this differently. Any suggestions on how to deal with this in another way are more than welcome.
    If the old site was ASP.NET site you can move the aspx pages to the sitefinity site (for Url Rewriter is important to have the old and new urls on the same ASP.NET application.

    I hope this information helps you.

    Best wishes,
    Parvan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal
    Check out the tips for optimizing your support resource searches.
  3. Andreas
    Andreas avatar
    49 posts
    Registered:
    29 Dec 2007
    26 May 2009
    Link to this post
    Hi and thanks!

    Yes this helps alot although I'm not quite there yet....

    Do the changes made to CmsHttpModule in 3.6 (see this threaed http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-cbdkch.aspx) affect the custom CmsHttpModuleUrlRedirect? Cause I can't really get it to work, all it does is redirect endlessly.

    Also, the rewrite redirects for me as well without using the CmsHttpModuleUrlRedirect class. This is using the wildcard mapping in the IIS.

    //Andreas
  4. Parvan
    Parvan avatar
    151 posts
    Registered:
    24 Sep 2012
    28 May 2009
    Link to this post
    Hello Andreas,

    We tested in Sitefinity 3.6 and the code should work.
    I have made fixes in the url rewrite rule:

    <urlrewrites> 
        <rule> 
            <url>/search/app\?catid=([\d]+)&amp;prodid=([\d]+)&amp;langid=([\d]+)</url> 
            <rewrite>/legacy/app\?cid=$1&amp;pid=$2&amp;lid=$3</rewrite> 
        </rule> 
    </urlrewrites>  

    As I noticed you have already configured wildcard mapping in the IIS, so this rule should work.
    If there are still problems can you send me your rewrite rules so I can try to reproduce the problem at our side.

    If you want the rules to perform redirection, use the solution in the forum. Then your modules sections in web.config are configured this way:

    <modules>   
    ...   
    <add name="Cms" type="Telerik.Cms.Web.CmsHttpModuleUrlRedirect, App_Code"/>   
    ...   
    </modules>   
      
    <httpModules>   
     ...   
    <add name="Cms" type="Telerik.Cms.Web.CmsHttpModuleUrlRedirect, App_Code"/>   
    ...   
    </httpModules>   


    If you do not want redirects then change the module like described in the User Manual:

    Parvan
    r nickname
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Andreas
    Andreas avatar
    49 posts
    Registered:
    29 Dec 2007
    29 May 2009
    Link to this post
    Thanks for the update Parvan.

    I've been testing both rewriting and redirecting on a new project it all works like a charm. Which makes it even worse since I can't blame anyone but myself for it not working now. ;-)

    Have a nice weekend and thanks for an outstanding support.

    //Andreas
  6. Andreas
    Andreas avatar
    49 posts
    Registered:
    29 Dec 2007
    29 May 2009
    Link to this post
    And its back to not working like a charm again.

    How are the urls for rewriting cached? Is there a way to clear it? It seems that once a rule been added to the array of urls to be rewritten its not going away. After removing all rewriting rules, restarting the webserver, clearing my browser cache I still get reirected/rewritten to an "old" rule that no longer exists. That just doesnt seem right. 

    I think this is what messed up my previous project. The website was redirecting to an old url I had added while testing and got into a loop.

    //Andreas
  7. Parvan
    Parvan avatar
    151 posts
    Registered:
    24 Sep 2012
    01 Jun 2009
    Link to this post
    Hello Andreas,

    The changes in the rewrite rules are applied immediately.
    Can you describe in more details how to reproduce the problem - for example, the exact rewrite rules you have used initially, what happened after changing the rules. The exact requested  urls and rules are important to reproduce the problem on our side.

    Regards,
    Parvan
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
  8. Andreas
    Andreas avatar
    49 posts
    Registered:
    29 Dec 2007
    01 Jun 2009
    Link to this post
    I used to have the following rules, while using wildcard mapping in the IIS and the redirect class supplied in another thread.

    <rule>/test</rule>
    <rewrite>http://www.mypage.com</rewrite>

    <rule>/test2</rule>
    <rewrite>/page1.aspx</rewrite>

    I removed the rules (and all other rules) friday, cleared browser cache, restarted webserver service etc but I still get redirected. There's nothing in my project that says I should be redirected when typing /test or /test2 now but I still am. Rewriting or redirecting doesnt matter. 

    If you remove your rule does it still not apply when you test it? I'm using Sitefinity 3.6 1936 btw.
  9. Andreas
    Andreas avatar
    49 posts
    Registered:
    29 Dec 2007
    01 Jun 2009
    Link to this post
    Hold a bit Parvan. Need to check something.

    //Andreas
  10. Sonya
    Sonya avatar
    231 posts
    Registered:
    24 Sep 2012
    01 Jun 2009
    Link to this post
    Hello Andreas,

    We will temporarily close this ticket. Please open it once you have any questions or you want us to continue with the investigation.

    All the best,
    Sonya
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
10 posts, 0 answered