0

I am working on a rewrite rule in Apache 2.4 in which any URL that ends with .pdf/ should add a query parameter and transform it to .pdf?q=pdf.

Example: http://www.example.com/us/elections.pdf/ should transform to http://www.example.com/us/elections.pdf?q=pdf

I tried to use the following rule and it worked

RedirectMatch 301 ^(.*).pdf/ $1.pdf?q=pdf

The problem is we also have some links in website like {hostname}/us/elections.pdf/node/img.thumbnail.png

For this, the above rule is adding q=pdf before node and transforming like {hostname}/us/elections.pdf?q=pdf_node_/img.thumbnail.png

How i can avoid this to happen?

How can i transform my rule in such a way that it works only for links which has .pdf/ at the end?

Any help would be great.

1 Answers1

1

If you want your regex to match only when it ends with '.pdf/' then you should write the regex accordingly and include the end of string anchor.

Change:

RedirectMatch 301 ^(.*).pdf/ $1.pdf?q=pdf

To:

RedirectMatch 301 ^(.*).pdf/$ $1.pdf?q=pdf

Note the $ at the end of the regex.