Share via

Blocking a specific URL using IIS URL Rewrite

Jabez Gan 21 Reputation points
2022-05-30T15:38:05.493+00:00

I have a URL:

test.com/ekp/api

I want to block all access to /ekp/api/* (including /ekp/api), but it seems like doesnt work.

206777-image.png

Any idea if this rule is correcT?

Windows development | Internet Information Services
0 comments No comments

Answer accepted by question author

Bruce Zhang-MSFT 3,776 Reputation points
2022-05-31T01:47:57.273+00:00

Hi @Anonymous ,

In my test, I made some changes in condition of URL, */ekp/api/* to /ekp/api/*. It can work well and show me 403 error. You can try this.

 <rule name="RequestBlockingRule1" patternSyntax="Wildcard" stopProcessing="true">  
                    <match url="*" />  
                    <conditions>  
                        <add input="{URL}" pattern="/ekp/api/*" />  
                    </conditions>  
                    <action type="CustomResponse" statusCode="403" statusReason="Forbidden: Access is denied." statusDescription="You do not have permission to view this directory or page using the credentials that you supplied." />  
                </rule>  

206787-1.png

If it still cannot work, please use failed request tracing to check what happened during the rewrite.


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Best regards,
Bruce Zhang

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Jabez Gan 21 Reputation points
    2022-05-31T03:18:48.137+00:00

    Hi Bruce,

    Thanks. Sorry - I just had to move my rules to the top. Noticed another rule was allowing it.

    Thanks1

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.