【问题标题】:Apache mod rewrite rulesApache mod 重写规则
【发布时间】:2012-06-14 22:27:06
【问题描述】:

我们需要根据用户代理将用户重定向到移动网站或普通网站。
我正在尝试在我的 http.conf 文件中编写以下代码,但它似乎不起作用。谁能指出我的错误?

RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos" [NC] RewriteRule ^/shop/website ^/shop/mobile [L,R=302]

【问题讨论】:

    标签: apache


    【解决方案1】:

    下面的代码(从重定向目标中删除了一个虚假的插入符号,以及明确的 302 代码)在 httpd.conf 中适用于我,但如果你将它放在 .htaccess 中,则需要更改它文件:

    RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos" [NC]
    RewriteRule ^/foo.txt /bar.txt [L,R]
    

    (如果您将其放入 .htaccess 文件中,您将删除目录规范,因为您会将其放入目录上下文中:

    RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos" [NC]
    RewriteRule foo.txt bar.txt [L,R]
    

    我相信您可以删除显式 302 重定向代码,因为 302 是默认设置。

    【讨论】:

    • 原始代码对我有用。 apache 未检测到浏览器的默认代理。我使用了具有相同代码的移动模拟器来保持它的工作。感谢您的回复!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-31
    • 2015-07-26
    • 2010-11-13
    • 2012-05-13
    • 1970-01-01
    • 2015-09-22
    • 1970-01-01
    相关资源
    最近更新 更多