i want to rewrite all URLs with trailing ".pdf" to open the pdf-files in the mozilla.pdf.js and have successfully testet following RewriteRule and RewriteCond on my HTTP virtual host (I use apache2 on ubuntu server btw):

example URL to rewrite:

```
http://server-test.local/downloads/dir2/file5/test.pdf

```

example target URL after rewrite:

```
http://server-test.local/libs/mozilla.pdf.js/web/viewer.html?file=/downloads/dir2/file5/test.pdf

```

```
RewriteCond %{HTTP_REFERER} !viewer.html
RewriteRule ^(.+)(\.pdf)$ http://server-test.local/libs/mozilla.pdf.js/web/viewer.html?file=$1 [R=301,L]

```

So the `RewriteCond` prevents another redirect which will cause the `mozilla.pdf.js` to try to load itself instead of the PDF file and cause an error. (Sry if description is unclear, i am not really into this topic)

Now I've tried to apply exact the same RewriteCond and RewriteRule for my other virtual host (https), which is - except of SSL and a Kerberos implementation - exact the same as the "server-test" virtual host:

```
RewriteCond %{HTTP_REFERER} !viewer.html
RewriteRule ^(.+)(\.pdf)$ https://server-prod.local/libs/mozilla.pdf.js/web/viewer.html?file=$1 [R=301,L]

```

but it seems that somehow the `RewriteCond` does not apply. The result is, that the redirect to the `mozilla.pdf.js` works, but the PDF will not be rendered and an error of the `mozilla.pdf.js` appears ("invalid PDF structure"), because - this is my theory- there is another redirection, so the `mozilla.pdf.js` does not load/render the pdf but it tries to load its own `viewer.html` instead.

I have also tried the following `RewriteCond`s, but no one of them changed the behaviour:

```
RewriteCond %{REQUEST_URI} !viewer.html*
RewriteCond %{REQUEST_URI} !^/libs/mozilla.pdf.js/web/viewer.html*
RewriteCond !viewer.html

```

My aim with these `RewriteCond`s is to prevent another (loop) redirection, if the URL before rewrite containing the string "viewer.html", so if the `[...]/viewer.html?file=/downloads/dir2/file5/test.pdf` is the `REQUEST_URI`, no more rewrite should happen.

Can someone please explain to me, why the `RewriteCond` works on the test virtual host (HTTP) but not on the production virtual host (HTTPS)? Except the SSL and the fact that the SSL secured virtual host has a Kerberos implementation, both virtual hosts, their directories and their configs are mostly the same. Is the SSL the problem? And does anyone know how I can fix this issue on the SSL virtual host? I need to find a solution somehow...

I would appreciate every kind of hints/help.