0

I have two rewrite rules:

RewriteRule ^library/(.*)$ market-intelligence/resources/$1 [L,R=301]
RewriteRule ^library/.*\.pdf$ email/$1 [L,R=301]

As one can see, they are for the same directory, but the second deals with all pdf files. However, any pdfs in the directory still lead to the first rule's destination.

Am I doing something wrong?

psorensen
  • 809
  • 4
  • 17
  • 33

1 Answers1

1

Am I doing something wrong?

Yes. Rules are tested sequentially and with the [L], the first matching rule fires and quits that scan. So the trick is to order your rules from the specific to the general. In this case swap them. The PDFs will be rewritten to the email folder and the rest to market-intelligence/resource.

TerryE
  • 10,724
  • 5
  • 26
  • 48
  • On a related note, do you see anything wrong with the .pdf rule? The redirect rule works accordingly, but it redirects `library/{file}.pdf` to `email/.pdf`instead of `email/file.pdf` – psorensen Feb 26 '14 at 20:11
  • 1
    Sorry, missed that one. `$1` matches match-pattern 1 in your regexp. You forgot the brackets, so you don't have one. Try `^library/(.*\.pdf)$`. Also read my [Tips for debugging .htaccess rewrite rules](http://stackoverflow.com/questions/9153262/tips-for-debugging-htaccess-rewrite-rules). – TerryE Feb 27 '14 at 01:26