csotelo
csotelo

Reputation: 1485

htaccess: rewrite rule to allow some file types with parameters (optionally)

I've written a rule that redirect to my login page before checking or downloading a file:

Options -Indexes 
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^https://mi.domain/*.$ [NC]
RewriteRule ^.*\.(pdf|ppt|pptx|htm|html|rar|zip|gz|tar|tif|txt)$ /security.php?file=$1 [NC]

If I visit https://mi.domain/omg.pdf works, but (to prevent cache browser) if I visit https://mi.domain/omg.pdf?v=1234 fails.

How to allow parameters?

Upvotes: 1

Views: 56

Answers (1)

anubhava
anubhava

Reputation: 786329

Use QSA flag in your rule to allow original query string in your URL to be preserved:

Options -Indexes 
RewriteEngine On

RewriteCond %{HTTP_REFERER} !^https://mi.domain/*.$ [NC]
RewriteRule ^.*\.(pdf|ppt|pptx|htm|html|rar|zip|gz|tar|tif|txt)$ /security.php?file=$1 [NC,QSA,L]

Upvotes: 1

Related Questions