Forum Moderators: phranque
Just wondering if it's possible for .htaccess to use a variable sent by php. I wish to use the variable in a precondition for mod_rewrite. That way, the .htaccess knows whether a user has been validated by my php script and will not redirect but instead allow the user to access a file. I looked into using enviroment variables but couldn't find anything clear enough to help my cause.
My .htacces:
RewriteEngine on
RewriteRule ^([^.]+\.rar)$ validate.php?file_to_download=$1 [NC]
If it is possible, what would such a precondition look like?
Thanks in advance,
Toucan
RewriteCond %{QUERY_STRING} ^yourvariable=(someEXPRESSION)
RewriteRule ^([^.]+\.rar)$ /validate.php?what-ever-you-would-like=$1-OR-%1 [NC,L]
%1 rather than $1 will give you the back-reference from the condition.
Hope this gives you some ideas.
Justin
BTW Added L flag to the rule -- should always be present, unless you know you do not need it.
Somehow, I either need to let .htaccess know that the user has been validated and not redirect (using a flag variable?)
OR..
only let .htaccess redirect when coming FROM a certain URL. Since my php script is the only one on the site, maybe it could allow access to the .zip file only if coming from .php?
Don't know whether either option is possible, I've looked around and find next to nothing.