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

Rewrite rules

2 posts, 0 answered
  1. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    04 Nov 2010
    Link to this post
    Hi,

    Im using the Advanced URLRewriter to rewrite url's from the old website. The old website had lots of urls like:

    /news.asp?item=123

    For each of these I want to redirect them with a 301 to my news homepage. I have setup the following rule, which works (partly):

    <rule mode="PermanentRedirect">
                    <url>/news\.asp(?![x])</url>
                    <rewrite>/news-events/news.aspx</rewrite>
                </rule>

    The only problem I am getting is that the querystring is automatically appended, so:

    /news.asp?id=123

    Redirects to:

    /news-events/news.aspx?id=123

    Which is not what I want. I dont want to append the querystring...is that happening just because it is within the brackets?

    Thanks in advance
    higgsy
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    05 Nov 2010
    Link to this post
    Hello higgsy,

    Thank you for using our services.

    Since the UrlRewriter works with regular expressions it users Regex.Replace method to replace the matched result with the rewrite rule. In your case the group for the query string is excluded from the match rule and the regular expression leave it. You can try with rule like this if you do not want to pass the query string parameter:
    <rule>
        <url>/news\.asp(\?([\w=&]+))</url>
        <rewrite>/news-events/news.aspx</rewrite>
    </rule>

    This rule will also match the query string and replace it in the replace method call.

    Sincerely yours,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered