Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.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/9/ios/111.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
基于浏览器类型和url模式的Apache重定向_Apache_.htaccess_Redirect_Mod Rewrite_Url Rewriting - Fatal编程技术网

基于浏览器类型和url模式的Apache重定向

基于浏览器类型和url模式的Apache重定向,apache,.htaccess,redirect,mod-rewrite,url-rewriting,Apache,.htaccess,Redirect,Mod Rewrite,Url Rewriting,我想对apache进行配置,这样,如果请求的url与某个模式匹配,并且是某个浏览器的url,它就会被重定向到特定的页面 我知道我可以重定向到阅读用户代理的页面,以使用以下内容获取浏览器: RewriteCond "%{HTTP_USER_AGENT}" ".*Trident.*" 例如,如果它是IE,并且url与特定模式匹配,我希望它随后被重定向到自定义html页面 这是url模式: https://example.com/alt/var/b?a=[v

我想对apache进行配置,这样,如果请求的url与某个模式匹配,并且是某个浏览器的url,它就会被重定向到特定的页面

我知道我可以重定向到阅读用户代理的页面,以使用以下内容获取浏览器:

RewriteCond "%{HTTP_USER_AGENT}"  ".*Trident.*"
例如,如果它是IE,并且url与特定模式匹配,我希望它随后被重定向到自定义html页面

这是url模式:

https://example.com/alt/var/b?a=[variable]:[numeric variable]:[someother variables I don't car eabout]

Examples:
https://example.com/alt/var/b?a=cat:200:someotherstuff
https://example.com/alt/var/b?a=cat:350:someotherstuff
https://example.com/alt/var/b?a=dog1:200:someotherstuff
https://example.com/alt/var/b?a=dog1:99:someotherstuff

我只对前两个变量感兴趣。第一个变量总是不同的。第二个变量(只能是一个数字)也总是不同的。如果第二个变量等于99,并且浏览器是IE,我希望它重定向到我的自定义html页面。我的问题是,我还没有弄清楚如何为此编写规则?零件将始终保持不变。

请您尝试以下内容,并按照所示样本编写。请确保在测试这些URL之前清除浏览器缓存。如果您想匹配
a=
之后的任何数字,那么这将起作用

RewriteEngine ON
RewriteCond %{HTTP_USER_AGENT} Trident|MSIE [NC]
RewriteCond %{THE_REQUEST} \s/alt/var/b\?a=[\w-]+:[0-9]+:[^\s]*\s [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/your_custom_page [L]

请你试一下下面的,按照你展示的样品写的。请确保在测试这些URL之前清除浏览器缓存。如果您想匹配
a=
之后的任何数字,那么这将起作用

RewriteEngine ON
RewriteCond %{HTTP_USER_AGENT} Trident|MSIE [NC]
RewriteCond %{THE_REQUEST} \s/alt/var/b\?a=[\w-]+:[0-9]+:[^\s]*\s [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/your_custom_page [L]
如果第二个变量等于
99
,并且浏览器是
IE
,我希望它重定向到我的自定义html页面

您可以使用此重定向规则:

RewriteEngine On

RewriteCond %{HTTP_USER_AGENT} Trident|MSIE [NC]
RewriteCond %{THE_REQUEST} /alt/var/b\?a=[^:]+:99:[^\s&]*\sHTTP [NC]
RewriteRule ^ /custom.html? [L,NE,R=301]
  • %{HTTP_USER_AGENT}Trident|MSIE
    :将匹配
    IE的用户代理
  • :99:
    :仅当第二个变量根据要求为
    99
    时才会重定向
  • 目标末尾的
    将去掉以前存在的查询字符串

如果第二个变量等于
99
,并且浏览器是
IE
,我希望它重定向到我的自定义html页面

您可以使用此重定向规则:

RewriteEngine On

RewriteCond %{HTTP_USER_AGENT} Trident|MSIE [NC]
RewriteCond %{THE_REQUEST} /alt/var/b\?a=[^:]+:99:[^\s&]*\sHTTP [NC]
RewriteRule ^ /custom.html? [L,NE,R=301]
  • %{HTTP_USER_AGENT}Trident|MSIE
    :将匹配
    IE的用户代理
  • :99:
    :仅当第二个变量根据要求为
    99
    时才会重定向
  • 目标末尾的
    将去掉以前存在的查询字符串

回答得好@Anubhava先生。祝你生日快乐,谢谢。最后的\sHTTP是做什么的?
请求的一个例子是``GET/index.php?id=123 HTTP/1.1`它一直匹配到
HTTP
@anubhava谢谢。要确认它是否适用于https?是的,它将适用于
https
以及Good Response@Anubhava sir。祝你生日快乐,谢谢。最后的\sHTTP是做什么的?
请求的一个例子是``GET/index.php?id=123 HTTP/1.1`它一直匹配到
HTTP
@anubhava谢谢。要确认它是否可以使用https?是的,它也可以使用
https