« Previous Next »

Not Answered Thread: URL Rewrite based on Query string value Swtich case...

Last post 12-02-2009 7:21 AM by mehta_gaurav. 6 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (7 items)

Sort Posts:

  • 10-09-2009, 6:50 AM

    URL Rewrite based on Query string value Swtich case...

    Hi,

    I need to redirect existing site pages to new site pages based on query string value

    e.g.

    http://www.xyz.com/default.php?doc_id=242&test  to http://www.xyz.com/mypage.aspx

    I have following requirements:

    1) need to consider only doc_id value, everything including "&" and text following it is optional. so that means

    All below URL should redirect to single page that is :  http://www.xyz.com/mypage.aspx

     

    http://www.xyz.com/default.php?doc_id=242

    http://www.xyz.com/default.php?doc_id=242&

    http://www.xyz.com/default.php?doc_id=242&te

    http://www.xyz.com/default.php?doc_id=242&test

     

    2)

    First requirement applies to all URLs additionally I need to do following:

    I have list of doc_ids, say from 1 to 150 and based on doc_id value I need to redirect on different pages

    If doc_id does not belongs to our list then it should be redirected to home page

    how to do this ? Is it possible to write swtich case ?

    Please let me know your feedback as I am very new to URL rewrite/redirect

    Regards,

    Gaurav

  • 10-15-2009, 1:25 AM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 3:38 PM
    • Redmond, WA
    • Posts 670

    Re: URL Rewrite based on Query string value Swtich case...

    for the 1): This post http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/ , tip #9 should give you an idea how to write a rule for that.

    Re 2): The rewrite maps should help here, e.g.:

    <rule name="Query String Rewrite">
      <match url="default\.php$" />
      <conditions>
        <add input="{QUERY_STRING}" pattern="p1=(\d+)" />
        <add input="{DocID2Page:{C:1}}" pattern="(.+)">
      </conditions>
      <action type="redirect" url="{C:1}" appendQueryString="false"/>
    </rule>

    <rewritemap name="DocID2Page" defaultValue="home.php">
       <add key="1" value="page1.php" />
       <add key="2" vlaue="page2.php" />
    </rewritemap>

    Note: the rules above are just to give you an idea. they are not properly formatted and have not been tested.

    http://ruslany.net
  • 10-15-2009, 1:30 AM In reply to

    Re: URL Rewrite based on Query string value Swtich case...

    Thanks very much for ur reply.

    I will  check this and do necessary changes as per our settings and let you know.

     

    Regards,

    Gaurav

  • 10-15-2009, 1:55 AM In reply to

    Re: URL Rewrite based on Query string value Swtich case...

    Hi Ruslany,

    Below is my another requirement for Domain rule:

    1) http://(www.)xyz.com/ (-with or without preceding www)  => 301 => http://www.xyz.com.in/ (- must have preceding www)

    2) http://(www.)xyz.com/example-page (- with or without preceding www)  => 301 => http://www.xyz.com.in/example-page (- must have preceding www)

    In short any additional domain e.g "xyz.com" should be redirected to "xyz.com.in"


    I have created following rule for above requirement and place it 1st on the rule list:

     <rule name="Canonical Host Name" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                            <add input="{HTTP_HOST}" negate="true" pattern="http://www.xyz.com.in" />
                    </conditions>
                    <action type="Redirect" url="http://www.xyz.com.in/{R:1}" redirectType="Permanent" appendQueryString="true" />
                  </rule>

    At present it is working fine but I want your feedback. Would you please check and let me know whether this rule is correct or not ?

    If there is any good alternative then do let me know

    Thanks,
    Gaurav

  • 10-19-2009, 5:43 PM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 3:38 PM
    • Redmond, WA
    • Posts 670

    Re: URL Rewrite based on Query string value Swtich case...

    gaurav_mehta:

    <add input="{HTTP_HOST}" negate="true" pattern="http://www.xyz.com.in" />

    This condition does not look right to me. It will always be true because the pattern will never match. The HTTP_HOST never contains the protocol prefix "http://".

    http://ruslany.net
  • 11-03-2009, 12:34 AM In reply to

    Re: URL Rewrite based on Query string value Swtich case...

     Thanks for your feedback. I will check this.

     

    BTW: Sorry for the delayed reply as I was not available for some days. Do  you suggest any other good alternative for this ?

     

    Regards,

    Gaurav

  • 12-02-2009, 7:21 AM In reply to

    Re: URL Rewrite based on Query string value Swtich case...

    I have changed the pattern in condition like this:

    pattern="www.xyz.com.in"

    It seems to be working fine as of now. If you have better solution then plz do let me know.

Page 1 of 1 (7 items)
Microsoft Communities