【问题标题】:no redirect rule for mobile redirect in htaccesshtaccess 中没有移动重定向的重定向规则
【发布时间】:2014-08-06 23:52:12
【问题描述】:

我使用 .htaccess 代码进行移动重定向:

RewriteEngine On

RewriteCond %{HTTP_USER_AGENT} (mobile|android|iphone|ipod|ipad|avantgo|blackberry|blazer|compal|elaine|epoc|fennec|hiptop|iemobile|iris|kindle|sgh|brew|htc|j2me|lg|midp|mmp|mot|netfront|nokia|obigo|openweb|operamini|palm|plucker|pocket|psp|samsung|sanyo|sch|smartphone|sonyericsson|symbian|symbos|teleca|treo|up.browser|up.link|vodafone|wap|wap1|wap2|webos|windowsce|xda|xiino) [NC]
RewriteRule ^(.*)$ some site [R=302,L]

但是,我希望将某些移动 IP/移动用户代理排除在上述重定向之外,而不是被拒绝。我希望他们看到桌面站点。 如何使用 .htaccess 代码做到这一点?

谢谢。

【问题讨论】:

    标签: .htaccess redirect mobile


    【解决方案1】:

    您可以添加另一个RewriteCond 进行排除:

    RewriteEngine On
    
    RewriteCond %{REMOTE_ADDR} !^(11\.22\.33\.44|55\.66\.77\.88)$
    RewriteCond %{HTTP_USER_AGENT} !(excluded-agent1|excluded-agent2|excluded-agent3)
    RewriteCond %{HTTP_USER_AGENT} (mobile|android|iphone|ipod|ipad|avantgo|blackberry|blazer|compal|elaine|epoc|fennec|hiptop|iemobile|iris|kindle|sgh|brew|htc|j2me|lg|midp|mmp|mot|netfront|nokia|obigo|openweb|operamini|palm|plucker|pocket|psp|samsung|sanyo|sch|smartphone|sonyericsson|symbian|symbos|teleca|treo|up.browser|up.link|vodafone|wap|wap1|wap2|webos|windowsce|xda|xiino) [NC]
    RewriteRule ^ /desktop-site [R=302,L]
    

    【讨论】:

    • 谢谢你,阿努巴瓦!不,我的代码中的“某个站点”是移动站点,而不是桌面。我希望我的代码中的所有用户代理都重定向到我的移动设备 - “某个站点”,排除移动代理来传递代码并查看我的桌面站点。这怎么能用 IP 地址实现?
    • 对不起,我能够理解您的评论。这个答案是针对这个要求I want some mobile IPs/mobile User Agents to be excluded。如果您想阻止某些 IP,请使用 RewriteCond %{REMOTE_ADDR} 条件。
    • 对不起,阿努巴瓦!我不想阻止某些移动用户代理或 IP,我想将它们从移动重定向中排除,即他们必须将站点视为桌面用户,而不是移动用户。对于此类 IP,我必须使用什么条件?
    • Anubhava,我尝试了您的代码,但无法正常工作。您还有其他建议吗?
    • 非常感谢,阿努巴瓦!这对我帮助很大!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-01
    • 2016-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多