locked
Redirect dynamic url / Webconfig file RRS feed

  • Question

  • User2145963266 posted

    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

    Friday, November 10, 2017 11:16 AM

Answers

  • User-460007017 posted

    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

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Monday, November 13, 2017 3:06 AM

All replies

  • User690216013 posted

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

    Saturday, November 11, 2017 12:19 AM
  • User-460007017 posted

    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

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Monday, November 13, 2017 3:06 AM
  • User2145963266 posted

    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. :)

    Monday, November 13, 2017 10:55 AM
  • User690216013 posted

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

    Tuesday, November 14, 2017 12:42 AM
  • User-460007017 posted

    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

    Tuesday, November 14, 2017 1:36 AM
  • User2145963266 posted

    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.

    Tuesday, November 14, 2017 9:54 AM
  • User2145963266 posted

    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.

    Tuesday, November 14, 2017 9:57 AM