我正在使用Apache的mod_rewrite将移动用户根据他们的http_user_agentredirect到我的移动站点。 然而并不是所有的页面都有一个移动等值 移动网页也以.html结尾,“完整”网页以.shtml结尾。
这里是一些伪代码。
用户是否具有特定的HTTP_USER_AGENT?
有移动网页吗?
如果是的话,带他们去那里 如果不是,则不需要redirect。
RewriteCond允许反向引用[0]捕获RewriteRule中的组。
RewriteCond %{HTTP_USER_AGENT} Mobile RewriteCond $1.html -f RewriteRule ^(.*)\.shtml$ $1.html [R]
[0]更像是一个前向参考…
可能最好发布在网站pipe理员部分。 但是你想要像下面这样的东西吗?
<script language=javascript> <!-- if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) { location.replace("http://url-to-send-them/iphone.html"); } --> </script>
有很多网站可以帮助你 – http://www.abeautifulsite.net/blog/2011/11/detecting-mobile-devices-with-javascript/
只需简单地将脚本添加到您想要检测的页面上,就不需要预先检查网站页面的存在。
有什么办法可以使用PHP来做到这一点,那么你可以做到这一点;
<?php $THEPAGE = 'WHATEVER THE URL YOU WANT IT TO BE'; $page = file_get_contents("$THEPAGE"); if(strstr($page, '404')) { } else { header('Location: ' .$THEPAGE .'\')'; } ?>