HTTP_USER_AGENT的.htaccess不工作 [英] .htaccess HTTP_USER_AGENT not working

查看:335
本文介绍了HTTP_USER_AGENT的.htaccess不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有.htaccess文件的问题,通常它会检查用户引用者,如果是从我的网站,它允许访问流mp4文件,但是现在我想允许分流到Android和iOS设备,我用间HTML5的标签,但它不会发送HTTP_REFERER所以我要检查用户代理,使MP4文件流,这是我的,但它只是不工作。

  RewriteEngine叙述上
的RewriteCond%{HTTP_USER_AGENT}的Andr​​oid |的iPod | iPhone | iPad的[NC,OR]
的RewriteCond%{HTTP_REFERER} ^ HTTP://(。直接\ | WWW \)mysite的\ .COM /.*$ [NC]
重写规则。* \。(MP4)$ http://www.mysite.com [R,NC]
 

解决方案

您使用的是否定在这里,所以你就失去了 [OR] 键,包括< !code> :

 的RewriteCond%{HTTP_USER_AGENT}(安卓|的iPod | iPhone | iPad的)![NC]
 

你的规则正在做的是重定向的时,它是不正确的引用者,而不是一个移动用户代理。你有什么之前:

 的RewriteCond%{HTTP_REFERER} ^ HTTP://(。直接\ | WWW \)mysite的\ .COM /.*$ [NC]
重写规则。* \。(MP4)$ http://www.mysite.com [R,NC]
 

时的一句话:如果引用者的不是 HTTP:(。直接\ | WWW \)?// mysite的\ .COM / ,然后重定向.MP4请求 http://www.mysite.com 。这里的逻辑是,如果引用者是正确的,他们可以得到的MP4文件就好了。

要遵循,你说,如果引用者是正确的逻辑的的,如果用户代理是移动的,服务于MP4,你需要否定整个事情。 (A或B) - &GT;做一些事情,到(A或B) - GT!;不要做一些事情,翻译过来就是:! A和B - &GT;不要做一些事情

所以,你需要否定的移动用户代理检查,而不是一个使用(这是什么东西默认重写条件下)。

I'm having problems the .htaccess file, normally it checks the user referer and if is from my site it allows the access to stream mp4 files, but now I want to allow the streaming to Android and iOS devices, I'm using html5 tag but it doesn't send http_referer so I want to check the user agent to allow the stream of the mp4 files, this is what I have but it just doesn't work.

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} "Android|iPod|iPhone|iPad" [NC,OR]
RewriteCond %{HTTP_REFERER} !^http://(direct\.|www\.)?mysite\.com/.*$ [NC]
RewriteRule .*\.(mp4)$ http://www.mysite.com [R,NC]

解决方案

You are using a negation here, so you have to lose the [OR] and include a !:

 RewriteCond %{HTTP_USER_AGENT} !(Android|iPod|iPhone|iPad) [NC]

What your rule is doing is redirecting when it is not the correct referer and is not a mobile user-agent. What you had before:

RewriteCond %{HTTP_REFERER} !^http://(direct\.|www\.)?mysite\.com/.*$ [NC]
RewriteRule .*\.(mp4)$ http://www.mysite.com [R,NC]

Is saying: If the referer isn't from http://(direct\.|www\.)?mysite\.com/, then redirect the .mp4 request to http://www.mysite.com. The logic here is if the referer is correct, they can get to the mp4 file just fine.

To follow the logic where you say if the referer is correct or if the user-agent is mobile, serve the mp4, you need to negate the entire thing. (A or B)-> do something, to !(A or B) -> don't do something, which translates to: !A and !B -> don't do something.

So you need to negate the mobile user-agent check and instead of an OR use an AND (which is what is default for rewrite conditions).

这篇关于HTTP_USER_AGENT的.htaccess不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆