twodayslate
twodayslate

Reputation: 2833

.htaccess to allow for file download if condition set

I currently have the current rule to allow for a file's viewing

RewriteRule ^ios/headers/([0-9]*\.[0-9]+|[0-9]+)/(.*).h$ /ios/headers/view.php?ios=$1&file=$2.h [L]

I have a list of header files and I want to put them through a viewer unless I set the ?raw=yes tag, then I want the user to be able to download it (actually go to the file).

How would I achieve this?

Is there a better way to do this? Is .htaccess even this powerful?

Upvotes: 1

Views: 150

Answers (1)

Jon Lin
Jon Lin

Reputation: 143876

You can check for the "raw=yes" using a RewriteCond:

RewriteCond %{QUERY_STRING} !raw=yes
RewriteRule ^ios/headers/([0-9]*\.[0-9]+|[0-9]+)/(.*).h$ /ios/headers/view.php?ios=$1&file=$2.h [L]

Then the rule won't get applied and the request won't get rewritten to view.php. Though, this is assuming that if you go directly to: /ios/headers/123.234/foo.h, you actually download foo.h. Otherwise, you'll need to add code in view.php for the raw=yes parameter and force the download through there.

Upvotes: 1

Related Questions