0

I'm trying to clean up some URLs to a bunch of PDF files. Right now, you access a PDF by visiting the following:

http://www.mywebsite.com/sites/default/files/reports/2010_Audit_Summary_Report.pdf

But I want to clean this up by being able to access the same files using this URL:

http://www.mywebsite.com/reports/2010_Audit_Summary_Report.pdf

I thought that I might be able to do the following:

<rule name="MySpecialRule" stopProcessing="true">
    <match url="/sites/default/files/reports/2010_Audit_Summary_Report.pdf" />
    <action type="Rewrite" url="/reports/2010_Audit_Summary_Report.pdf" />
</rule>

But this is not working. Of course, the sample rule above would only work for one PDF, where I want this to work for all PDFs within the same directory.

Is this possible?

HopelessN00b
  • 53,795
  • 33
  • 135
  • 209
dcolumbus
  • 475
  • 1
  • 5
  • 10
  • I'm not really understanding why no one has a solution ... I know this is possible, I just don't exactly know how to accomplish it. – dcolumbus Dec 31 '14 at 23:20

1 Answers1

0

To match more than one specific URL, you need to use a regular expression and then reference the found string in the action:

 <rule name="MySpecialRule" stopProcessing="true">
     <match url="/sites/default/files/reports/([_a-z0-9]+).pdf" />
     <action type="Rewrite" url="/reports/{R:1}.pdf" />
 </rule>

Here I assume your filename consists only of letters, digits and underscores. I haven't tested this, but it should give you the idea how to solve this.

Peter Hahndorf
  • 14,058
  • 3
  • 41
  • 58