Search code examples
regexweb-config

I need help making this regular expression to match part of url


I am writing a rewrite rule in web.config file and want to match against a url (using regular expression) if it containes:

*/admin*

So as long as the url contains above it should match. Example of legal matches:

http://test.com/admin
https://test.com/admin
http://test.com/admin/
http://test.com/admin/test
http://test.com/admin/grgr/hht/

Example of illegal matches:

http://test.com
https://test.com/adminpage
https://test.com/adminpage/

I have tried the followings without success:

<match url="(.*)/admin$" ignoreCase="false" />
<match url="/admin?" ignoreCase="false" />
<match url=".*/admin?" ignoreCase="false" />

Solution

  • Try this regex

    .*admin(\/.*|$)