Mod rewrite mod_rewrite-根据x_wap_配置文件头的存在重定向到其他url

Mod rewrite mod_rewrite-根据x_wap_配置文件头的存在重定向到其他url,mod-rewrite,Mod Rewrite,我们有一个桌面版和一个移动版的webapp。 桌面url更突出,因此我们希望将用户重定向到移动版本,以防请求来自移动设备的桌面url 在apache配置中,我们有mod_rewrite模块 我现在的配置是这样的 <IfModule mod_rewrite> RewriteEngine On RewriteCond %{x-wap-profile} ^https?:// RewriteRule ^/(.*) http://google.com [L,R] </IfModule&g

我们有一个桌面版和一个移动版的webapp。 桌面url更突出,因此我们希望将用户重定向到移动版本,以防请求来自移动设备的桌面url

在apache配置中,我们有mod_rewrite模块 我现在的配置是这样的

<IfModule mod_rewrite>
RewriteEngine On
RewriteCond %{x-wap-profile} ^https?://
RewriteRule ^/(.*) http://google.com [L,R]
</IfModule>

重新启动发动机
重写COND%{x-wap-profile}^https?://
重写规则^/(*))http://google.com [左,右]
在这一点上,这是我们唯一的重写规则,所以我不确定是否需要L,因为这是第一条也是最后一条规则

我刚刚指示重定向到google.com进行测试

我不确定我的条件检查是否正确。我无法确定如何检查是否存在标头。这是错误的吗?如果是,请告诉我如何指定重写条件

我是怎么测试的? 我正在Firefox浏览器上进行测试,并使用ModifyHeaders插件模拟移动请求。我正在添加x_wap_配置文件头。
但是,我没有看到此配置发生任何重定向。您能告诉我哪里出了问题吗?如果这里可以引入任何日志来验证是否触发了此规则,我也将不胜感激。尽管当前修改的配置没有出现任何错误。

检查mod_rewrite中的任意头(即标题不在中),语法为:

RewriteCond %{HTTP:x-wap-profile}

这一条似乎有效:

RewriteEngine On
RewriteCond %{HTTP:x-wap-profile} ^.+
RewriteRule .* http://google.com [L,R]


piotrek@piotrek-Vostro-2520:~/vhosts/localhost$ curl http://localhost/
OKOK
piotrek@piotrek-Vostro-2520:~/vhosts/localhost$ curl -H 'x-wap-profile: abcd' http://localhost/
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="http://google.com">here</a>.</p>
<hr>
<address>Apache/2.4.6 (Ubuntu) Server at localhost Port 80</address>
</body></html>
重新编写引擎打开
重写cond%{HTTP:x-wap-profile}^+
重写规则。*http://google.com [左,右]
piotrek@piotrek-Vostro-2520:~/vhosts/localhost$curlhttp://localhost/
好的
piotrek@piotrek-Vostro-2520:~/vhosts/localhost$curl-H'x-wap-profile:abcd'http://localhost/
302发现
建立
文档已移动


部分中,您应该注意的其他事项: