We are excited to announce that the IIS.NET Forums are moving to the new Microsoft Q&A experience. Learn more >

Redirect dynamic url / Webconfig file [Answered]RSS

7 replies

Last post Nov 14, 2017 09:57 AM by dazzclub

  • Redirect dynamic url / Webconfig file

    Nov 10, 2017 11:16 AM|dazzclub|LINK

    Hi All,

    I'm looking to redirect  old urls /blog/?p=13 (the number varies) to a static page..I'm looking to place this code in my webconfig file..

    the regex I've used to capture this is..^blog\/?p=[0-9]$

    and the code I use to place this in the webconfig file...

    <rewrite>
    <rules>
    <rule name="Blog Redirects" stopProcessing="true">
    <match url="^blog\/?p=[0-9]$" />

    <action type="Redirect" url="redirect url" redirectType="Permanent"/>
    </rule>
    </rules>
    </rewrite>

    Obviously the redirect isn't working, any pointers would be very much appreciated..

    Thanks

    Darren

  • Re: Redirect dynamic url / Webconfig file

    Nov 11, 2017 12:19 AM|lextm|LINK

    The part after ? is a query so you should add a condition to valid it, not as part of the URL in match tag.

    Lex Li
    Want to have a chat on the issues you meet? Book an appointment at https://buy.stripe.com/cN24ia0yi7sAdIA7sv
    ---------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Redirect dynamic url / Webconfig file

    Nov 13, 2017 03:06 AM|Yuk Ding|LINK

    Hi dazzclub,

    Try this one

        <rule name="rewrite" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{REQUEST_URI}" pattern="^/blog/\?p=[0-9]+" />
                        </conditions>
                        <action type="Redirect" url="redirect url" appendQueryString="false" />
                    </rule>

    It works fine on myside. The variable{REQUEST_URI} contain the uri /blog/ and query string p=13. Just ensure the URL begin with/blog/.

    If you only need to rewrite the URL which contain /blog/ pattern="/blog/\?p=[0-9]+" is enough.

    Best Regards,

    Yuk Ding

    Yuk Ding

    MSDN Community Support
    Please remember to "Mark as Answer" the responses that resolved your issue.
  • Re: Redirect dynamic url / Webconfig file

    Nov 13, 2017 10:55 AM|dazzclub|LINK

    Hi Yuk Ding,

    Thanks for the reply and I really appreciate your help.

    I've inserted my information where needed i.e redirect url ...

    When I include the code in my config file it crashes the server (brings down my website) displaying this code; 

    104:    <rule name="rewrite" stopProcessing="true">

    105:           <match url="(.*)" />

    Is there anything that I'm missing that should be included in that code? Maybe an additional tags/wrappers? 

    Thanks for your help. :)

  • Re: Redirect dynamic url / Webconfig file

    Nov 14, 2017 12:42 AM|lextm|LINK

    What exactly does the error page say except the line? It must tell what is the issue.

    Lex Li
    Want to have a chat on the issues you meet? Book an appointment at https://buy.stripe.com/cN24ia0yi7sAdIA7sv
    ---------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Redirect dynamic url / Webconfig file

    Nov 14, 2017 01:36 AM|Yuk Ding|LINK

    Hi dazzclub,

    Could you provide your <rewrites>section? It works fine on my side. So I assume there is a duplicated rule name crashing or the rule is not placed in the correct section. Also if you placed in a duplicated section, it could report this as well. In addition, just ensure URL rewrite module has been installed correctly.

    Best Regards,

    Yuk Ding

    Yuk Ding

    MSDN Community Support
    Please remember to "Mark as Answer" the responses that resolved your issue.
  • Re: Redirect dynamic url / Webconfig file

    Nov 14, 2017 09:54 AM|dazzclub|LINK

    Hi Yuk,

    I believe I placed it in the wrong section of the webconfig file which caused the site to crash.

    I've now placed it with another existing rewrite tag and all is working fine.

    Thank you very much for your help.

  • Re: Redirect dynamic url / Webconfig file

    Nov 14, 2017 09:57 AM|dazzclub|LINK

    Hi Lextem,

    Apologies for not getting back to you. Looking back on the code I think another "match rule" existed and that I placed it in the wrong section maybe within the wrong tags.

    Thank you for your help. I very much appreciate it.