Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 如何基于HTTP引用重定向请求?_Apache_.htaccess_Redirect - Fatal编程技术网

Apache 如何基于HTTP引用重定向请求?

Apache 如何基于HTTP引用重定向请求?,apache,.htaccess,redirect,Apache,.htaccess,Redirect,我有一个重定向规则,可以将所有PDF、Word、Excel和Power point文档重定向到一个页面 RewriteEngine on RewriteRule ^(.*).(pdf|doc|docm|docx|dot|dotm|dotx|odt|csv|dbf|dif|xls|xlsb|xlsm|xlsx|xlt|xltm|xltx|xlw|pot|potm|potx|ppa|ppam|pps|ppsm|ppsx|ppt|pptm|pptx)$ http://myurl.ca/file-dow

我有一个重定向规则,可以将所有PDF、Word、Excel和Power point文档重定向到一个页面

RewriteEngine on
RewriteRule ^(.*).(pdf|doc|docm|docx|dot|dotm|dotx|odt|csv|dbf|dif|xls|xlsb|xlsm|xlsx|xlt|xltm|xltx|xlw|pot|potm|potx|ppa|ppam|pps|ppsm|ppsx|ppt|pptm|pptx)$ http://myurl.ca/file-download-tracker/?file=$1.$2 [R,L]
在那个页面上,我有一些代码,可以将这个文件的数据推送到Google Analytics,然后重定向回用户最初试图访问的文件

我正在尝试为此规则编写一个条件,仅当用户不是来自
http://myurl.ca/file-download-tracker/?file=myfile.pdf
url,但运气不好。我怎么写这个规则

这是我认为我与这种情况最接近的结果:

RewriteCond %{HTTP_REFERER} !^http://myurl.ca/file-download-tracker/.*

我找到了一个可行的条件,它可以检查引用者是否来自“文件下载跟踪器”页面

现在我正在与浏览器缓存作斗争。重定向到此页面后,浏览器会缓存重定向的文件,因此当我尝试返回到用户单击的原始文件时,浏览器会将我带回重定向页面。所以它现在陷入了一个循环

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^[^?]+\?([^&]*&)*file-download-tracker(.*)file=(.*)(&.*)?$
RewriteRule ^(.*).(pdf|doc|docm|docx|dot|dotm|dotx|odt|csv|dbf|dif|xls|xlsb|xlsm|xlsx|xlt|xltm|xltx|xlw|pot|potm|potx|ppa|ppam|pps|ppsm|ppsx|ppt|pptm|pptx)$ http://my-url.ca/file-download-tracker/?file=$1.$2 [L,NC,R=302,E=nocache:1]