Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

What's wrong with this web.config regex?

Posted on 2016-09-30
3
Medium Priority
?
62 Views
Last Modified: 2016-09-30
I have a web.config file with the following rule in it:

<rule name="redirectStaticFileRequestsToDownloadHandler" stopProcessing="true">
       <match url="board\/([0-9]+)\/boarddocs\/([^/]+)?$" />
      <action type="Redirect" url="/download?filename={R:2}" appendQueryString="false" />
</rule>

Open in new window


If anyone tries to access a file from a URL like "board/[any number]/boarddocs/[any string]" it will redirect them to "/download?filename=[that second string from the URL example]". I've run my code through http://www.regexr.com/ and it says it should be capturing group #2. I tested replacing {R:2} with {R:1} and it redirects to the first captured string ([any number]) like expected.

What am I doing wrong in trying to reference that second string? Thanks!
0
Comment
Question by:SiobhanElara
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 29

Accepted Solution

by:
Dr. Klahn earned 1000 total points
ID: 41823927
The up-caret ^ is a reserved character in regexes which indicates "start of string".  Since the location of the second regex is well past the start of string, there will be no match on any input.

Suggest:  .* instead which will capture anything to the end of the original URI.
0
 
LVL 20

Assisted Solution

by:Russ Suter
Russ Suter earned 1000 total points
ID: 41823940
@Dr. Klahn
The caret here is specifying that the capture group matches against any character that is not a '/' character. This is perfectly acceptable Regex syntax.

@SiobhanElara
This regex won't match if the user has additional '/' characters after. For example, the following URL would match:
http://board/2341/boarddocs/foo.html
But this won't:
http://board/2341/boarddocs/foo/mydoc.html

Could that be your issue here?
1
 

Author Closing Comment

by:SiobhanElara
ID: 41824058
Thanks, folks! Changing to .* solved the problem, including any slashes being passed along.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question