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

Redirect to 404 if there is "?" (Question mark) in the urlRSS

1 reply

Last post May 29, 2021 07:46 AM by lextm

  • Redirect to 404 if there is "?" (Question mark) in the url

    May 28, 2021 08:14 AM|arunasivan|LINK


    I am trying to redirect a page if there is a "?" in the URL using web.config,  but it is not working

    I added a condition to negate if the param is "?"

    The rule is 

        <rule name="Activa-LT_rd" stopProcessing="true">
        <match url="Activa-LT.asp" />
        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{UNENCODED_URL}" pattern="\?" negate="true" />
        <action type="Redirect" url="Activa-LT/" redirectType="Permanent" />

    Appreciate any help 

  • Re: Redirect to 404 if there is "?" (Question mark) in the url

    May 29, 2021 07:46 AM|lextm|LINK

    If you study some basic concepts of URLs, you will see that "?" in the browser's address bar only indicates a query is appended, https://en.wikipedia.org/wiki/Uniform_Resource_Identifier

    Then on IIS side you should check if the query exists, like https://stackoverflow.com/questions/12648281/iis-rewrite-rule-to-check-for-querystring-and-add-it-if-its-not-there 

    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.