【问题标题】:URL rewriting for mobile devices移动设备的 URL 重写
【发布时间】:2011-04-07 06:26:39
【问题描述】:

我知道这个问题已经被问过很多次了,但我仍然无法弄清楚我的代码出了什么问题。

我的 HTML 上有一个样式表链接

<link rel="stylesheet" href="style.css" type="text/css" media="screen" />

如果用户在移动设备上,我想重定向到另一个文件。 我是这样做的:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/style.css$
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|webos|googlebot-mobile" [NC]
RewriteRule (.*) /mobile.css [L,R=302]

我的文件都在子域的根目录下,所以我猜!^/style.css$的规则应该是正确的。

当我尝试访问 /style.css 时,我没有重定向,但是当我尝试访问 / 时,Firefox 告诉我存在重定向循环。

我错过了什么吗? 谢谢

【问题讨论】:

    标签: iphone android css .htaccess mobile-website


    【解决方案1】:

    如果你使用 Rewrite 而不是 Redirect,它会起作用:

    RewriteEngine on   
    RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|webos|googlebot-mobile" [NC]  
    RewriteRule ^style.css$ /mobile.css [L,NC]  
    

    【讨论】:

    • np :) 我很惭愧地承认,在阅读您的问题之前,我从未想到过这种类型的解决方案。学习新东西总是好的!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-06
    • 2013-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多